mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
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>
This commit is contained in:
parent
7b06349be5
commit
8549f24c91
9 changed files with 31 additions and 29 deletions
|
@ -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 -
|
||||
|
|
|
@ -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, {}, {}, {});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue