From bce5d9579c045482bb54f51564a3ce3277c3fc6f Mon Sep 17 00:00:00 2001 From: Denis Kenzior Date: Wed, 22 Apr 2015 17:57:53 -0500 Subject: [PATCH] gatchat: Introduce g_at_chat_get_userdata --- gatchat/gatchat.c | 31 +++++++++++++++++++++++++++++++ gatchat/gatchat.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c index aaf6e9b1..33bfc212 100644 --- a/gatchat/gatchat.c +++ b/gatchat/gatchat.c @@ -1135,6 +1135,29 @@ static gboolean at_chat_cancel_group(struct at_chat *chat, guint group) return TRUE; } +static gpointer at_chat_get_userdata(struct at_chat *chat, + guint group, guint id) +{ + GList *l; + struct at_command *c; + + if (chat->command_queue == NULL) + return NULL; + + l = g_queue_find_custom(chat->command_queue, GUINT_TO_POINTER(id), + at_command_compare_by_id); + + if (l == NULL) + return NULL; + + c = l->data; + + if (c->gid != group) + return NULL; + + return c->user_data; +} + static guint at_chat_register(struct at_chat *chat, guint group, const char *prefix, GAtNotifyFunc func, gboolean expect_pdu, gpointer user_data, @@ -1540,6 +1563,14 @@ gboolean g_at_chat_cancel_all(GAtChat *chat) return at_chat_cancel_group(chat->parent, chat->group); } +gpointer g_at_chat_get_userdata(GAtChat *chat, guint id) +{ + if (chat == NULL) + return NULL; + + return at_chat_get_userdata(chat->parent, chat->group, id); +} + guint g_at_chat_register(GAtChat *chat, const char *prefix, GAtNotifyFunc func, gboolean expect_pdu, gpointer user_data, diff --git a/gatchat/gatchat.h b/gatchat/gatchat.h index 367581ee..7290b34f 100644 --- a/gatchat/gatchat.h +++ b/gatchat/gatchat.h @@ -150,6 +150,8 @@ guint g_at_chat_send_and_expect_short_prompt(GAtChat *chat, const char *cmd, gboolean g_at_chat_cancel(GAtChat *chat, guint id); gboolean g_at_chat_cancel_all(GAtChat *chat); +gpointer g_at_chat_get_userdata(GAtChat *chat, guint id); + guint g_at_chat_register(GAtChat *chat, const char *prefix, GAtNotifyFunc func, gboolean expect_pdu, gpointer user_data, GDestroyNotify notify);