Add g_at_send_listing function

This commit is contained in:
Denis Kenzior 2009-06-15 16:37:13 -05:00
parent f00af45270
commit 69372e642e
2 changed files with 54 additions and 6 deletions

View File

@ -60,6 +60,7 @@ struct at_command {
char **prefixes; char **prefixes;
guint id; guint id;
GAtResultFunc callback; GAtResultFunc callback;
GAtNotifyFunc listing;
gpointer user_data; gpointer user_data;
GDestroyNotify notify; 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, static struct at_command *at_command_create(const char *cmd,
const char **prefix_list, const char **prefix_list,
GAtNotifyFunc listing,
GAtResultFunc func, GAtResultFunc func,
gpointer user_data, gpointer user_data,
GDestroyNotify notify) GDestroyNotify notify)
@ -195,6 +197,7 @@ static struct at_command *at_command_create(const char *cmd,
c->prefixes = prefixes; c->prefixes = prefixes;
c->callback = func; c->callback = func;
c->listing = listing;
c->user_data = user_data; c->user_data = user_data;
c->notify = notify; c->notify = notify;
@ -412,8 +415,18 @@ out:
if (!(p->flags & G_AT_CHAT_FLAG_NO_LEADING_CRLF)) if (!(p->flags & G_AT_CHAT_FLAG_NO_LEADING_CRLF))
p->state = PARSER_STATE_GUESS_MULTILINE_RESPONSE; p->state = PARSER_STATE_GUESS_MULTILINE_RESPONSE;
p->response_lines = g_slist_prepend(p->response_lines, if (cmd->listing) {
line); 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; return TRUE;
} }
@ -787,7 +800,8 @@ static gboolean can_write_data(GIOChannel *channel, GIOCondition cond,
} }
if (chat->cmd_bytes_written == 0 && wakeup_first == TRUE) { 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) if (!cmd)
return FALSE; return FALSE;
@ -973,8 +987,9 @@ gboolean g_at_chat_set_disconnect_function(GAtChat *chat,
return TRUE; return TRUE;
} }
guint g_at_chat_send(GAtChat *chat, const char *cmd, static guint send_common(GAtChat *chat, const char *cmd,
const char **prefix_list, GAtResultFunc func, const char **prefix_list,
GAtNotifyFunc listing, GAtResultFunc func,
gpointer user_data, GDestroyNotify notify) gpointer user_data, GDestroyNotify notify)
{ {
struct at_command *c; 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) if (chat == NULL || chat->command_queue == NULL)
return 0; 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) if (!c)
return 0; return 0;
@ -997,6 +1013,26 @@ guint g_at_chat_send(GAtChat *chat, const char *cmd,
return c->id; 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) gboolean g_at_chat_cancel(GAtChat *chat, guint id)
{ {
GList *l; GList *l;

View File

@ -86,6 +86,18 @@ guint g_at_chat_send(GAtChat *chat, const char *cmd,
const char **valid_resp, GAtResultFunc func, const char **valid_resp, GAtResultFunc func,
gpointer user_data, GDestroyNotify notify); 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); gboolean g_at_chat_cancel(GAtChat *chat, guint id);
guint g_at_chat_register(GAtChat *chat, const char *prefix, guint g_at_chat_register(GAtChat *chat, const char *prefix,