Teach uemis downloader about downloading into private trips

Now that we pass in the full device_data_t information, we can look at
the "create_private_dive" flag and decide just how to record newly
downloaded dives properly.

Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Linus Torvalds 2014-10-12 07:11:34 -04:00 committed by Dirk Hohndel
parent a7e1e7fee1
commit b47e0658cf

View file

@ -120,6 +120,17 @@ static struct dive *uemis_start_dive(uint32_t deviceid)
return dive; return dive;
} }
static void record_uemis_dive(device_data_t *devdata, struct dive *dive)
{
if (devdata->create_new_trip) {
if (!devdata->trip)
devdata->trip = create_and_hookup_trip_from_dive(dive);
else
add_dive_to_trip(dive, devdata->trip);
}
record_dive(dive);
}
/* send text to the importer progress bar */ /* send text to the importer progress bar */
static void uemis_info(const char *fmt, ...) static void uemis_info(const char *fmt, ...)
{ {
@ -681,7 +692,7 @@ static void parse_tag(struct dive *dive, char *tag, char *val)
* index into yet another data store that we read out later. In order to * index into yet another data store that we read out later. In order to
* correctly populate the location and gps data from that we need to remember * correctly populate the location and gps data from that we need to remember
* the adresses of those fields for every dive that references the divespot. */ * the adresses of those fields for every dive that references the divespot. */
static bool process_raw_buffer(uint32_t deviceid, char *inbuf, char **max_divenr, bool keep_number, int *for_dive) static bool process_raw_buffer(device_data_t *devdata, uint32_t deviceid, char *inbuf, char **max_divenr, bool keep_number, int *for_dive)
{ {
char *buf = strdup(inbuf); char *buf = strdup(inbuf);
char *tp, *bp, *tag, *type, *val; char *tp, *bp, *tag, *type, *val;
@ -784,14 +795,14 @@ static bool process_raw_buffer(uint32_t deviceid, char *inbuf, char **max_divenr
* be a short read because of some error */ * be a short read because of some error */
if (done && ++bp < endptr && *bp != '{' && strstr(bp, "{{")) { if (done && ++bp < endptr && *bp != '{' && strstr(bp, "{{")) {
done = false; done = false;
record_dive(dive); record_uemis_dive(devdata, dive);
mark_divelist_changed(true); mark_divelist_changed(true);
dive = uemis_start_dive(deviceid); dive = uemis_start_dive(deviceid);
} }
} }
if (log) { if (log) {
if (dive->dc.diveid) { if (dive->dc.diveid) {
record_dive(dive); record_uemis_dive(devdata, dive);
mark_divelist_changed(true); mark_divelist_changed(true);
} else { /* partial dive */ } else { /* partial dive */
free(dive); free(dive);
@ -875,7 +886,7 @@ const char *do_uemis_import(device_data_t *data)
success = uemis_get_answer(mountpath, "getDivelogs", 3, 0, &result); success = uemis_get_answer(mountpath, "getDivelogs", 3, 0, &result);
/* process the buffer we have assembled */ /* process the buffer we have assembled */
if (mbuf) if (mbuf)
if (!process_raw_buffer(deviceidnr, mbuf, &newmax, keep_number, NULL)) { if (!process_raw_buffer(data, deviceidnr, mbuf, &newmax, keep_number, NULL)) {
/* if no dives were downloaded, mark end appropriately */ /* if no dives were downloaded, mark end appropriately */
if (end == -2) if (end == -2)
end = start - 1; end = start - 1;
@ -930,7 +941,7 @@ const char *do_uemis_import(device_data_t *data)
success = uemis_get_answer(mountpath, "getDive", 3, 0, &result); success = uemis_get_answer(mountpath, "getDive", 3, 0, &result);
if (mbuf) { if (mbuf) {
int divenr; int divenr;
(void)process_raw_buffer(deviceidnr, mbuf, &newmax, false, &divenr); (void)process_raw_buffer(data, deviceidnr, mbuf, &newmax, false, &divenr);
#if UEMIS_DEBUG & 2 #if UEMIS_DEBUG & 2
fprintf(debugfile, "got dive %d, looking for dive %d\n", divenr, i); fprintf(debugfile, "got dive %d, looking for dive %d\n", divenr, i);
#endif #endif