From 726628df95cfbc82f5481d3123bd23e00376ea36 Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Mon, 15 Jun 2009 16:37:13 -0500 Subject: [PATCH] Add g_at_send_listing function --- gatchat/gatchat.c | 48 +++++++++++++++++++++++++++++++++++++++++------ gatchat/gatchat.h | 12 ++++++++++++ 2 files changed, 54 insertions(+), 6 deletions(-) diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c index af2147bf..0a373721 100644 --- a/gatchat/gatchat.c +++ b/gatchat/gatchat.c @@ -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; diff --git a/gatchat/gatchat.h b/gatchat/gatchat.h index 58ca9114..52c6b368 100644 --- a/gatchat/gatchat.h +++ b/gatchat/gatchat.h @@ -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, -- 2.34.1