summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-06 21:36:51 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-16 14:26:37 -0700
commitd93b261e8954e8ce5f652d0af2dcf0b379c1bed1 (patch)
tree0eaf9bb713e6c0a5d188c570e068c4d66e8ae616 /core
parente8d3f75541765fce3193b19a2f30ac8f827e00f5 (diff)
downloadsubsurface-d93b261e8954e8ce5f652d0af2dcf0b379c1bed1.tar.gz
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>
Diffstat (limited to 'core')
-rw-r--r--core/device.cpp33
-rw-r--r--core/device.h2
2 files changed, 17 insertions, 18 deletions
diff --git a/core/device.cpp b/core/device.cpp
index 1c0d6d5c6..63e2eea1d 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -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());
}
diff --git a/core/device.h b/core/device.h
index c401fd6a0..623014b21 100644
--- a/core/device.h
+++ b/core/device.h
@@ -11,6 +11,7 @@ extern "C" {
struct divecomputer;
struct device;
struct device_table;
+struct dive_table;
// global device table
extern struct device_table device_table;
@@ -25,6 +26,7 @@ extern void call_for_each_dc(void *f, void (*callback)(void *, const char *, uin
const char *, const char *, const char *), bool select_only);
extern void clear_device_nodes();
const char *get_dc_nickname(const struct divecomputer *dc);
+extern bool device_used_by_selected_dive(const struct device *dev);
extern const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc);