diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2018-10-23 13:29:04 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2018-10-29 00:09:31 +0000 |
commit | d3a7c5448fe166444980ed41757c9e03d83ece2f (patch) | |
tree | 7a2a4f05b808705cd27845335876184f87243b5c | |
parent | ae6239bfec75df8a6795c2cc0017fcb0148e01e5 (diff) | |
download | subsurface-d3a7c5448fe166444980ed41757c9e03d83ece2f.tar.gz |
Dive site: return pointer to dive_site in create_dive_site_*()
This changes more of the dive-site interface to return pointers
instead of UUIDs. Currently, most call sites directly extract
UUIDs afterwards. Ultimately, the UUIDs will be generally replaced
by pointers, which will then simplify these callers.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r-- | core/datatrak.c | 2 | ||||
-rw-r--r-- | core/dive.c | 2 | ||||
-rw-r--r-- | core/divesite.c | 14 | ||||
-rw-r--r-- | core/divesite.h | 8 | ||||
-rw-r--r-- | core/gpslocation.cpp | 4 | ||||
-rw-r--r-- | core/import-cobalt.c | 2 | ||||
-rw-r--r-- | core/import-divinglog.c | 2 | ||||
-rw-r--r-- | core/libdivecomputer.c | 2 | ||||
-rw-r--r-- | core/liquivision.c | 2 | ||||
-rw-r--r-- | core/load-git.c | 4 | ||||
-rw-r--r-- | core/parse-xml.c | 10 | ||||
-rw-r--r-- | core/parse.c | 6 | ||||
-rw-r--r-- | core/uemis-downloader.c | 2 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 2 | ||||
-rw-r--r-- | mobile-widgets/qmlmanager.cpp | 5 | ||||
-rw-r--r-- | smtk-import/smartrak.c | 4 |
16 files changed, 35 insertions, 36 deletions
diff --git a/core/datatrak.c b/core/datatrak.c index dbc79534c..98cfcb795 100644 --- a/core/datatrak.c +++ b/core/datatrak.c @@ -204,7 +204,7 @@ unsigned char *dt_dive_parser(unsigned char *runner, struct dive *dt_dive) ds = get_dive_site_by_name(buffer); dt_dive->dive_site_uuid = ds ? ds->uuid : 0; if (dt_dive->dive_site_uuid == 0) - dt_dive->dive_site_uuid = create_dive_site(buffer, dt_dive->when); + dt_dive->dive_site_uuid = create_dive_site(buffer, dt_dive->when)->uuid; free(locality); locality = NULL; free(dive_point); diff --git a/core/dive.c b/core/dive.c index da9410f2d..347dbdbfa 100644 --- a/core/dive.c +++ b/core/dive.c @@ -4080,7 +4080,7 @@ void dive_set_geodata_from_picture(struct dive *dive, struct picture *picture) if (ds) { ds->location = picture->location; } else { - dive->dive_site_uuid = create_dive_site_with_gps("", &picture->location, dive->when); + dive->dive_site_uuid = create_dive_site_with_gps("", &picture->location, dive->when)->uuid; invalidate_dive_cache(dive); } } diff --git a/core/divesite.c b/core/divesite.c index bef505814..f6e96e3c5 100644 --- a/core/divesite.c +++ b/core/divesite.c @@ -203,16 +203,16 @@ uint32_t create_divesite_uuid(const char *name, timestamp_t divetime) } /* allocate a new site and add it to the table */ -uint32_t create_dive_site(const char *name, timestamp_t divetime) +struct dive_site *create_dive_site(const char *name, timestamp_t divetime) { uint32_t uuid = create_divesite_uuid(name, divetime); struct dive_site *ds = alloc_or_get_dive_site(uuid); ds->name = copy_string(name); - return uuid; + return ds; } /* same as before, but with current time if no current_dive is present */ -uint32_t create_dive_site_from_current_dive(const char *name) +struct dive_site *create_dive_site_from_current_dive(const char *name) { if (current_dive != NULL) { return create_dive_site(name, current_dive->when); @@ -225,14 +225,14 @@ uint32_t create_dive_site_from_current_dive(const char *name) } /* same as before, but with GPS data */ -uint32_t create_dive_site_with_gps(const char *name, const location_t *loc, timestamp_t divetime) +struct dive_site *create_dive_site_with_gps(const char *name, const location_t *loc, timestamp_t divetime) { uint32_t uuid = create_divesite_uuid(name, divetime); struct dive_site *ds = alloc_or_get_dive_site(uuid); ds->name = copy_string(name); ds->location = *loc; - return ds->uuid; + return ds; } /* a uuid is always present - but if all the other fields are empty, the dive site is pointless */ @@ -330,7 +330,7 @@ void merge_dive_sites(uint32_t ref, uint32_t* uuids, int count) mark_divelist_changed(true); } -uint32_t find_or_create_dive_site_with_name(const char *name, timestamp_t divetime) +struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime) { int i; struct dive_site *ds; @@ -339,7 +339,7 @@ uint32_t find_or_create_dive_site_with_name(const char *name, timestamp_t diveti break; } if (ds) - return ds->uuid; + return ds; return create_dive_site(name, divetime); } diff --git a/core/divesite.h b/core/divesite.h index d9e2881e4..0b21d69af 100644 --- a/core/divesite.h +++ b/core/divesite.h @@ -58,9 +58,9 @@ int nr_of_dives_at_dive_site(uint32_t uuid, bool select_only); bool is_dive_site_used(uint32_t uuid, bool select_only); void free_dive_site(struct dive_site *ds); void delete_dive_site(uint32_t id); -uint32_t create_dive_site(const char *name, timestamp_t divetime); -uint32_t create_dive_site_from_current_dive(const char *name); -uint32_t create_dive_site_with_gps(const char *name, const location_t *, timestamp_t divetime); +struct dive_site *create_dive_site(const char *name, timestamp_t divetime); +struct dive_site *create_dive_site_from_current_dive(const char *name); +struct dive_site *create_dive_site_with_gps(const char *name, const location_t *, timestamp_t divetime); struct dive_site *get_dive_site_by_name(const char *name); struct dive_site *get_dive_site_by_gps(const location_t *); struct dive_site *get_dive_site_by_gps_and_name(char *name, const location_t *); @@ -71,7 +71,7 @@ void copy_dive_site(struct dive_site *orig, struct dive_site *copy); void merge_dive_site(struct dive_site *a, struct dive_site *b); void clear_dive_site(struct dive_site *ds); unsigned int get_distance(const location_t *loc1, const location_t *loc2); -uint32_t find_or_create_dive_site_with_name(const char *name, timestamp_t divetime); +struct dive_site *find_or_create_dive_site_with_name(const char *name, timestamp_t divetime); void merge_dive_sites(uint32_t ref, uint32_t *uuids, int count); #ifdef __cplusplus diff --git a/core/gpslocation.cpp b/core/gpslocation.cpp index 485cbac56..3d27e28cc 100644 --- a/core/gpslocation.cpp +++ b/core/gpslocation.cpp @@ -211,8 +211,8 @@ static void copy_gps_location(struct gpsTracker &gps, struct dive *d) { struct dive_site *ds = get_dive_site_by_uuid(d->dive_site_uuid); if (!ds) { - d->dive_site_uuid = create_dive_site(qPrintable(gps.name), gps.when); - ds = get_dive_site_by_uuid(d->dive_site_uuid); + ds = create_dive_site(qPrintable(gps.name), gps.when); + d->dive_site_uuid = ds->uuid; } ds->location = gps.location; } diff --git a/core/import-cobalt.c b/core/import-cobalt.c index 869bbdab2..9208ad696 100644 --- a/core/import-cobalt.c +++ b/core/import-cobalt.c @@ -197,7 +197,7 @@ static int cobalt_dive(void *param, int columns, char **data, char **column) return 1; } sprintf(tmp, "%s / %s", location, location_site); - state->cur_dive->dive_site_uuid = find_or_create_dive_site_with_name(tmp, state->cur_dive->when); + state->cur_dive->dive_site_uuid = find_or_create_dive_site_with_name(tmp, state->cur_dive->when)->uuid; free(tmp); } free(location); diff --git a/core/import-divinglog.c b/core/import-divinglog.c index 255f765d9..d0e8786e6 100644 --- a/core/import-divinglog.c +++ b/core/import-divinglog.c @@ -287,7 +287,7 @@ static int divinglog_dive(void *param, int columns, char **data, char **column) state->cur_dive->when = (time_t)(atol(data[1])); if (data[2]) - state->cur_dive->dive_site_uuid = find_or_create_dive_site_with_name(data[2], state->cur_dive->when); + state->cur_dive->dive_site_uuid = find_or_create_dive_site_with_name(data[2], state->cur_dive->when)->uuid; if (data[3]) utf8_string(data[3], &state->cur_dive->buddy); diff --git a/core/libdivecomputer.c b/core/libdivecomputer.c index a4c21b423..b22d5fed2 100644 --- a/core/libdivecomputer.c +++ b/core/libdivecomputer.c @@ -596,7 +596,7 @@ static void parse_string_field(struct dive *dive, dc_field_string_t *str) parse_location(line, &location); if (location.lat.udeg && location.lon.udeg) - dive->dive_site_uuid = create_dive_site_with_gps(str->value, &location, time(NULL)); + dive->dive_site_uuid = create_dive_site_with_gps(str->value, &location, time(NULL))->uuid; } } #endif diff --git a/core/liquivision.c b/core/liquivision.c index b8e7ece2b..e5ad9fef0 100644 --- a/core/liquivision.c +++ b/core/liquivision.c @@ -227,7 +227,7 @@ static void parse_dives (int log_version, const unsigned char *buf, unsigned int // now that we have the dive time we can store the divesite // (we need the dive time to create deterministic uuids) if (found_divesite) { - dive->dive_site_uuid = find_or_create_dive_site_with_name(location, dive->when); + dive->dive_site_uuid = find_or_create_dive_site_with_name(location, dive->when)->uuid; free(location); } //unsigned int end_time = array_uint32_le(buf + ptr); diff --git a/core/load-git.c b/core/load-git.c index f040f9de6..b0d94f3cf 100644 --- a/core/load-git.c +++ b/core/load-git.c @@ -159,7 +159,7 @@ static void parse_dive_gps(char *line, struct membuffer *str, void *_dive) if (!ds) { ds = get_dive_site_by_gps(&location); if (!ds) - dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when); + dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when)->uuid; else dive->dive_site_uuid = ds->uuid; } else { @@ -183,7 +183,7 @@ static void parse_dive_location(char *line, struct membuffer *str, void *_dive) if (!ds) { ds = get_dive_site_by_name(name); if (!ds) - dive->dive_site_uuid = create_dive_site(name, dive->when); + dive->dive_site_uuid = create_dive_site(name, dive->when)->uuid; else dive->dive_site_uuid = ds->uuid; } else { diff --git a/core/parse-xml.c b/core/parse-xml.c index c1d9fc2d5..a49004bae 100644 --- a/core/parse-xml.c +++ b/core/parse-xml.c @@ -981,7 +981,7 @@ static void divinglog_place(char *place, uint32_t *uuid, struct parser_state *st if (ds) *uuid = ds->uuid; else - *uuid = create_dive_site(buffer, state->cur_dive->when); + *uuid = create_dive_site(buffer, state->cur_dive->when)->uuid; // TODO: capture the country / city info in the taxonomy instead free(state->city); @@ -1133,7 +1133,7 @@ static void gps_lat(char *buffer, struct dive *dive) location.lat = parse_degrees(buffer, &end); if (!ds) { - dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when); + dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when)->uuid; } else { if (ds->location.lat.udeg && ds->location.lat.udeg != location.lat.udeg) fprintf(stderr, "Oops, changing the latitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)"); @@ -1149,7 +1149,7 @@ static void gps_long(char *buffer, struct dive *dive) location.lon = parse_degrees(buffer, &end); if (!ds) { - dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when); + dive->dive_site_uuid = create_dive_site_with_gps(NULL, &location, dive->when)->uuid; } else { if (ds->location.lon.udeg && ds->location.lon.udeg != location.lon.udeg) fprintf(stderr, "Oops, changing the longitude of existing dive site id %8x name %s; not good\n", ds->uuid, ds->name ?: "(unknown)"); @@ -1189,7 +1189,7 @@ static void gps_in_dive(char *buffer, struct dive *dive, struct parser_state *st state->cur_location = location; dive->dive_site_uuid = ds->uuid; } else { - dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when); + dive->dive_site_uuid = create_dive_site_with_gps("", &location, dive->when)->uuid; } } else { ds = get_dive_site_by_uuid(uuid); @@ -2120,7 +2120,7 @@ int parse_dlf_buffer(unsigned char *buffer, size_t size, struct dive_table *tabl /* Measure GPS */ state.cur_location.lat.udeg = (int)((ptr[7] << 24) + (ptr[6] << 16) + (ptr[5] << 8) + (ptr[4] << 0)); state.cur_location.lon.udeg = (int)((ptr[11] << 24) + (ptr[10] << 16) + (ptr[9] << 8) + (ptr[8] << 0)); - state.cur_dive->dive_site_uuid = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when); + state.cur_dive->dive_site_uuid = create_dive_site_with_gps("DLF imported", &state.cur_location, state.cur_dive->when)->uuid; break; default: break; diff --git a/core/parse.c b/core/parse.c index c0d127d0b..8da7322a0 100644 --- a/core/parse.c +++ b/core/parse.c @@ -435,8 +435,8 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) if (exact_match) { dive->dive_site_uuid = exact_match->uuid; } else { - dive->dive_site_uuid = create_dive_site(buffer, dive->when); - struct dive_site *newds = get_dive_site_by_uuid(dive->dive_site_uuid); + struct dive_site *newds = create_dive_site(buffer, dive->when); + dive->dive_site_uuid = newds->uuid; if (has_location(&state->cur_location)) { // we started this uuid with GPS data, so lets use those newds->location = state->cur_location; @@ -450,7 +450,7 @@ void add_dive_site(char *ds_name, struct dive *dive, struct parser_state *state) dive->dive_site_uuid = ds->uuid; } } else { - dive->dive_site_uuid = create_dive_site(buffer, dive->when); + dive->dive_site_uuid = create_dive_site(buffer, dive->when)->uuid; } } free(to_free); diff --git a/core/uemis-downloader.c b/core/uemis-downloader.c index 9f4936edb..ce91f9d40 100644 --- a/core/uemis-downloader.c +++ b/core/uemis-downloader.c @@ -992,7 +992,7 @@ static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char * } else if (!is_log && dive && !strcmp(tag, "divespot_id")) { int divespot_id = atoi(val); if (divespot_id != -1) { - dive->dive_site_uuid = create_dive_site("from Uemis", dive->when); + dive->dive_site_uuid = create_dive_site("from Uemis", dive->when)->uuid; uemis_mark_divelocation(dive->dc.diveid, divespot_id, dive->dive_site_uuid); } #if UEMIS_DEBUG & 2 diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 8d5ecdcff..e617a8140 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -688,7 +688,7 @@ uint32_t MainTab::updateDiveSite(uint32_t pickedUuid, dive *d) if (pickedUuid == RECENTLY_ADDED_DIVESITE) { QString name = ui.location->text().isEmpty() ? tr("New dive site") : ui.location->text(); - pickedUuid = create_dive_site(qPrintable(name), displayed_dive.when); + pickedUuid = create_dive_site(qPrintable(name), displayed_dive.when)->uuid; createdNewDive = true; LocationFilterModel::instance()->addName(name); } diff --git a/mobile-widgets/qmlmanager.cpp b/mobile-widgets/qmlmanager.cpp index c5c9469d9..0a10c640e 100644 --- a/mobile-widgets/qmlmanager.cpp +++ b/mobile-widgets/qmlmanager.cpp @@ -760,7 +760,7 @@ static void setupDivesite(struct dive *d, struct dive_site *ds, double lat, doub if (ds) { ds->location = location; } else { - d->dive_site_uuid = create_dive_site_with_gps(locationtext, &location, d->when); + d->dive_site_uuid = create_dive_site_with_gps(locationtext, &location, d->when)->uuid; } } @@ -879,8 +879,7 @@ bool QMLManager::checkLocation(DiveObjectHelper *myDive, struct dive *d, QString if (!ds) ds = get_dive_site_by_name(qPrintable(location)); if (!ds && !location.isEmpty()) { - uint32_t uuid = create_dive_site(qPrintable(location), d->when); - ds = get_dive_site_by_uuid(uuid); + ds = create_dive_site(qPrintable(location), d->when); } d->dive_site_uuid = ds ? ds->uuid : 0; } diff --git a/smtk-import/smartrak.c b/smtk-import/smartrak.c index f787b401a..d97e8b69f 100644 --- a/smtk-import/smartrak.c +++ b/smtk-import/smartrak.c @@ -376,9 +376,9 @@ static void smtk_build_location(MdbHandle *mdb, char *idx, timestamp_t when, uin ds = get_dive_site_by_name(str); if (!ds) { if (!has_location(&loc)) - *location = create_dive_site(str, when); + *location = create_dive_site(str, when)->uuid; else - *location = create_dive_site_with_gps(str, &loc, when); + *location = create_dive_site_with_gps(str, &loc, when)->uuid; ds = get_dive_site_by_uuid(*location); } else { *location = ds->uuid; |