aboutsummaryrefslogtreecommitdiffstats
path: root/core/uemis-downloader.c
AgeCommit message (Collapse)Author
2019-06-19Cleanup: move tag functions into own translation unitGravatar Berthold Stoeger
Make dive.h a bit slimmer. It's only a drop in the bucket - but at least when modifying tag functions not the *whole* application is rebuilt anymore. 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-12Cleanup: move declaration of get_stylesheet() to qthelper.hGravatar Berthold Stoeger
The function is defined in qthelper.c and thus not all users of dive.h have to suck in the xslt headers. 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-12Parser: parse into custom dive site tableGravatar Berthold Stoeger
To extend the undo system to dive sites, the importers and downloaders must not parse directly into the global dive site table. Instead, pass a dive_site_table argument to parse into. For now, always pass the global dive_site_table so that this commit should not cause any functional change. 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-03-17Core: remove variable name conflictGravatar Dirk Hohndel
Having a parameter with the same name as a global variable is potentially confusing. Found via LGTM.com Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2019-02-28Uemis: remove trip deletion on dive deletionGravatar Berthold Stoeger
Since ff9506b21bbb9910256841dcb577bcb2e19047e8 the downloaders don't add dives to a new trip, but the import code does. Remove the code in the Uemis downloader that would remove a dive from the trip. The code has been broken recently anyway (instead of testing for trip, it tested for the notrip flag, which make no sense whatsoever). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-19Import: don't add to new trip while downloadingGravatar Berthold Stoeger
Since process_imported_dives() can add dives to a newly generated trip, this need not be done in the downloading code. This makes data flow distinctly simpler, as no trip table and no add-new-trip flag has to be passed down to the libdivecomputer glue code. Moreover, since now the trip creation is done at the import step rather than the download step, the latest status of the "add to new trip" checkbox will be considered. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2019-01-09Core: add trip_table parameter to trip-functionsGravatar Berthold Stoeger
Currently trips are added to the global trip table. If we want to make dive-import undoable, we should be able to parse trips of a log-file into a distinct table. Therefore, add a trip_table parameter to - insert_trip() - create_and_hookup_trip_from_dive() - autogroup_dives() - unregister_trip() - remove_dive_from_trip() Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-12-23Cleanup: remove unused parameter was_autogenGravatar Berthold Stoeger
In commit 6bf4120dbbf7be1b9267e0e86f3948b77870ea71 the trip-flags were replaced by a simple boolean. This made the was_autogen parameter to the remove_dive_from_trip() and unregister_dive_from_trip() functions unused. Remove these parameters. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-20Core: replace tripflag by notrip booleanGravatar Berthold Stoeger
The only remaining use of the tripflag was to mark dives that were removed explicitly from a trip, i.e. shouldn't be autogrouped. Therefore replace the enum by a simple boolean. Currently, there is no way of unsetting the notrip flag. But this shouldn't result in a user-visible change. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-19Uemis downloader: free ans_path on errorGravatar Berthold Stoeger
In a few instances, the ans_path was not freed on error. Fix them. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-11-19Warnings: silence new gcc warnings in uemis-downloader.cGravatar Berthold Stoeger
Since upgrading to gcc 8.2 it produces noisy warnings about potentially truncated strings. It doesn't recognize that filenr can never become >4000. So clamp it down explicitly. Do this by adding a function that does the assembly of the filename path. Adding unnecessary code to silence compiler warnings is dubious, but in this case it might be reasonable. Fix a second instance by increasing the stack-allocated buffer to 32 bytes. Hopefully nobody has more divespots than would fit in a 9-decimal digit number! 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: use pointer instead of uuid in uemis_helperGravatar Berthold Stoeger
Another small step in removing dive-site UUIDs: use a pointer instead of a UUID in the "uemis_helper" structure. 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: 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: remove uuid in Uemis' divesite-mapGravatar Berthold Stoeger
The uemis downloader uses a cache for location to divesite id. Trivially, the divesite-uuid can be replaced by a pointer. This is a tiny step to remove divesite UUIDs. 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-06Core: remove dive->downloaded flagGravatar Berthold Stoeger
This flag had two distinct uses: - signal that dives were downloaded, not imported - use to mark imported dives Both are not used anymore, therefore remove the flag. The uemis downloaded misused the flag to mark deleted dives. Instead misuse the "hidden_by_filter" flag. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-10-05Cleanup: don't access downloadTable directly in Uemis-downloaderGravatar Berthold Stoeger
The Uemis downloader determines the dive-number to be downloaded by either checking the download-table [interrupted connection] or the global dive table [fresh download]. The downloadTable is passed in the device data structure, but in the function to determine the latest dive, the global downloadTable is accessed directly [thus supposing that this table was passed in device data]. Instead, use the table from device data to avoid funny surprises should we change to a non-global download table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
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-31uemis: code refactoringGravatar Oliver Schwaneberg
- Variable max_deleted_seen had no effect and is removed. - Results of read/write operations are evaluated to assert success and to prevent compiler warnings. Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-01-31uemis: Fix mapping of object_ids to dive numbersGravatar Oliver Schwaneberg
When performing a factory reset to an uemis, the object_ids within the divelog will not be reset. Nevertheless, the dive numbers are reset to 1. So, the first log will have a positive offset n to the first dive number. The uemis-downloader used the object_id from the logs as a start point for getDive, if dives were already synced before. This causes the sync to stall. I prevent this by subtracting the lowest object_id from the requested before using it as dive number. Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-01-27uemis: speed up synchronisation of same divesitesGravatar Oliver Schwaneberg
uemis-downloader downloads the dive spot for each dive, even if the same location was already downloaded before within the ongoing synchronization run. I modified the function "get_uemis_divespot" to remember all requested divespot_ids and their mapping to uuids. New helper functions: - static void erase_divespot_mapping() - static void add_to_divespot_mapping(int divespot_id, uint32_t dive_site_uuid) - static bool is_divespot_mappable(int divespot_id) - static uint32_t get_dive_site_uuid_by_divespot_id(int divespot_id) The memory leak is removed through the call of erade_divespot_mapping(). Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-01-19Checking for ACK for getDive.Gravatar Oliver Schwaneberg
get_matching_dive does not check if the DC wrote an acknowledgement for the requested dive. As result, the sync stalls if dive number 0 is not available. Signed-off-by: Oliver Schwaneberg <oliver.schwaneberg@gmail.com>
2018-01-11Use helper function empty_string() instead of manual checksGravatar Berthold Stoeger
For code consistency, substitute boolean expressions: s && *s -> !empty_string(s) s && s[0] -> !empty_string(s) !s || !*s -> empty_string(s) !s || !s[0] -> empty_string(s) Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2018-01-06Trivial: remove redundant declarations of downloadTableGravatar Berthold Stoeger
downloadTable was declared twice in "dive.h". Remove one occurence. Moreover, "uemis-downloader.c" also declared downloadTable. This can likewise be removed, because "uemis-downloader.c" indirectly includes "dive.h". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2017-12-30Cleanup: consistently handle file open failuresGravatar Dirk Hohndel
In part based on Coverity CID 45129 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-30Cleanup: fix memory leakGravatar Dirk Hohndel
Oops, I previously fixed only one of two instances. Coverity CID 45078 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-27Cleanup: avoid memory leakGravatar Dirk Hohndel
Coverity CID 45078 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-12-26Cleanup: avoid out of bounds accessGravatar Dirk Hohndel
sizeof() is clearly the wrong way to get to the size of that array... Coverity CID 208294 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-07-17Resolve type confusionGravatar Dirk Hohndel
No idea why this now shows up as an error in the iOS build. We need to refer to the typedef, not the underlying struct. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-06-27Switch over to SSRF_CUSTOM_IO v2Gravatar Linus Torvalds
I hate changing the IO interfaces this often, but when I converted the custom serial interface to the more generic custom IO interface, I intentionally left the legacy serial operations alone, because I didn't want to change something I didn't care about. But it turns out that leaving them with the old calling convention caused extra problems when converting the bluetooth serial code to have the BLE GATT packet fall-back, which requires mixing two kinds of operations. Also, the packet_open() routine was passed a copy of the 'dc_context_t', which makes it possible to update the 'dc_custom_io_t' field on the fly at open time. That makes a lot of chaining operations much simpler, since now you can chain the 'custom_io_t' at open time and then libdivecomputer will automatically call the new routines instead of the old ones. That dc_context_t availability gets rid of all the if (device && device->ops) return device->ops->serial_xyz(..); hackery inside the rfcomm routines - now we can just at open time do a simple dc_context_set_custom_io(context, &ble_serial_ops); to switch things over to the BLE version of the serial code instead. Finally, SSRF_CUSTOM_IO v2 added an opaque "dc_user_device_t" pointer argument to the custom_io descriptor, which gets filled in as the custom_io is registered with the download context. Note that unlike most opaque pointers, this one is opaque to *libdivecomputer*, and the type is supposed to be supplied by the user. We define the "dc_user_device_t" as our old "struct device_data_t", making it "struct user_device_t" instead. That means that the IO routines now get passed the device info showing what device they are supposed to download for. That, in turn, means that now our BLE GATT open code can take the device type it opens for into account if it wants to. And it will want to, since the rules for Shearwater are different from the rules for Suunto, for example. NOTE! Because of the interface change with libdivecomputer, this will need a flag-day again where libdivecomputer and subsurface are updated together. It may not be the last time, either. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2017-05-27Separate the download thread from the widget logicGravatar Tomaz Canabrava
This is important to not duplicate code for the Qml view. Now the DownloadFromDiveComputer widget is mostly free from important code (that has been upgraded to the core folder), and I can start coding the QML interface. There are still a few functions on the desktop widget that will die so I can call them via the QML code later. I also touched the location of a few globals (please, let's stop using those) - because it was declared on the desktop code and being used in the core. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-04-29Add SPDX header to core C filesGravatar Dirk Hohndel
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2017-03-11Merge branch 'master' of https://github.com/dje29/subsurfaceGravatar Dirk Hohndel
2017-03-11divespot > dive spotGravatar Martin Měřinský
2017-03-11divelog > dive logGravatar Martin Měřinský
2017-03-09Fix potential double/float to int rounding errorsGravatar Jeremie Guichard
Not using lrint(f) when converting double/float to int creates rounding errors. This error was detected by TestParse::testParseDM4 failure on Windows. It was creating rounding inconsistencies on Linux too, see change in TestDiveDM4.xml. Enable -Wfloat-conversion for gcc version greater than 4.9.0 Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2017-03-08Change calls to rint into lrint avoiding conversion warningsGravatar Jeremie Guichard
Using gcc option "-Wfloat-conversion" is useful to catch potential conversion errors (where lrint should be used). rint returns double and still raises the same warning, this is why this change updates all rint calls to lrint. In few places, where input type is a float, corresponding lrinf is used. Signed-off-by: Jeremie Guichard <djebrest@gmail.com>
2016-04-29Extend time parsing to before 1970Gravatar Linus Torvalds
It turns out that we are starting to have users that have logs that go back that far. It won't be common, but let's get it right anyway. NOTE! With us now supporting dates earlier in 1900, this also makes "utc_mktime()" always add the "1900" to the year field. That way we avoid ever using the fairly ambiguous two-digit shorthand. It didn't use to be all that ambiguous when we knew that any two-digit number less than 70 had to be 2000+. Now that we support going back to earlier in the last centiry, that certainty is eroding. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2016-04-04Move subsurface-core to core and qt-mobile to mobile-widgetsGravatar Dirk Hohndel
Having subsurface-core as a directory name really messes with autocomplete and is obviously redundant. Simmilarly, qt-mobile caused an autocomplete conflict and also was inconsistent with the desktop-widget name for the directory containing the "other" UI. And while cleaning up the resulting change in the path name for include files, I decided to clean up those even more to make them consistent overall. This could have been handled in more commits, but since this requires a make clean before the build, it seemed more sensible to do it all in one. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>