summaryrefslogtreecommitdiff
path: root/gatchat
diff options
context:
space:
mode:
authorDenis Kenzior <denkenz@gmail.com>2009-06-15 16:37:13 -0500
committerMarcel Holtmann <marcel@holtmann.org>2009-06-30 12:43:38 -0700
commit726628df95cfbc82f5481d3123bd23e00376ea36 (patch)
tree78d05b667dfdb62efb5862b3c911742cd8ce3bf5 /gatchat
parent28ec7532c4e5a483d20f6c8d228b5692791fd04b (diff)
downloadconnman-726628df95cfbc82f5481d3123bd23e00376ea36.tar.gz
connman-726628df95cfbc82f5481d3123bd23e00376ea36.tar.bz2
connman-726628df95cfbc82f5481d3123bd23e00376ea36.zip
Add g_at_send_listing function
Diffstat (limited to 'gatchat')
-rw-r--r--gatchat/gatchat.c48
-rw-r--r--gatchat/gatchat.h12
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,