summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-10-10 21:41:36 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-10-16 14:26:37 -0700
commit8549f24c915b05e0e84e73d3d99e7888d3c7c063 (patch)
treeb5696fb7675b448b9f812af79a8492d4ace318b4 /core
parent7b06349be55935be9a09310a5c0bba50e4585d35 (diff)
downloadsubsurface-8549f24c915b05e0e84e73d3d99e7888d3c7c063.tar.gz
core: add device_table parameter to device table functions
Instead of accessing the global device table directly, add a parameter to all device-table accessing functions. This makes all places in the code that access the global device table grep-able, which is necessary to include the device-table code in the undo system. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'core')
-rw-r--r--core/datatrak.c2
-rw-r--r--core/device.cpp24
-rw-r--r--core/device.h9
-rw-r--r--core/dive.c2
-rw-r--r--core/divelist.c13
-rw-r--r--core/libdivecomputer.c2
-rw-r--r--core/load-git.c4
-rw-r--r--core/parse-xml.c2
-rw-r--r--core/parse.c2
9 files changed, 31 insertions, 29 deletions
diff --git a/core/datatrak.c b/core/datatrak.c
index 9a0af0cc1..720b631b3 100644
--- a/core/datatrak.c
+++ b/core/datatrak.c
@@ -565,7 +565,7 @@ static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive
dt_dive->dc.deviceid = 0;
else
dt_dive->dc.deviceid = 0xffffffff;
- create_device_node(dt_dive->dc.model, dt_dive->dc.deviceid, "", "", dt_dive->dc.model);
+ create_device_node(&device_table, dt_dive->dc.model, dt_dive->dc.deviceid, "", "", dt_dive->dc.model);
dt_dive->dc.next = NULL;
if (!is_SCR && dt_dive->cylinders.nr > 0) {
get_cylinder(dt_dive, 0)->end.mbar = get_cylinder(dt_dive, 0)->start.mbar -
diff --git a/core/device.cpp b/core/device.cpp
index 2982910a8..4b2395509 100644
--- a/core/device.cpp
+++ b/core/device.cpp
@@ -219,7 +219,7 @@ const struct device *get_device_for_dc(const struct device_table *table, const s
* When setting the device ID, we also fill in the
* serial number and firmware version data
*/
-extern "C" void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid)
+extern "C" void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid, const struct device_table *device_table)
{
if (!deviceid)
return;
@@ -230,7 +230,7 @@ extern "C" void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid)
if (!dc->model)
return;
- const device *node = get_device_for_dc(&device_table, dc);
+ const device *node = get_device_for_dc(device_table, dc);
if (!node)
return;
@@ -275,14 +275,14 @@ static void addDC(std::vector<device> &dcs, const std::string &m, uint32_t d, co
}
}
-extern "C" void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname)
+extern "C" void create_device_node(struct device_table *device_table, const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname)
{
- addDC(device_table.devices, model ?: "", deviceid, nickname ?: "", serial ?: "", firmware ?: "");
+ addDC(device_table->devices, model ?: "", deviceid, nickname ?: "", serial ?: "", firmware ?: "");
}
-extern "C" void clear_device_nodes()
+extern "C" void clear_device_nodes(struct device_table *device_table)
{
- device_table.devices.clear();
+ device_table->devices.clear();
}
/* Returns whether the given device is used by a selected dive. */
@@ -303,7 +303,7 @@ extern "C" int is_default_dive_computer_device(const char *name)
return qPrefDiveComputer::device() == name;
}
-extern "C" void set_dc_nickname(struct dive *dive)
+extern "C" void set_dc_nickname(struct dive *dive, struct device_table *device_table)
{
if (!dive)
return;
@@ -312,21 +312,21 @@ extern "C" void set_dc_nickname(struct dive *dive)
for_each_dc (dive, dc) {
if (!empty_string(dc->model) && dc->deviceid &&
- !get_device_for_dc(&device_table, 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(),
+ auto it = std::find_if(device_table->devices.begin(), device_table->devices.end(),
[dc] (const device &dev)
{ return !strcasecmp(dev.model.c_str(), dc->model); });
- if (it != device_table.devices.end()) {
+ if (it != device_table->devices.end()) {
// we already have this model but a different deviceid
std::string simpleNick(dc->model);
if (dc->deviceid == 0)
simpleNick += " (unknown deviceid)";
else
simpleNick += " (" + QString::number(dc->deviceid, 16).toStdString() + ")";
- addDC(device_table.devices, dc->model, dc->deviceid, simpleNick, {}, {});
+ addDC(device_table->devices, dc->model, dc->deviceid, simpleNick, {}, {});
} else {
- addDC(device_table.devices, dc->model, dc->deviceid, {}, {}, {});
+ addDC(device_table->devices, dc->model, dc->deviceid, {}, {}, {});
}
}
}
diff --git a/core/device.h b/core/device.h
index e145ce7e2..b9729cdcc 100644
--- a/core/device.h
+++ b/core/device.h
@@ -17,12 +17,13 @@ struct dive_table;
extern struct device_table device_table;
extern void fake_dc(struct divecomputer *dc);
-extern void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid);
-extern void set_dc_nickname(struct dive *dive);
-extern void create_device_node(const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname);
+extern void set_dc_deviceid(struct divecomputer *dc, unsigned int deviceid, const struct device_table *table);
+
+extern void set_dc_nickname(struct dive *dive, struct device_table *table);
+extern void create_device_node(struct device_table *table, const char *model, uint32_t deviceid, const char *serial, const char *firmware, const char *nickname);
extern int nr_devices(const struct device_table *table);
extern const struct device *get_device(const struct device_table *table, int i);
-extern void clear_device_nodes();
+extern void clear_device_nodes(struct device_table *table);
const char *get_dc_nickname(const struct divecomputer *dc);
extern bool device_used_by_selected_dive(const struct device *dev);
diff --git a/core/dive.c b/core/dive.c
index 0658d73bc..065000970 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -1595,7 +1595,7 @@ static void fixup_dive_dc(struct dive *dive, struct divecomputer *dc)
{
/* Add device information to table */
if (dc->deviceid && (dc->serial || dc->fw_version))
- create_device_node(dc->model, dc->deviceid, dc->serial, dc->fw_version, "");
+ create_device_node(&device_table, dc->model, dc->deviceid, dc->serial, dc->fw_version, "");
/* Fixup duration and mean depth */
fixup_dc_duration(dc);
diff --git a/core/divelist.c b/core/divelist.c
index b1e670e31..c76ec7b25 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -826,7 +826,7 @@ void process_loaded_dives()
for_each_dive(i, dive) {
if (!dive->hidden_by_filter)
shown_dives++;
- set_dc_nickname(dive);
+ set_dc_nickname(dive, &device_table);
}
sort_dive_table(&dive_table);
@@ -1161,12 +1161,13 @@ void process_imported_dives(struct dive_table *import_table, struct trip_table *
/* check if we need a nickname for the divecomputer for newly downloaded dives;
* since we know they all came from the same divecomputer we just check for the
* first one */
- if (flags & IMPORT_IS_DOWNLOADED)
- set_dc_nickname(import_table->dives[0]);
- else
+ if (flags & IMPORT_IS_DOWNLOADED) {
+ set_dc_nickname(import_table->dives[0], &device_table);
+ } else {
/* they aren't downloaded, so record / check all new ones */
for (i = 0; i < import_table->nr; i++)
- set_dc_nickname(import_table->dives[i]);
+ set_dc_nickname(import_table->dives[i], &device_table);
+ }
/* Sort the table of dives to be imported and combine mergable dives */
sort_dive_table(import_table);
@@ -1375,7 +1376,7 @@ void clear_dive_file_data()
}
clear_dive(&displayed_dive);
- clear_device_nodes();
+ clear_device_nodes(&device_table);
clear_events();
clear_filter_presets();
diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c
index 071350c8b..f824ed153 100644
--- a/core/libdivecomputer.c
+++ b/core/libdivecomputer.c
@@ -931,7 +931,7 @@ static unsigned int fixup_suunto_versions(device_data_t *devdata, const dc_event
(devinfo->firmware >> 8) & 0xff,
(devinfo->firmware >> 0) & 0xff);
}
- create_device_node(devdata->model, devdata->deviceid, serial_nr, firmware, "");
+ create_device_node(&device_table, devdata->model, devdata->deviceid, serial_nr, firmware, "");
return serial;
}
diff --git a/core/load-git.c b/core/load-git.c
index 0cf18d48c..915db26e2 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -712,7 +712,7 @@ static void parse_dc_date(char *line, struct membuffer *str, struct git_parser_s
{ UNUSED(str); update_date(&state->active_dc->when, line); }
static void parse_dc_deviceid(char *line, struct membuffer *str, struct git_parser_state *state)
-{ UNUSED(str); set_dc_deviceid(state->active_dc, get_hex(line)); }
+{ UNUSED(str); set_dc_deviceid(state->active_dc, get_hex(line), &device_table); }
static void parse_dc_diveid(char *line, struct membuffer *str, struct git_parser_state *state)
{ UNUSED(str); state->active_dc->diveid = get_hex(line); }
@@ -1000,7 +1000,7 @@ static void parse_settings_divecomputerid(char *line, struct membuffer *str, str
break;
line = parse_keyvalue_entry(parse_divecomputerid_keyvalue, &id, line, str);
}
- create_device_node(id.model, id.deviceid, id.serial, id.firmware, id.nickname);
+ create_device_node(&device_table, id.model, id.deviceid, id.serial, id.firmware, id.nickname);
}
static void parse_picture_filename(char *line, struct membuffer *str, struct git_parser_state *state)
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 61af0f617..bce6d2f31 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -829,7 +829,7 @@ static void try_to_fill_dc(struct divecomputer *dc, const char *name, char *buf,
if (MATCH("model", utf8_string, &dc->model))
return;
if (MATCH("deviceid", hex_value, &deviceid)) {
- set_dc_deviceid(dc, deviceid);
+ set_dc_deviceid(dc, deviceid, &device_table);
return;
}
if (MATCH("diveid", hex_value, &dc->diveid))
diff --git a/core/parse.c b/core/parse.c
index 281e9c3bc..a1b906bfb 100644
--- a/core/parse.c
+++ b/core/parse.c
@@ -201,7 +201,7 @@ void dc_settings_start(struct parser_state *state)
void dc_settings_end(struct parser_state *state)
{
- create_device_node(state->cur_settings.dc.model, state->cur_settings.dc.deviceid, state->cur_settings.dc.serial_nr,
+ create_device_node(&device_table, state->cur_settings.dc.model, state->cur_settings.dc.deviceid, state->cur_settings.dc.serial_nr,
state->cur_settings.dc.firmware, state->cur_settings.dc.nickname);
reset_dc_settings(state);
}