Add g_at_send_listing function
authorDenis Kenzior <denkenz@gmail.com>
Mon, 15 Jun 2009 21:37:13 +0000 (16:37 -0500)
committerMarcel Holtmann <marcel@holtmann.org>
Tue, 30 Jun 2009 19:43:38 +0000 (12:43 -0700)
gatchat/gatchat.c
gatchat/gatchat.h

index af2147b..0a37372 100644 (file)
@@ -60,6 +60,7 @@ struct at_command {
        char **prefixes;
        guint id;
        GAtResultFunc callback;
+       GAtNotifyFunc listing;
        gpointer user_data;
        GDestroyNotify notify;
 };
@@ -145,6 +146,7 @@ static gint at_command_compare_by_id(gconstpointer a, gconstpointer b)
 
 static struct at_command *at_command_create(const char *cmd,
                                                const char **prefix_list,
+                                               GAtNotifyFunc listing,
                                                GAtResultFunc func,
                                                gpointer user_data,
                                                GDestroyNotify notify)
@@ -195,6 +197,7 @@ static struct at_command *at_command_create(const char *cmd,
 
        c->prefixes = prefixes;
        c->callback = func;
+       c->listing = listing;
        c->user_data = user_data;
        c->notify = notify;
 
@@ -412,8 +415,18 @@ out:
        if (!(p->flags & G_AT_CHAT_FLAG_NO_LEADING_CRLF))
                p->state = PARSER_STATE_GUESS_MULTILINE_RESPONSE;
 
-       p->response_lines = g_slist_prepend(p->response_lines,
-                                               line);
+       if (cmd->listing) {
+               GAtResult result;
+
+               result.lines = g_slist_prepend(NULL, line);
+               result.final_or_pdu = NULL;
+
+               cmd->listing(&result, cmd->user_data);
+
+               g_slist_free(result.lines);
+               g_free(line);
+       } else
+               p->response_lines = g_slist_prepend(p->response_lines, line);
 
        return TRUE;
 }
@@ -787,7 +800,8 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond,
        }
 
        if (chat->cmd_bytes_written == 0 && wakeup_first == TRUE) {
-               cmd = at_command_create(chat->wakeup, NULL, NULL, NULL, NULL);
+               cmd = at_command_create(chat->wakeup, NULL, NULL, NULL,
+                                       NULL, NULL);
 
                if (!cmd)
                        return FALSE;
@@ -973,8 +987,9 @@ gboolean g_at_chat_set_disconnect_function(GAtChat *chat,
        return TRUE;
 }
 
-guint g_at_chat_send(GAtChat *chat, const char *cmd,
-                       const char **prefix_list, GAtResultFunc func,
+static guint send_common(GAtChat *chat, const char *cmd,
+                       const char **prefix_list,
+                       GAtNotifyFunc listing, GAtResultFunc func,
                        gpointer user_data, GDestroyNotify notify)
 {
        struct at_command *c;
@@ -982,7 +997,8 @@ guint g_at_chat_send(GAtChat *chat, const char *cmd,
        if (chat == NULL || chat->command_queue == NULL)
                return 0;
 
-       c = at_command_create(cmd, prefix_list, func, user_data, notify);
+       c = at_command_create(cmd, prefix_list, listing, func,
+                               user_data, notify);
 
        if (!c)
                return 0;
@@ -997,6 +1013,26 @@ guint g_at_chat_send(GAtChat *chat, const char *cmd,
        return c->id;
 }
 
+guint g_at_chat_send(GAtChat *chat, const char *cmd,
+                       const char **prefix_list, GAtResultFunc func,
+                       gpointer user_data, GDestroyNotify notify)
+{
+       return send_common(chat, cmd, prefix_list, NULL, func,
+                               user_data, notify);
+}
+
+guint g_at_chat_send_listing(GAtChat *chat, const char *cmd,
+                               const char **prefix_list,
+                               GAtNotifyFunc listing, GAtResultFunc func,
+                               gpointer user_data, GDestroyNotify notify)
+{
+       if (listing == NULL)
+               return 0;
+
+       return send_common(chat, cmd, prefix_list, listing, func,
+                               user_data, notify);
+}
+
 gboolean g_at_chat_cancel(GAtChat *chat, guint id)
 {
        GList *l;
index 58ca911..52c6b36 100644 (file)
@@ -86,6 +86,18 @@ guint g_at_chat_send(GAtChat *chat, const char *cmd,
                                const char **valid_resp, GAtResultFunc func,
                                gpointer user_data, GDestroyNotify notify);
 
+/*!
+ * Same as the above command, except that the caller wishes to receive the
+ * intermediate responses immediately through the GAtNotifyFunc callback.
+ * The final response will still be sent to GAtResultFunc callback.  The
+ * final GAtResult will not contain any lines from the intermediate responses.
+ * This is useful for listing commands such as CMGL or CPBR.
+ */
+guint g_at_chat_send_listing(GAtChat *chat, const char *cmd,
+                               const char **valid_resp,
+                               GAtNotifyFunc listing, GAtResultFunc func,
+                               gpointer user_data, GDestroyNotify notify);
+
 gboolean g_at_chat_cancel(GAtChat *chat, guint id);
 
 guint g_at_chat_register(GAtChat *chat, const char *prefix,