summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-05 21:24:31 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-16 14:26:37 -0700
commit7415824a8c6a650bba185686f389b34bcd3ea854 (patch)
tree27478be816d1f0fdcb2ee5cbacc5e98c41825dfd
parent74b8d13672284136e7192645c2ba190f3e0b6f70 (diff)
downloadsubsurface-7415824a8c6a650bba185686f389b34bcd3ea854.tar.gz
core: use C accessors in core/libdivecomputer.c instead of callback
Searching the proper device for the divecomputer was done via a callback. Very hard to follow code. Since we can now access "struct device" from C, obtain it directly via get_device_for_dc(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/libdivecomputer.c25
1 files changed, 5 insertions, 20 deletions
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index 12b9dabf9..071350c8b 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -552,25 +552,6 @@ static uint32_t calculate_string_hash(const char *str)
}
/*
- * Find an existing device ID for this device model and serial number
- */
-static void dc_match_serial(void *_dc, const char *model, uint32_t deviceid, const char *nickname, const char *serial, const char *firmware)
-{
- UNUSED(nickname);
- UNUSED(firmware);
-
- struct divecomputer *dc = _dc;
-
- if (!deviceid)
- return;
- if (!dc->model || !model || strcasecmp(dc->model, model))
- return;
- if (!dc->serial || !serial || strcasecmp(dc->serial, serial))
- return;
- dc->deviceid = deviceid;
-}
-
-/*
* Set the serial number.
*
* This also sets the device ID by looking for existing devices that
@@ -581,8 +562,12 @@ static void dc_match_serial(void *_dc, const char *model, uint32_t deviceid, con
*/
static void set_dc_serial(struct divecomputer *dc, const char *serial)
{
+ const struct device *device;
+
dc->serial = serial;
- call_for_each_dc(dc, dc_match_serial, false);
+ if ((device = get_device_for_dc(&device_table, dc)) != NULL)
+ dc->deviceid = device_get_id(device);
+
if (!dc->deviceid)
dc->deviceid = calculate_string_hash(serial);
}