diff options
author | Tambet Ingo <tambet@gmail.com> | 2008-09-11 08:35:32 +0300 |
---|---|---|
committer | Tambet Ingo <tambet@gmail.com> | 2008-09-11 08:35:32 +0300 |
commit | ac4409e7cea29e03d311e6b805a084837d8bb70f (patch) | |
tree | 6b534ff91a3976a0268a89c858543bc973b17f8c /src/mm-serial.h | |
parent | bb874acea0c8552f86932084e222b45a94119f29 (diff) |
Rewrite serial device communications.
Instead of vague "send something, wait something" the responses are now
analyzed by (overridable) parsers. Makes all the modem implementations much
easier since each caller knows without any code whether the call succeeded
or failed.
Another thing that makes modem code simpler (and the whole thing more robust),
is the queueing of sent commands. Each queued command has a command and a
callback which is quaranteed to get called, even if sending failed.
Define and implement error reporting.
Diffstat (limited to 'src/mm-serial.h')
-rw-r--r-- | src/mm-serial.h | 91 |
1 files changed, 38 insertions, 53 deletions
diff --git a/src/mm-serial.h b/src/mm-serial.h index bd138516..37162c6f 100644 --- a/src/mm-serial.h +++ b/src/mm-serial.h @@ -6,12 +6,12 @@ #include <glib/gtypes.h> #include <glib-object.h> -#define MM_TYPE_SERIAL (mm_serial_get_type ()) -#define MM_SERIAL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_SERIAL, MMSerial)) -#define MM_SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_SERIAL, MMSerialClass)) -#define MM_IS_SERIAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_SERIAL)) -#define MM_IS_SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_SERIAL)) -#define MM_SERIAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_SERIAL, MMSerialClass)) +#define MM_TYPE_SERIAL (mm_serial_get_type ()) +#define MM_SERIAL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MM_TYPE_SERIAL, MMSerial)) +#define MM_SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MM_TYPE_SERIAL, MMSerialClass)) +#define MM_IS_SERIAL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MM_TYPE_SERIAL)) +#define MM_IS_SERIAL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MM_TYPE_SERIAL)) +#define MM_SERIAL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MM_TYPE_SERIAL, MMSerialClass)) #define MM_SERIAL_DEVICE "device" #define MM_SERIAL_BAUD "baud" @@ -20,66 +20,51 @@ #define MM_SERIAL_STOPBITS "stopbits" #define MM_SERIAL_SEND_DELAY "send-delay" -typedef struct { - GObject parent; -} MMSerial; - -typedef struct { - GObjectClass parent; -} MMSerialClass; - -GType mm_serial_get_type (void); - -typedef void (*MMSerialGetReplyFn) (MMSerial *serial, - const char *reply, - gpointer user_data); +typedef struct _MMSerial MMSerial; +typedef struct _MMSerialClass MMSerialClass; -typedef void (*MMSerialWaitForReplyFn) (MMSerial *serial, - int reply_index, - gpointer user_data); +typedef gboolean (*MMSerialResponseParserFn) (gpointer user_data, + GString *response, + GError **error); -typedef void (*MMSerialWaitQuietFn) (MMSerial *serial, - gboolean timed_out, +typedef void (*MMSerialResponseFn) (MMSerial *serial, + GString *response, + GError *error, gpointer user_data); typedef void (*MMSerialFlashFn) (MMSerial *serial, gpointer user_data); -const char *mm_serial_get_device (MMSerial *serial); - -gboolean mm_serial_open (MMSerial *self); +struct _MMSerial { + GObject parent; +}; -void mm_serial_close (MMSerial *self); -gboolean mm_serial_send_command (MMSerial *self, - GByteArray *command); +struct _MMSerialClass { + GObjectClass parent; +}; -gboolean mm_serial_send_command_string (MMSerial *self, - const char *str); +GType mm_serial_get_type (void); -guint mm_serial_get_reply (MMSerial *self, - guint timeout, - const char *terminators, - MMSerialGetReplyFn callback, - gpointer user_data); +void mm_serial_set_response_parser (MMSerial *self, + MMSerialResponseParserFn fn, + gpointer user_data, + GDestroyNotify notify); -guint mm_serial_wait_for_reply (MMSerial *self, - guint timeout, - char **responses, - char **terminators, - MMSerialWaitForReplyFn callback, - gpointer user_data); +gboolean mm_serial_open (MMSerial *self, + GError **error); -void mm_serial_wait_quiet (MMSerial *self, - guint timeout, - guint quiet_time, - MMSerialWaitQuietFn callback, - gpointer user_data); +void mm_serial_close (MMSerial *self); +void mm_serial_queue_command (MMSerial *self, + const char *command, + guint32 timeout_seconds, + MMSerialResponseFn callback, + gpointer user_data); -guint mm_serial_flash (MMSerial *self, - guint32 flash_time, - MMSerialFlashFn callback, - gpointer user_data); +guint mm_serial_flash (MMSerial *self, + guint32 flash_time, + MMSerialFlashFn callback, + gpointer user_data); -GIOChannel *mm_serial_get_io_channel (MMSerial *self); +const char *mm_serial_get_device (MMSerial *self); #endif /* MM_SERIAL_H */ |