summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-05 21:12:49 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-16 14:26:37 -0700
commit74b8d13672284136e7192645c2ba190f3e0b6f70 (patch)
tree58fb6f80b32b453e6fdb60646b83ebb44c02efdc /core
parentc4bfecce1bcd9a7b5f2fc85b1466adf9a1d2336a (diff)
downloadsubsurface-74b8d13672284136e7192645c2ba190f3e0b6f70.tar.gz
core: make get_device_for_dc() accessible from C
The function getDCExact() was used to search for a device structure matching a divecomputer. Since C code can now access struct device, we can export that function to C. Rename it to get_device_for_dc() for consistency with naming of the core functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/device.cpp9
-rw-r--r--core/device.h2
2 files changed, 7 insertions, 4 deletions
diff --git a/core/device.cpp b/core/device.cpp
index b65c8dd7f..b688e36eb 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -213,8 +213,9 @@ bool device::operator<(const device &a) const
return std::tie(deviceId, model) < std::tie(a.deviceId, a.model);
}
-static const device *getDCExact(const std::vector<device> &dcs, const divecomputer *dc)
+const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc)
{
+ const std::vector<device> &dcs = table->devices;
auto it = std::lower_bound(dcs.begin(), dcs.end(), device{dc->model, dc->deviceid, {}, {}, {}});
return it != dcs.end() && it->model == dc->model && it->deviceId == dc->deviceid ? &*it : NULL;
}
@@ -234,7 +235,7 @@ extern "C" void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid)
if (!dc->model)
return;
- const device *node = getDCExact(device_table.devices, dc);
+ const device *node = get_device_for_dc(&device_table, dc);
if (!node)
return;
@@ -329,7 +330,7 @@ extern "C" void set_dc_nickname(struct dive *dive)
for_each_dc (dive, dc) {
if (!empty_string(dc->model) && dc->deviceid &&
- !getDCExact(device_table.devices, dc)) {
+ !get_device_for_dc(&device_table, dc)) {
// we don't have this one, yet
auto it = std::find_if(device_table.devices.begin(), device_table.devices.end(),
[dc] (const device &dev)
@@ -351,7 +352,7 @@ extern "C" void set_dc_nickname(struct dive *dive)
const char *get_dc_nickname(const struct divecomputer *dc)
{
- const device *existNode = getDCExact(device_table.devices, dc);
+ const device *existNode = get_device_for_dc(&device_table, dc);
if (existNode && !existNode->nickName.empty())
return existNode->nickName.c_str();
diff --git a/core/device.h b/core/device.h
index a976a7e64..22163e56c 100644
--- a/core/device.h
+++ b/core/device.h
@@ -26,6 +26,8 @@ extern void call_for_each_dc(void *f, void (*callback)(void *, const char *, uin
extern void clear_device_nodes();
const char *get_dc_nickname(const struct divecomputer *dc);
+extern const struct device *get_device_for_dc(const struct device_table *table, const struct divecomputer *dc);
+
// struct device accessors for C-code. The returned strings are not stable!
const char *device_get_model(const struct device *dev);
const uint32_t device_get_id(const struct device *dev);