aboutsummaryrefslogtreecommitdiffstats
path: root/core
AgeCommit message (Collapse)Author
2020-10-24parser: add device_table to parser stateGravatar Berthold Stoeger
If we want to avoid the parsers to directly modify global data, we have to provide a device_table to parse into. This adds such a state and the corresponding function parameters. However, for now this is unused. Adding new parameters is very painful and this commit shows that we urgently need a "struct divelog" collecting all those tables! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23cleanup: remove unused function intdup()Gravatar Berthold Stoeger
That was used by the old xml-params code, which was recently replaced. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23parser: replace params[] code by new xml_params structGravatar Berthold Stoeger
This fixes a load of memory holes, and makes the code (hopefully) more readable. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23core: add a small helper-struct that keeps track of xml-parametersGravatar Berthold Stoeger
The XML-parameter code is a mess. Ownership is unclear. Allocation and freeing of strings is in different functions. Sometimes only every second string is free()d, because keys are not copied. But this is done inconsistently. The caller has to know how many parameters the callee may add. Instead, let's add a small helper-struct that uses C++ memory management, but exports a C-API. The array for the XML-library is generated on the fly. This is only the implementation, the old code is not yet replaced. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-23libdc: free value strings given by libdc's dc_parser_get_field()Gravatar Berthold Stoeger
Apparently libdc gives us copies of strings. The API is very scary, because (at least according to my reading of the code), the key/value pair may be stored in a cache. Thus on free()ing the string in the cache becomes invalid and we must not access it twice. Very obscure. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17devices: use case-insensitive comparison for modelGravatar Berthold Stoeger
Recently, the sorting of the devices was changed to be case-insensitive for models for consistency reasons. However, then the equality-comparison should also be case-insensitive. Break it out into its own function, to avoid that mistake in the future. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17cleanup: rename clear_device_nodes() to clear_device_table()Gravatar Berthold Stoeger
For consistency with all the other clear_*_table functions (dive, trip, dive_site, ...) Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17filter: remove filter_preset_table_tGravatar Berthold Stoeger
We used a typedef "filter_preset_table_t" for the filter preset table, because it is a "std::vector<filter_preset>". However, that is in contrast to all the other global tables (dives, trips, sites) that we have. Therefore, turn this into a standard struct, which simply inherits from "std::vector<filter_preset>". Note that while inheriting from std::vector<> is generally not recommended, it is not a problem here, because we don't modify it in any shape or form. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-17filter: make filter_preset_table an opaque struct for C codeGravatar Berthold Stoeger
filter_preset_table_t was defined as "void" for C code. However, that meant that any pointer could be passed as such a table and such a table could be passed as any pointer, without generating compiler warnings. Indeed, we had a parameter-mixup that went unnoticed. Therefore, make filter_preset_t an anonymous structure with the name filter_preset instead. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16cleanup: use correct printf formatGravatar Dirk Hohndel
This fixes a warning from the CodeQL scan. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-16core: use case-insensitive comparison for device modelsGravatar Berthold Stoeger
The code in core/libdivecomputer.c used string insensitive comparison for device models, before being merged into core/device.c. Let's reinstate that behavior, since it appears to be more logical. On would assume that two different vendors will not use the same model with different casing (and the same device-ids), so that should be safe. This uses strcoll to correctly sort unicode, which will hopefully never be needed! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16cleanup: replace std::find_if by std::any_ofGravatar Berthold Stoeger
To search for devices with the same model, we used find_if(). However, that was only to check whether such a thing exists, not to actually do something with said device. Therefore, change this to std::any_of() to make it clear what the purpose of the statement is. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: add device_table parameter to device table functionsGravatar Berthold Stoeger
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>
2020-10-16core: remove call_for_each_dc()Gravatar Berthold Stoeger
The core now loops over the devices directly - no need for this callback. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: use C accessors in core/save-xml.c instead of callbackGravatar Berthold Stoeger
We now can loop over devices from C and check for selection. So let's get rid of the last user of the call_for_all_devices() callback. Code readability improvement is not stellar, but one less place where we shoe-horn user data through a void-pointer. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: factor out device_is_used_by_selected_dive() functionGravatar Berthold Stoeger
We have a callback for all devices with a twist: it can loop over those devices that are used by a selected dive. This is used for exporting a subset of the dive log. Factor out the "is device used by selected dive" part of the function and make it available to C. The goal is to make the whole callback thing unnecessary and let C code loop directly over the device list. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: use C accessors in core/save-git.c instead of callbackGravatar Berthold Stoeger
Now we can simply loop over the list of devices. In this case, it's not much more readable, but at least we don't have that nasty pass user-data through "void *" pattern. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16cleanup: remove device::operator!=()Gravatar Berthold Stoeger
This was not used. Moreover, mark device::operator==() for removal. This is used for detecting changes in the DiveComputerModel. This can be removed once that is integrated into the undo system. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: use C accessors in core/libdivecomputer.c instead of callbackGravatar Berthold Stoeger
Searching the proper device for the divecomputer was done via a callback. Very hard to follow code. Since we can now access "struct device" from C, obtain it directly via get_device_for_dc(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: make get_device_for_dc() accessible from CGravatar Berthold Stoeger
The function getDCExact() was used to search for a device structure matching a divecomputer. Since C code can now access struct device, we can export that function to C. Rename it to get_device_for_dc() for consistency with naming of the core functions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16core: add C struct device and struct device_table accessorsGravatar Berthold Stoeger
Up to now, "struct device" and "struct device_table" were C++ only, because they used C++ strings for convenience. Since we switched from QString to std::string, we can create accessors for these structs. For the C code, we simply declare them as opaque structs and give the full definition only for C++. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16cleanup: use std::vector in struct device_tableGravatar Berthold Stoeger
Since we converted from QString to std::string, let's also use std::vector instead of QVector. We don't need COW semantics and all the rigmarole. Let's try to keep Qt data structures out of the core. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16cleanup: use std::string in struct deviceGravatar Berthold Stoeger
struct device is a core data structure and therefore shouldn't use QString. QString stores as UTF-16 (which is a very questionable choice in itself). However, the real problem is that this puts us in lifetime-management hell when interfacing with C code: The UTF-16 has to be converted to UTF-8, but when returning such a string, this puts burden on the caller who has to free it. In fact, instead of looping over devices from C-code we had a callback that sent down temporary C-strings with qPrintable. In contrast, std::string is guaranteed to store its data as contiguous null-terminated and C-compatible strings. Therefore, replace the QString by std::string. Keep the QString just in one place that formats a hexadecimal number to avoid any potential change. The disadvantage of using std::string is that it will crash when constructed with a NULL argument, consistent with C-style functions such as strcmp, etc. Arguably, NULL is different from the empty string even though we treat both as the same. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16cleanup: fix tiny memory hole in device.cppGravatar Berthold Stoeger
empty_string() returns true for "". Thus, we can't simply overwrite the pointer if empyt_string() returns true, but must free the string regardless. The joys of C memory management! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-16Duration is in secondsGravatar Miika Turkia
The dive duration is given in seconds in the Shearwater cloud database. (At least nowadays.) Signed-off-by: Miika Turkia <miika.turkia@gmail.com>
2020-10-16parser: fix parsing of DAN filesGravatar Berthold Stoeger
The last two parameters of the parse_dan_format() function were mixed up: sites should come before filter_presets. This should have caused crashes, for DAN files with dive sites. I don't understand why this didn't cause compiler warnings. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-13core: fix detection of duplicate device namesGravatar Berthold Stoeger
Recently (c9b8584bd2) the sort criteria of the device-table was changed from (model/id) to (id/model). However, that messed with the detection of duplicate device names: there, the code searched for the first element greater or equal to (model / 0). With the reversal of the sort criteria, this would now always give the first element. Therefore, do a simple non-binary search, which is much more robust. The binary search was a silly and pointless premature optimization anyway - don't do such things if not necessary! Since only one place in the code search for existence for a model-name, fold the corresponding function into that place. Moreover, change the code to do a case-insensitive compare. This is consistent with the dc_match_serial() code in core/libdivecomputer.c, where matching models is case-insensitive! Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-13cleanup: remove unused function is_default_dive_computer()Gravatar Berthold Stoeger
The last actual user was apparently removed back in 2013(!): 34db6dc2bea6173c070c9820a2e57a511b9ca0b1 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-11core: sort device-table by id/model instead of model/idGravatar Berthold Stoeger
The device table is accessed by core via a callback using call_for_each_dc(). This sorts the table by device-id. It is unclear whether this is needed - since currently all it does is make sure that the devices have a fixed order in XML and git log files. In any case, this means that the table had to be copied and sorted in call_for_each_dc(). Since the frontend now does its own sorting, we can just keep the core table sorted as it needs it. This in turn will ultimately make it possible to replace the callback by a simple loop. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-06cleanup: use pointer-to-function connect() in ConfigureDiveComputerGravatar Berthold Stoeger
This version is compile-time checked and therefore less risky with respect to refactoring. Since the same three signals were connect()ed for three different threads-objects, do this in a new function. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-05core: don't merge sample-derived pressures in merge_one_cylinder()Gravatar Berthold Stoeger
These will be recalculated from the pressures in fixup_dive() anyway. Suggested-by: Linus Torvalds <torvalds@linux-foundation.org> Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-05core: improve merging of cylinders pressuresGravatar Berthold Stoeger
When merging cylinders pressures derived from samples were taken as maximum of the start and minimum of the end pressure, which makes sense, since we believe that this is the same cylinder. However, for manually entered pressures, this was not done. Moreover, when one dive had manual pressures and the other only pressure from samples, the manual pressure was taken. However, that could have been the wrong one, for example if the end pressure was manually set for the cylinder of the first part of the dive, but not the last. Therefore, improve merging of manuall set pressures in two ways: 1) use maximum/minimum for start/end pressure 2) if the pressure of one cylinder was manually set, but not for the other, complete with the sample pressure (if that exists). Fixes #2884. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-05cleanup: remove libdc_serial field in device_data_tGravatar Berthold Stoeger
This was only set but never read. Therefore, remove it. Divecomputer serial numbers are now handled via a string-based interface. We can't remove the integer-based firmware number, because that is still used by the OSTC firmware check in ConfigureDiveComputerDialog. Let's not risk breaking that. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-05cleanup: remove DC_FIELD_STRING conditional compilationGravatar Berthold Stoeger
This dates from 2014 - this should be obsolete: we certainly don't support such old libdivecomputer versions. Moreover, we bundle our own anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-05download from dive computer: correctly list transports triedGravatar Dirk Hohndel
Instead of just 'BT' or 'device name' (which is wrong in cases where we don't use a device name in the first place, like USBHID), try to list the actual transports that we will consider. A big part of this patch is just moving code around so we don't need a forward declaration of the static helper function. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-05libdc/debug: provide better info regarding libdc interactionGravatar Dirk Hohndel
Instead of just sending this to the user through the progress bar text, also send things to stderr in verbose mode. That should make it easier to debug situations where we fail to download from a dive computer. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-10-05Use get_n2 helper functionGravatar Robert C. Helling
Now, that we have this helper function that should have been introduced long ago, we can make some more expressions more idiomatic. Signed-off-by: Robert C. Helling <helling@atdotde.de>
2020-10-03cleanup: make device code more consistent with coreGravatar Berthold Stoeger
We keep track of device, i.e. distinct dive computers with id in the core. The corresponding code stuck out like a sore thumb. Firstly, because it is C++. But more importantly, because it used inconsistent nameing conventions. Notably it defined a "DiveComputerNode" when this is something very different from "struct dive_computer", the latter being the dive-computer related data of a single dive. Since the whole thing is defined in "device.h" and the function to create such an entry is called "create_device_node", call the structure "device". Use snake_case for consistency with the other core structures. Moreover, call the collection of devices "device_table" in analogy with "dive_table", etc. Overall, this should make the core code more consistent style-wise. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03cleanup: use getDCExact() instead of callback in set_dc_deviceid()Gravatar Berthold Stoeger
core/device.c used to be a C file, which couldn't access the C++ divecomputer list directly. Therefore, instead of a simple loop, searching for a matching DC was implemented via a callback with void * user data parameter. Wild. Since the file is now C++, let's just use direct access to the C++ data structures to make this readable by mere humans. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03cleanup: pass divecomputer to getDC() and getDCExact() helpersGravatar Berthold Stoeger
These are used to search for device nodes and were passed model and device id (for the exact version). However, all callers used them to search for the node corresponding to a specific struct divecomputer, so let's just pass that instead to make the caller site less complex. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03cleanup: hide DiveComputerList implementation detailsGravatar Berthold Stoeger
Remove the declaration of helper functions needed only in core/device.cpp. To this goal, turn the member functions into free functions. Cosmetics: turn the DiveComputer[Node|List] "class"es into "struct"s, since all members were public anyway. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03filter: add tank size filter constraintGravatar Berthold Stoeger
This is an actual user request. Fixes #1787. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03filter: implement filtering for gas mixesGravatar Berthold Stoeger
This adds filter constraints for numerical filtering for gas-mixes. Currently, this does a "match any" kind of search, which means that a dive is filtered if any of its cylinders matches. We should also implement "all-of" and "none-of" modes for cylinder filtering. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03core: add N2 and general gas component accessorsGravatar Berthold Stoeger
There were helper functions to access O2 and He component fractions. Add another one for N2. Indeed, this can be used in three cases, where N2 was deduced indirectly. Moreover, add a general accessor with a gas_component argument. This will be used by the filter code to filter for gas components. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03core: make gas type enum globally availableGravatar Berthold Stoeger
The deco-routines used an enum to pass around the inert gas type. Make that globally available and make it include O2. This will be used in a future commit to generalize access of gas fractions. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03cleanup: use getDiveSelection() to loop over selected divesGravatar Berthold Stoeger
getDiveSelection() returns a vector of the selected dives. Use that instead of looping over the dive table and checking manually. This removes a few lines of code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-03cleanup: replace get_trip_date_string() by get_trip_string()Gravatar Berthold Stoeger
The get_trip_date_string() formatted, as the name implies, the date of a trip. It was passed a number of parameters and had only one caller, which would also add the location if it existed. Therefore, move all that logic into the helper function and name it get_trip_string(). Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
2020-10-01membuffer: be defensive about bad C library vsnprintf implementationsGravatar Linus Torvalds
Dirk reports that some Windows users have had odd corruption in the commit messages in the cloud storage. They make no sense at all unless there is some very weird Windows library bug. The prime suspect is 'vsnprintf()' returning a negative error when the target buffer is too small (rather than the proper "this is how much space it would need"). That is a very traditional C library bug that I thougth had been fixed everywhere, but there doesn't really seem to be a lot of other likely causes. So let's make our membuffer code be defensive against bad libraries that return negative error numbers from vsnprintf. Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2020-09-30Android BLE discovery: use discovery agentGravatar Dirk Hohndel
Android can't scan for classic BT devices, so when BT support was first added, we simply didn't use the discovery agent at all and relied on the list of paired BT devices provided by Android. This still worked fine for a lot of BLE devices that allowed 'bonding' with the Android device - similar to pairing. But some BLE devices (like the Shearwater Peregrine) don't support bonding and so our Android code didn't see them at all. With this commit we start a BLE only scan on Android to add to the list of already paired devices. Fixes: #2974 Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
2020-09-30bluetooth discovery: report more information about progressGravatar Dirk Hohndel
We certainly should log errors and the complete list of discovered devices. Also, it's good practice to set a specific search time (I picked three minutes). This way we won't constantly scan and drain resources. Signed-off-by: Dirk Hohndel <dirk@hohndel.org>