aboutsummaryrefslogtreecommitdiffstats
path: root/core/divesite.c
AgeCommit message (Collapse)Author
2019-10-02Core: implement move functions for dive and dive_site tableGravatar Berthold Stoeger
To allow efficient moving of downloaded dives from the download thread to the model, implement a general move function that moves table data. Instantiate that function for the dive and dive_site tables. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-09-21Cleanup: replace is_dive_site_used() by is_dive_site_selected()Gravatar Berthold Stoeger
is_dive_site_used() had a "selected" parameter. If true it would return whether the given dive site had a selected dive. Turns out all callers had this parameter set to true. Therefore, replace by a simplified function without the "selected" parameter and give the function an appropriate name. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-06-19Cleanup: generate clear_*_table() functions by macroGravatar Berthold Stoeger
In analogy to the other table functions, generate these by a macro as well. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-30Bugfix for algorithm in get_distance()Gravatar Doug Junkins
Fixed bug in the Haversine function in get_distance() based on algorithm at https://www.movable-type.co.uk/scripts/latlong.html and added bounds to the 'a' term to avoid floating point errors for antipodal points. Signed-off-by: Doug Junkins <junkins@foghead.com>
2019-04-15Cleanup: free dive table in trips and dive sitesGravatar Berthold Stoeger
Trips and dive sites were changed to use dive tables instead of linked lists. But the memory used for the tables wasn't freed. Do this. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: make UUID generation deterministicGravatar Berthold Stoeger
Instead of using a random UUID, use an SHA1 hash of name, description and notes (if defined). This is necessary for testing. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: make dive site merging undoableGravatar Berthold Stoeger
This one was rather trivial, as there is no actual merging done. Quite simply, a number of dive sites are removed and their dive added to a different dive site. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: inform model of dive site addition / deletionGravatar Berthold Stoeger
Introduce two DiveListNotifier signals which are sent by the undo commands if dives are added to / removed from the core. The signal has the dive site and the index in the global dive site table as payload. Thus, the model has only to remove the appropriate rows. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Cleanup: macroize dive site table functions, keep table sortedGravatar Berthold Stoeger
Turn the table functions of the dive site handling into macros as was already used for dives and dive trips. This has the effect that the table is kept sorted by UUID. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Cleanup: rename unregister_trip() to remove_trip()Gravatar Berthold Stoeger
For consistency with remove_dive(). Moreover, swap parameter order in remove_dive() so that both functions use the same parameter order. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: keep frontend informed of changes to dive site countGravatar Berthold Stoeger
Add a new signal to DiveListNotifier. Send signal if dives are added or removed and therefore the dive count of a dive site changes. The dive sites are collected and the signal is sent at the end of the command. Add code to update the table view. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive sites: simplify nr_of_dives_at_dive_site()Gravatar Berthold Stoeger
1) The second parameter (selected_only) was always false. Therefore, remove it. 2) Simplify the function by simply returning the reference count. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: use ref-counts to see if dive site is usedGravatar Berthold Stoeger
Checking for dive site usage is now simply checking the number of dives. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: add dive site ref-countingGravatar Berthold Stoeger
Instead of setting dive->dive_site directly, call the add_dive_to_dive_site() and unregister_dive_from_dive_site() functions. In the parser this turned out to be a bit tricky. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive sites: prepare for dive site ref-countingGravatar Berthold Stoeger
Add a dive site table to each dive site to keep track of dives that have been added to a dive site. Add two functions to add dives to / remove dives from dive sites. Since dive sites now contain a dive table, the order of includes had to be changed: "divesite.h" now includes "dive.h" and not vice-versa. This caused some include churn. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: set UUID only on save or loadGravatar Berthold Stoeger
Since the UUID will be overwritten on save and is only used on save and load, set it only on save or load. For other created dive sites, leave the UUID field uninitialized. This means that the UUID will change between saves. Let's see how the git saver handles that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: ensure that no two dive sites have same UUIDGravatar Berthold Stoeger
We absolutely want to avoid dive site with the same UUID. But that could happen when reimporting a log where the dive sites diverged. Therefore, on adding a dive site to a table, change the UUID if it already exists. Since dives are associated to dive sites with pointers, this should have no negative impact. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: consider dive site in AddDive()Gravatar Berthold Stoeger
If a dive site was added for a new dive, remove it on undo. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Cleanup: let get_dive_site_idx() compare pointersGravatar Berthold Stoeger
The code used dive site uuids, which are not really used anymore. The only caller of this function does certainly not use a copy, so let's compare pointers instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Undo: make undo-system dive site-awareGravatar Berthold Stoeger
As opposed to dive trips, dive sites were always directly added to the global table, even on import. Instead, parse the divesites into a distinct table and merge them on import. Currently, this does not do any merging of dive sites, i.e. dive sites are considered as either equal or different. Nevertheless, merging of data should be rather easy to implement and simply follow the code of the dive merging. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-04-12Dive site: add dive site table parameter to dive site functionsGravatar Berthold Stoeger
To enable undo of dive site functions, it is crucial to work with different dive site tables. Therefore add a dive site table parameter to dive site functions. For now, always pass the global dive site table. Thus, this commit shouldn't alter any functionality. After this change, a simple search for dive_site_table reveals all places where the global dive site table is accessed. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-02-28Cleanup: move get_divesite_idx() to divesite.cGravatar Berthold Stoeger
This function was defined in divelist.c, whereas it's better located in divesite.c. Move it. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-02-28Cleanup: uninline get_dive_site_by_uuidGravatar Berthold Stoeger
There seems to be no compelling reason to have this function inlined. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-02-09Cleanup: remove unsused function clear_dive_site()Gravatar Berthold Stoeger
The last caller was removed in 11a211fb02ad5443342d91b6967f150cb4f6d34f Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-02-09Cleanup: remove unused function create_dive_site_from_current_dive()Gravatar Berthold Stoeger
The last caller was removed in 11a211fb02ad5443342d91b6967f150cb4f6d34f Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-02-09Cleanup: make create_divesite_uuid() of static linkageGravatar Berthold Stoeger
This function was not used outside of core/divesite.h Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-07Dive sites: don't delete unused dive sites on saveGravatar Berthold Stoeger
Unused dive sites were deleted on save. This clashed with the undo system in the following scenario: 1) Delete single-use dive site. 2) Save (dive site deleted) 3) Undo (reference to freed dive site) Therefore, as a quick-fix, keep the referenced dive site around. Note that this also means that empty dive sites must not be deleted, as it might refer to a dive in the undo system. Instead only clear references to empty dive sites in the global dive table. Factor this functionality out, as it was common to the XML and git savers. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: replace dive->dive_site_uuid by dive_siteGravatar Berthold Stoeger
Replace the UUID reference of struct dive by a pointer to dive_site. This commit is rather large in lines, but nevertheless quite simple since most of the UUID->pointer work was done in previous commits. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: pass dive-site pointers to merge_dive_sites()Gravatar Berthold Stoeger
Instead of passing uuids, pass a pointer to the dive site. This is small step in an effort to remove uuids. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: pass dive-site pointer to delete_dive_site()Gravatar Berthold Stoeger
Instead of passing a uuid, pass a pointer to the dive site. This is small step in an effort to remove uuids. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: pass dive-site pointer to is_dive_site_used()Gravatar Berthold Stoeger
Instead of passing a uuid, pass a pointer to the dive site. This is small step in an effort to remove uuids. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: pass dive-site pointer to nr_of_dives_at_dive_site()Gravatar Berthold Stoeger
Instead of passing a uuid, pass a pointer to the dive site. This is small step in an effort to remove uuids. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-29Dive site: return pointer to dive_site in create_dive_site_*()Gravatar Berthold Stoeger
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>
2018-10-29Dive site: return pointer to dive_site in get_dive_site_*()Gravatar Berthold Stoeger
As a first step in removing dive-site uuids, change the interface of the get_dive_site_*() functions to return pointers instead of uuids. This makes code a bit more complicated in places where the uuid is extracted afterwards (needed NULL check). Nevertheless, these places should disappear once pointers instead of uuids are stored in the dive-structures. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-23Core: accept NULL-pointer in free_trip() and free_divesite()Gravatar Berthold Stoeger
This is consistent with most other free_*() functions in the core code and will make cleanup of parser state less verbose. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-21Add 'location_t' data structureGravatar Linus Torvalds
Instead of having people treat latitude and longitude as separate things, just add a 'location_t' data structure that contains both. Almost all cases want to always act on them together. This is really just prep-work for adding a few more locations that we track: I want to add a entry/exit location to each dive (independent of the dive site) because of how the Garmin Descent gives us the information (and hopefully, some day, other dive computers too). Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2018-10-15Parser: fix leakage of dive-site and dive dataGravatar Berthold Stoeger
Dive site data was collected in "cur_dive_site", which was then merged into an existing or a new dive site. But only the struct dive_site pointed to by "cur_dive_site" and the taxonomy data were freed, not the textual data such as name or description. Therefore, split out the approrpriate free-ing from the delete_dive_site() function and call that instead of a simple free(). A similar situation occured for dives that would not be added to the dive-table because they were deemed incomplete. Use free_dive() here instead of a simple free() too. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-13Dive site: use own copy of taxonomy in dive-site-edit widgetGravatar Berthold Stoeger
The dive-site-edit widget uses a copy of the to-be-edited site to compare with old values. Generally, this seems overkill (the original dive-site can be used for such a comparison). But one place where it can't simply be removed is the taxonomy, because the widget needs a place to store the unsaved data. Change the code to use an explicit taxonomy structure instead of the one provided in the copy. This should ultimately allow removal of the latter. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-07Leak fix: free taxonomy data in delete_dive_site()Gravatar Berthold Stoeger
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-07-11core: remove clang warning in divesite.cGravatar jan Iversen
Add () in complex condition to avoid clang warning. Signed-off-by: Jan Iversen <jani@apache.org>
2018-07-06core: don't crash on merge of non-existing dive siteGravatar Dirk Hohndel
While we shouldn't have a dive that references a dive site that doesn't exist, if we do, we shouldn't crash. And a dive site that doesn't exist is most definitely 'empty'. Reported-by: Benjamin Fogel <nystire@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-05-14Core: introduce new subsurface-string headerGravatar Dirk Hohndel
First small step to shrinking dive.h. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2018-01-11Introduce helper function empty_string()Gravatar Berthold Stoeger
There are ca. 50 constructs of the kind same_string(s, "") to test for empty or null strings. Replace them by the new helper function empty_string(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-05core: free() in a safe way, reverse geolookup unstabilityGravatar Jan Mulder
A simple one line change that solves (for me) numerous hard crashes when adding geo tags by reverse lookup from the dive site edit screen. This is one of those crashes that is might not be reproducible on any platform, or even between different builds on one platform. This said, I found that the free() on line 99 of divesitehelpers.cpp tried to free pointers to random data, ie. not pointing to valid taxonomy category strings. And those pointers where simply caused by freeing the string earlier, and leaving the pointer around. So, this change is nothing more than setting the just freed pointer to NULL, to allow free() to be called later safely. Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-12-31divesite.c: use union in create_divesite_uuid()Gravatar Lubomir I. Ivanov
The return produces a warning about "strict-aliasing rules". Use a union to fit the hash and the uint32_t into the same block of memory, which obeys the GCC strict-aliasing rules. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-12-19git storage: invalidate cache on merge dive siteGravatar Jan Mulder
In hindsight a very simple bug to fix, but it requires some knowledge on the inner workings of our git storage. The changes on merge of dive sites were simply not saved (completely) because the git storage code has a cache that we need to invalidate selectively (ie. for the dive we just gave a new dive site uuid) to get things finally embedded in the overall commit. The main reason this bug went unnoticed for more than 2 years is that most people use the XML/SSRF format (where this problem is non exsistent), and dive site merging is probably not a very much used feature either. Fixes: #939 Signed-off-by: Jan Mulder <jlmulder@xs4all.nl>
2017-10-05divesite.c: use NULL instead of 0 for char* buffersGravatar Lubomir I. Ivanov
Makes it clearer that these are buffers and not integers like `ds->uuid`. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-10-05divesite.c: prevent double free()Gravatar Lubomir I. Ivanov
Reported-by: Benjamin Fogel <nystire@gmail.com> Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
2017-10-04Don't add separate country field, use taxonomyGravatar Dirk Hohndel
The more I looked at the code that added the country to the dive site, the more it seemed redundant given what we have with the taxonomy. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-10-04Add taxonomy copy helper functionGravatar Dirk Hohndel
We don't want to just be able to copy all of a dive site. Sometimes we might want to be able to copy just the taxonomy. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>