From: Rob Norris Date: Thu, 6 Oct 2011 18:09:36 +0000 (+0100) Subject: Add new process stage for acquire methods. X-Git-Url: https://git.street.me.uk/andy/viking.git/commitdiff_plain/0944940fe9a9268a45669a140cac4c5e3d1cd036?hp=f965a4b9a7ce37c4f9529900825cd971633b4d20 Add new process stage for acquire methods. This is designed to handle the main event of conversion / whatever processing is to be done. ATM only invoked for the new VIK_DATASOURCE_INTERNAL type. --- diff --git a/src/acquire.c b/src/acquire.c index 1a65e91f..a71df622 100644 --- a/src/acquire.c +++ b/src/acquire.c @@ -119,6 +119,7 @@ static void get_from_anything ( w_and_interface_t *wi ) } gdk_threads_leave(); + // TODO consider removing 'type' and make everything run via the specficied process function switch ( source_interface->type ) { case VIK_DATASOURCE_GPSBABEL_DIRECT: result = a_babel_convert_from (vtl, cmd, (BabelStatusFunc) progress_func, extra, w); @@ -129,6 +130,10 @@ static void get_from_anything ( w_and_interface_t *wi ) case VIK_DATASOURCE_SHELL_CMD: result = a_babel_convert_from_shellcommand ( vtl, cmd, extra, (BabelStatusFunc) progress_func, w); break; + case VIK_DATASOURCE_INTERNAL: + if ( source_interface->process_func ) + result = source_interface->process_func ( vtl, cmd, extra, (BabelStatusFunc) progress_func, w ); + break; default: g_critical("Houston, we've had a problem."); } @@ -224,7 +229,8 @@ static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikD /* for manual dialogs */ GtkWidget *dialog = NULL; GtkWidget *status; - gchar *cmd, *extra; + gchar *cmd = NULL; + gchar *extra = NULL; gchar *cmd_off = NULL; gchar *extra_off = NULL; acq_dialog_widgets_t *w; @@ -315,8 +321,8 @@ static void acquire ( VikWindow *vw, VikLayersPanel *vlp, VikViewport *vvp, VikD ( pass_along_data, &cmd, &extra, name_src_track ); g_free ( name_src_track ); - } else - source_interface->get_cmd_string_func ( pass_along_data, &cmd, &extra ); + } else if ( source_interface->get_cmd_string_func ) + source_interface->get_cmd_string_func ( pass_along_data, &cmd, &extra ); /* Get data for Off command */ if ( source_interface->off_func ) { diff --git a/src/acquire.h b/src/acquire.h index d6cd2246..8b8eb929 100644 --- a/src/acquire.h +++ b/src/acquire.h @@ -27,6 +27,7 @@ #include "vikwindow.h" #include "viklayerspanel.h" #include "vikviewport.h" +#include "babel.h" typedef struct _VikDataSourceInterface VikDataSourceInterface; @@ -42,10 +43,12 @@ typedef struct { gpointer user_data; } acq_dialog_widgets_t; +/* Direct, URL & Shell types process the results with GPSBabel to create tracks/waypoint */ typedef enum { VIK_DATASOURCE_GPSBABEL_DIRECT, VIK_DATASOURCE_URL, - VIK_DATASOURCE_SHELL_CMD + VIK_DATASOURCE_SHELL_CMD, + VIK_DATASOURCE_INTERNAL } vik_datasource_type_t; typedef enum { @@ -79,6 +82,9 @@ typedef void (*VikDataSourceGetCmdStringFunc) ( gpointer user_data, gchar **babe typedef void (*VikDataSourceGetCmdStringFuncWithInput) ( gpointer user_data, gchar **babelargs_or_shellcmd, gchar **inputfile_or_inputtype, const gchar *input_file_name ); typedef void (*VikDataSourceGetCmdStringFuncWithInputInput) ( gpointer user_data, gchar **babelargs_or_shellcmd, gchar **inputfile_or_inputtype, const gchar *input_file_name, const gchar *input_track_file_name ); +/* The actual function to do stuff - must report success/failure */ +typedef gboolean (*VikDataSourceProcessFunc) ( gpointer vtl, const gchar *cmd, const gchar *extra, BabelStatusFunc status_cb, acq_dialog_widgets_t *adw ); + /* */ typedef void (*VikDataSourceProgressFunc) (gpointer c, gpointer data, acq_dialog_widgets_t *w); @@ -109,6 +115,8 @@ struct _VikDataSourceInterface { /* or VikDataSourceGetCmdStringFuncWithInput, if inputtype is not NONE */ VikDataSourceGetCmdStringFunc get_cmd_string_func; + VikDataSourceProcessFunc process_func; + VikDataSourceProgressFunc progress_func; VikDataSourceAddProgressWidgetsFunc add_progress_widgets_func; VikDataSourceCleanupFunc cleanup_func; diff --git a/src/datasource_bfilter.c b/src/datasource_bfilter.c index fb237496..78dbe9c7 100644 --- a/src/datasource_bfilter.c +++ b/src/datasource_bfilter.c @@ -66,6 +66,7 @@ VikDataSourceInterface vik_datasource_bfilter_simplify_interface = { FALSE, /* keep dialog open after success */ NULL, NULL, NULL, (VikDataSourceGetCmdStringFunc) datasource_bfilter_simplify_get_cmd_string, + (VikDataSourceProcessFunc) NULL, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -101,6 +102,7 @@ VikDataSourceInterface vik_datasource_bfilter_dup_interface = { FALSE, /* keep dialog open after success */ NULL, NULL, NULL, (VikDataSourceGetCmdStringFunc) datasource_bfilter_dup_get_cmd_string, + (VikDataSourceProcessFunc) NULL, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -133,6 +135,7 @@ VikDataSourceInterface vik_datasource_bfilter_polygon_interface = { FALSE, /* keep dialog open after success */ NULL, NULL, NULL, (VikDataSourceGetCmdStringFunc) datasource_bfilter_polygon_get_cmd_string, + (VikDataSourceProcessFunc) NULL, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, @@ -168,6 +171,7 @@ VikDataSourceInterface vik_datasource_bfilter_exclude_polygon_interface = { FALSE, /* keep dialog open after success */ NULL, NULL, NULL, (VikDataSourceGetCmdStringFunc) datasource_bfilter_exclude_polygon_get_cmd_string, + (VikDataSourceProcessFunc) NULL, NULL, NULL, NULL, (VikDataSourceOffFunc) NULL, diff --git a/src/datasource_file.c b/src/datasource_file.c index 43896bc0..1b4daeae 100644 --- a/src/datasource_file.c +++ b/src/datasource_file.c @@ -67,6 +67,7 @@ VikDataSourceInterface vik_datasource_file_interface = { (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) datasource_file_add_setup_widgets, (VikDataSourceGetCmdStringFunc) datasource_file_get_cmd_string, + (VikDataSourceProcessFunc) NULL, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_file_cleanup, diff --git a/src/datasource_gc.c b/src/datasource_gc.c index 1f68e82f..b3b6b2c5 100644 --- a/src/datasource_gc.c +++ b/src/datasource_gc.c @@ -74,6 +74,7 @@ VikDataSourceInterface vik_datasource_gc_interface = { (VikDataSourceCheckExistenceFunc) datasource_gc_check_existence, (VikDataSourceAddSetupWidgetsFunc) datasource_gc_add_setup_widgets, (VikDataSourceGetCmdStringFunc) datasource_gc_get_cmd_string, + (VikDataSourceProcessFunc) NULL, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_gc_cleanup, diff --git a/src/datasource_google.c b/src/datasource_google.c index 95d4516a..10d4991a 100644 --- a/src/datasource_google.c +++ b/src/datasource_google.c @@ -57,6 +57,7 @@ VikDataSourceInterface vik_datasource_google_interface = { (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) datasource_google_add_setup_widgets, (VikDataSourceGetCmdStringFunc) datasource_google_get_cmd_string, + (VikDataSourceProcessFunc) NULL, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_google_cleanup, diff --git a/src/datasource_gps.c b/src/datasource_gps.c index 00590221..41023e92 100644 --- a/src/datasource_gps.c +++ b/src/datasource_gps.c @@ -63,6 +63,7 @@ VikDataSourceInterface vik_datasource_gps_interface = { (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) datasource_gps_add_setup_widgets, (VikDataSourceGetCmdStringFunc) datasource_gps_get_cmd_string, + (VikDataSourceProcessFunc) NULL, (VikDataSourceProgressFunc) datasource_gps_progress, (VikDataSourceAddProgressWidgetsFunc) datasource_gps_add_progress_widgets, (VikDataSourceCleanupFunc) datasource_gps_cleanup, diff --git a/src/datasource_osm.c b/src/datasource_osm.c index c7f91fe5..9315f5c8 100644 --- a/src/datasource_osm.c +++ b/src/datasource_osm.c @@ -60,6 +60,7 @@ VikDataSourceInterface vik_datasource_osm_interface = { (VikDataSourceCheckExistenceFunc) NULL, (VikDataSourceAddSetupWidgetsFunc) datasource_osm_add_setup_widgets, (VikDataSourceGetCmdStringFunc) datasource_osm_get_cmd_string, + (VikDataSourceProcessFunc) NULL, (VikDataSourceProgressFunc) NULL, (VikDataSourceAddProgressWidgetsFunc) NULL, (VikDataSourceCleanupFunc) datasource_osm_cleanup,