mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 19:23:24 +00:00
devices: create device nodes in parsers
So far, we added a non-global device table to the parser states. Now, create device nodes in that table instead of in the global table. Thus, on undo of dive-import, the new device nodes will be removed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
255f561aff
commit
8c65558b5c
6 changed files with 23 additions and 14 deletions
|
@ -159,7 +159,8 @@ static dc_status_t dt_libdc_buffer(unsigned char *ptr, int prf_length, int dc_mo
|
|||
* Parses a mem buffer extracting its data and filling a subsurface's dive structure.
|
||||
* Returns a pointer to last position in buffer, or NULL on failure.
|
||||
*/
|
||||
static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct dive_site_table *sites, long maxbuf)
|
||||
static unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive, struct dive_site_table *sites,
|
||||
struct device_table *devices, long maxbuf)
|
||||
{
|
||||
int rc, profile_length, libdc_model;
|
||||
char *tmp_notes_str = NULL;
|
||||
|
@ -565,7 +566,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(&device_table, dt_dive->dc.model, dt_dive->dc.deviceid, "", "", dt_dive->dc.model);
|
||||
create_device_node(devices, 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 -
|
||||
|
@ -578,6 +579,7 @@ bail:
|
|||
free(devdata);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Parses the header of the .add file, returns the number of dives in
|
||||
* the archive (must be the same than number of dives in .log file).
|
||||
|
@ -675,7 +677,8 @@ static void wlog_compl_parser(struct memblock *wl_mem, struct dive *dt_dive, int
|
|||
* Main function call from file.c memblock is allocated (and freed) there.
|
||||
* If parsing is aborted due to errors, stores correctly parsed dives.
|
||||
*/
|
||||
int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites)
|
||||
int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips,
|
||||
struct dive_site_table *sites, struct device_table *devices)
|
||||
{
|
||||
UNUSED(trips);
|
||||
unsigned char *runner;
|
||||
|
@ -707,7 +710,7 @@ int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_t
|
|||
while ((i < numdives) && ((long) runner < maxbuf)) {
|
||||
struct dive *ptdive = alloc_dive();
|
||||
|
||||
runner = dt_dive_parser(runner, ptdive, sites, maxbuf);
|
||||
runner = dt_dive_parser(runner, ptdive, sites, devices, maxbuf);
|
||||
if (wl_mem)
|
||||
wlog_compl_parser(wl_mem, ptdive, i);
|
||||
if (runner == NULL) {
|
||||
|
|
|
@ -361,9 +361,9 @@ int parse_file(const char *filename, struct dive_table *table, struct trip_table
|
|||
wl_name = strcat(wl_name, ".add");
|
||||
if((ret = readfile(wl_name, &wl_mem)) < 0) {
|
||||
fprintf(stderr, "No file %s found. No WLog extensions.\n", wl_name);
|
||||
ret = datatrak_import(&mem, NULL, table, trips, sites);
|
||||
ret = datatrak_import(&mem, NULL, table, trips, sites, devices);
|
||||
} else {
|
||||
ret = datatrak_import(&mem, &wl_mem, table, trips, sites);
|
||||
ret = datatrak_import(&mem, &wl_mem, table, trips, sites, devices);
|
||||
free(wl_mem.buffer);
|
||||
}
|
||||
free(mem.buffer);
|
||||
|
|
|
@ -23,7 +23,8 @@ extern "C" {
|
|||
#endif
|
||||
extern int try_to_open_cochran(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
|
||||
extern int try_to_open_liquivision(const char *filename, struct memblock *mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
|
||||
extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
|
||||
extern int datatrak_import(struct memblock *mem, struct memblock *wl_mem, struct dive_table *table, struct trip_table *trips,
|
||||
struct dive_site_table *sites, struct device_table *devices);
|
||||
extern void ostctools_import(const char *file, struct dive_table *table, struct trip_table *trips, struct dive_site_table *sites);
|
||||
|
||||
extern int readfile(const char *filename, struct memblock *mem);
|
||||
|
|
|
@ -713,7 +713,12 @@ 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), &device_table); }
|
||||
{
|
||||
UNUSED(str);
|
||||
int id = get_hex(line);
|
||||
set_dc_deviceid(state->active_dc, id, &device_table); // prefer already known serial/firmware over those from the loaded log
|
||||
set_dc_deviceid(state->active_dc, id, state->devices);
|
||||
}
|
||||
|
||||
static void parse_dc_diveid(char *line, struct membuffer *str, struct git_parser_state *state)
|
||||
{ UNUSED(str); state->active_dc->diveid = get_hex(line); }
|
||||
|
@ -984,9 +989,8 @@ static void parse_divecomputerid_keyvalue(void *_cid, const char *key, const cha
|
|||
* it can have multiple strings (but see the tag parsing for another example of
|
||||
* that) in addition to the non-string entries.
|
||||
*/
|
||||
static void parse_settings_divecomputerid(char *line, struct membuffer *str, struct git_parser_state *_unused)
|
||||
static void parse_settings_divecomputerid(char *line, struct membuffer *str, struct git_parser_state *state)
|
||||
{
|
||||
UNUSED(_unused);
|
||||
struct divecomputerid id = { pop_cstring(str, line) };
|
||||
|
||||
/* Skip the '"' that stood for the model string */
|
||||
|
@ -1001,7 +1005,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(&device_table, id.model, id.deviceid, id.serial, id.firmware, id.nickname);
|
||||
create_device_node(state->devices, 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)
|
||||
|
@ -1699,7 +1703,7 @@ static int parse_settings_entry(struct git_parser_state *state, const git_tree_e
|
|||
git_blob *blob = git_tree_entry_blob(state->repo, entry);
|
||||
if (!blob)
|
||||
return report_error("Unable to read settings file");
|
||||
for_each_line(blob, settings_parser, NULL);
|
||||
for_each_line(blob, settings_parser, state);
|
||||
git_blob_free(blob);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -830,7 +830,8 @@ 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, &device_table);
|
||||
set_dc_deviceid(dc, deviceid, &device_table); // prefer already known serial/firmware over those from the loaded log
|
||||
set_dc_deviceid(dc, deviceid, state->devices);
|
||||
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(&device_table, state->cur_settings.dc.model, state->cur_settings.dc.deviceid, state->cur_settings.dc.serial_nr,
|
||||
create_device_node(state->devices, 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…
Add table
Reference in a new issue