]> git.street.me.uk Git - andy/viking.git/blobdiff - src/babel.h
Threading rewrite to remove use of unsupported cross platform threading update of...
[andy/viking.git] / src / babel.h
index bc8e85bb915c516a0bdaab8a2e88dceb48481a3a..ae2fa95917d7c2ac9b98b06865b8c902e441e8ab 100644 (file)
@@ -3,6 +3,7 @@
  *
  * Copyright (C) 2003-2005, Evan Battaglia <gtoevan@gmx.net>
  * Copyright (C) 2005, Alex Foobarian <foobarian@gmail.com>
+ * Copyright (C) 2015, Rob Norris <rw_norris@hotmail.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
 #ifndef _VIKING_BABEL_H
 #define _VIKING_BABEL_H
 
+#include <glib.h>
+
+#include "viktrwlayer.h"
+#include "download.h"
+
+G_BEGIN_DECLS
+
+/**
+ * BabelProgressCode:
+ * @BABEL_DIAG_OUTPUT: a line of diagnostic output is available. The pointer is to a 
+ *                     NULL-terminated line of diagnostic output from gpsbabel.
+ * @BABEL_DONE: gpsbabel finished, or %NULL if no callback is needed.
+ *
+ * Used when calling #BabelStatusFunc.
+ */
 typedef enum {
   BABEL_DIAG_OUTPUT,
   BABEL_DONE,
 } BabelProgressCode;
 
-typedef void (*BabelStatusFunc)(BabelProgressCode, gpointer);
+/**
+ * BabelStatusFunc:
+ *
+ * Callback function.
+ */
+typedef void (*BabelStatusFunc)(BabelProgressCode, gpointer, gpointer);
 
-/*
- * a_babel_convert modifies data in a trw layer using gpsbabel filters.  This routine is synchronous;
- * that is, it will block the calling program until the conversion is done.  To avoid blocking, call
- * this routine from a worker thread.  The arguments are as follows:
- * 
- * vt              The TRW layer to modify.  All data will be deleted, and replaced by what gpsbabel outputs.
- * 
- * babelargs       A string containing gpsbabel command line filter options.  No file types or names should
- *                 be specified.
- * 
- * cb             A callback function, called with the following status codes:
- *                   BABEL_DIAG_OUTPUT: a line of diagnostic output is available.  The pointer is to a 
- *                                      NUL-terminated line of diagnostic output from gpsbabel.
- *                   BABEL_DIAG_DONE: gpsbabel finished,
- *                 or NULL if no callback is needed.
+/**
+ * ProcessOptions:
+ *
+ * All values are defaulted to NULL
+ *
+ * Need to specify at least one of babelargs, URL or shell_command
  */
-int a_babel_convert( VikTrwLayer *vt, const char *babelargs, BabelStatusFunc cb );
+typedef struct {
+  gchar* babelargs; // The standard initial arguments to gpsbabel (if gpsbabel is to be used) - normally should include the input file type (-i) option.
+  gchar* filename; // Input filename (or device port e.g. /dev/ttyS0)
+  gchar* input_file_type; // If NULL then uses internal file format handler (GPX only ATM), otherwise specify gpsbabel input type like "kml","tcx", etc...
+  gchar* url; // URL input rather than a filename
+  gchar* babel_filters; // Optional filter arguments to gpsbabel
+  gchar* shell_command; // Optional shell command to run instead of gpsbabel - but will be (Unix) platform specific
+} ProcessOptions;
 
-/*
- * a_babel_convert_from loads data into a trw layer from a file, using gpsbabel.  This routine is synchronous;
- * that is, it will block the calling program until the conversion is done.  To avoid blocking, call
- * this routine from a worker thread. The arguments are as follows:
+/**
+ * BabelMode:
  * 
- * vt              The TRW layer to place data into.  Duplicate items will be overwritten. 
+ * Store the Read/Write support offered by gpsbabel for a given format.
+ */
+typedef struct {
+    unsigned waypointsRead : 1;
+    unsigned waypointsWrite : 1;
+    unsigned tracksRead : 1;
+    unsigned tracksWrite : 1;
+    unsigned routesRead : 1;
+    unsigned routesWrite : 1;
+} BabelMode;
+
+/**
+ * BabelDevice:
+ * @name: gpsbabel's identifier of the device
+ * @label: human readable label
  * 
- * babelargs       A string containing gpsbabel command line options.  In addition to any filters, this string
- *                 must include the input file type (-i) option. 
+ * Representation of a supported device.
+ */
+typedef struct {
+    BabelMode mode;
+    gchar *name;
+    gchar *label;
+} BabelDevice;
+
+/**
+ * BabelFile:
+ * @name: gpsbabel's identifier of the format
+ * @ext: file's extension for this format
+ * @label: human readable label
  * 
- * cb             Optional callback function. Same usage as in a_babel_convert.
+ * Representation of a supported file format.
  */
-int a_babel_convert_from( VikTrwLayer *vt, const char *babelargs, BabelStatusFunc cb, const char *file );
+typedef struct {
+    BabelMode mode;
+    gchar *name;
+    gchar *ext;
+    gchar *label;
+} BabelFile;
+
+GList *a_babel_file_list;
+GList *a_babel_device_list;
+
+void a_babel_foreach_file_with_mode (BabelMode mode, GFunc func, gpointer user_data);
+void a_babel_foreach_file_read_any (GFunc func, gpointer user_data);
+
+// NB needs to match typedef VikDataSourceProcessFunc in acquire.h
+gboolean a_babel_convert_from ( VikTrwLayer *vt, ProcessOptions *process_options, BabelStatusFunc cb, gpointer user_data, DownloadFileOptions *download_options );
+
+gboolean a_babel_convert_to( VikTrwLayer *vt, VikTrack *track, const char *babelargs, const char *file, BabelStatusFunc cb, gpointer user_data );
+
+void a_babel_init ();
+void a_babel_post_init ();
+void a_babel_uninit ();
+
+gboolean a_babel_available ();
+
+G_END_DECLS
 
 #endif