mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: factor out device_is_used_by_selected_dive() function
We have a callback for all devices with a twist: it can loop over those devices that are used by a selected dive. This is used for exporting a subset of the dive log. Factor out the "is device used by selected dive" part of the function and make it available to C. The goal is to make the whole callback thing unnecessary and let C code loop directly over the device list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
e8d3f75541
commit
d93b261e89
2 changed files with 17 additions and 18 deletions
|
@ -285,27 +285,24 @@ extern "C" void clear_device_nodes()
|
|||
device_table.devices.clear();
|
||||
}
|
||||
|
||||
/* Returns whether the given device is used by a selected dive. */
|
||||
extern "C" bool device_used_by_selected_dive(const struct device *dev)
|
||||
{
|
||||
for (dive *d: getDiveSelection()) {
|
||||
struct divecomputer *dc;
|
||||
for_each_dc (d, dc) {
|
||||
if (dc->deviceid == dev->deviceId)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
extern "C" void call_for_each_dc (void *f, void (*callback)(void *, const char *, uint32_t, const char *, const char *, const char *),
|
||||
bool select_only)
|
||||
{
|
||||
for (const device &node : device_table.devices) {
|
||||
bool found = false;
|
||||
if (select_only) {
|
||||
for (dive *d: getDiveSelection()) {
|
||||
struct divecomputer *dc;
|
||||
for_each_dc (d, dc) {
|
||||
if (dc->deviceid == node.deviceId) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found)
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
found = true;
|
||||
}
|
||||
if (found)
|
||||
for (const device &node: device_table.devices) {
|
||||
if (!select_only || device_used_by_selected_dive(&node))
|
||||
callback(f, node.model.c_str(), node.deviceId, node.nickName.c_str(),
|
||||
node.serialNumber.c_str(), node.firmware.c_str());
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue