From: Denis Kenzior <denkenz@gmail.com>
To: ofono@ofono.org
Subject: Re: [PATCH 7/7] Add g_at_server_register to register callback
Date: Wed, 03 Mar 2010 13:28:16 -0600 [thread overview]
Message-ID: <201003031328.16832.denkenz@gmail.com> (raw)
In-Reply-To: <1267628212-14079-7-git-send-email-zhenhua.zhang@intel.com>
[-- Attachment #1: Type: text/plain, Size: 2375 bytes --]
Hi Zhenhua,
> ---
> gatchat/gatserver.c | 47
+++++++++++++++++++++++++++++++++++++++++++++++
> gatchat/gatserver.h | 6 ++++++
> 2 files changed, 53 insertions(+), 0 deletions(-)
>
> diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c
> index bea51f5..c49e5f8 100644
> --- a/gatchat/gatserver.c
> +++ b/gatchat/gatserver.c
> @@ -987,3 +987,50 @@ gboolean g_at_server_set_debug(GAtServer *server,
> GAtDebugFunc func,
>
> return TRUE;
> }
> +
> +guint g_at_server_register(GAtServer *server, const char *prefix,
> + GAtServerCommandType type,
> + GAtServerNotifyFunc notify,
> + gpointer user_data,
> + GDestroyNotify destroy_notify)
> +{
> + struct at_command *node;
> +
> + if (server == NULL || server->command_list == NULL)
> + return 0;
> +
> + if (notify == NULL)
> + return 0;
> +
> + if (prefix == NULL || strlen(prefix) == 0)
> + return 0;
> +
> + node = g_hash_table_lookup(server->command_list, prefix);
> +
> + if (node) {
> + g_hash_table_remove(server->command_list, prefix);
> +
> + if (node->destroy_notify)
> + node->destroy_notify(node->user_data);
> +
> + g_free(node->prefix);
> +
> + g_free(node);
> + }
If you properly setup your hash table then you can simply get rid of this
part.
> +
> + node = g_try_new0(struct at_command, 1);
> +
> + if (!node)
> + return 0;
> +
> + node->id = server->next_command_id++;
> + node->prefix = g_strdup(prefix);
> + node->type = type;
> + node->notify = notify;
> + node->user_data = user_data;
> + node->destroy_notify = destroy_notify;
> +
> + g_hash_table_insert(server->command_list, node->prefix, node);
Use g_hash_table_replace here.
> +
> + return node->id;
> +}
> diff --git a/gatchat/gatserver.h b/gatchat/gatserver.h
> index 5db9321..59cdf25 100644
> --- a/gatchat/gatserver.h
> +++ b/gatchat/gatserver.h
> @@ -80,6 +80,12 @@ gboolean g_at_server_set_debug(GAtServer *server,
> GAtDebugFunc func,
> gpointer user);
>
> +guint g_at_server_register(GAtServer *server, const char *prefix,
> + GAtServerCommandType type,
> + GAtServerNotifyFunc notify,
> + gpointer user_data,
> + GDestroyNotify destroy_notify);
Return a gboolean here. And where's my unregister function?
> +
> #ifdef __cplusplus
> }
> #endif
>
Regards,
-Denis
next prev parent reply other threads:[~2010-03-03 19:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-03 14:56 [PATCH 1/7] Remove old server_parse_line Zhenhua Zhang
2010-03-03 14:56 ` [PATCH 2/7] Add framework of server parser Zhenhua Zhang
2010-03-03 14:56 ` [PATCH 3/7] Add basic command parsing Zhenhua Zhang
2010-03-03 14:56 ` [PATCH 4/7] Add extended " Zhenhua Zhang
2010-03-03 14:56 ` [PATCH 5/7] Add server at command data structure Zhenhua Zhang
2010-03-03 14:56 ` [PATCH 6/7] Add notify at command callback Zhenhua Zhang
2010-03-03 14:56 ` [PATCH 7/7] Add g_at_server_register to register callback Zhenhua Zhang
2010-03-03 19:28 ` Denis Kenzior [this message]
2010-03-04 1:41 ` Zhenhua Zhang
2010-03-03 19:23 ` [PATCH 5/7] Add server at command data structure Denis Kenzior
2010-03-04 1:40 ` Zhenhua Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201003031328.16832.denkenz@gmail.com \
--to=denkenz@gmail.com \
--cc=ofono@ofono.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox