mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
devices: add functions to add / remove / check for devices
To include the device code in the undo system, we need functions to check for the existence of devices and to add or remove them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
a261466594
commit
53118be1f9
3 changed files with 26 additions and 2 deletions
|
@ -218,7 +218,7 @@ bool device::operator<(const device &a) const
|
|||
return strcoll(model.c_str(), a.model.c_str()) < 0;
|
||||
}
|
||||
|
||||
const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc)
|
||||
extern "C" const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc)
|
||||
{
|
||||
const std::vector<device> &dcs = table->devices;
|
||||
device dev { dc->model, dc->deviceid, {}, {}, {} };
|
||||
|
@ -226,6 +226,12 @@ const struct device *get_device_for_dc(const struct device_table *table, const s
|
|||
return it != dcs.end() && same_device(*it, dev) ? &*it : NULL;
|
||||
}
|
||||
|
||||
extern "C" bool device_exists(const struct device_table *device_table, const struct device *dev)
|
||||
{
|
||||
auto it = std::lower_bound(device_table->devices.begin(), device_table->devices.end(), *dev);
|
||||
return it != device_table->devices.end() && same_device(*it, *dev);
|
||||
}
|
||||
|
||||
/*
|
||||
* When setting the device ID, we also fill in the
|
||||
* serial number and firmware version data
|
||||
|
@ -292,6 +298,20 @@ extern "C" void create_device_node(struct device_table *device_table, const char
|
|||
addDC(device_table->devices, model ?: "", deviceid, nickname ?: "", serial ?: "", firmware ?: "");
|
||||
}
|
||||
|
||||
/* Does not check for duplicates! */
|
||||
extern "C" void add_to_device_table(struct device_table *device_table, const struct device *dev)
|
||||
{
|
||||
auto it = std::lower_bound(device_table->devices.begin(), device_table->devices.end(), *dev);
|
||||
device_table->devices.insert(it, *dev);
|
||||
}
|
||||
|
||||
extern "C" void remove_device(struct device_table *device_table, const struct device *dev)
|
||||
{
|
||||
auto it = std::lower_bound(device_table->devices.begin(), device_table->devices.end(), *dev);
|
||||
if (it != device_table->devices.end() && same_device(*it, *dev))
|
||||
device_table->devices.erase(it);
|
||||
}
|
||||
|
||||
extern "C" void clear_device_table(struct device_table *device_table)
|
||||
{
|
||||
device_table->devices.clear();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue