diff options
author | Zhenhua Zhang <zhenhua.zhang@intel.com> | 2010-03-19 17:44:44 +0800 |
---|---|---|
committer | Denis Kenzior <denkenz@gmail.com> | 2010-03-22 12:59:04 -0500 |
commit | 7633a54ffd0e017cd73914d65ebc690ec70e97c2 (patch) | |
tree | b51ef7ee15ecc8d738639348a2b732c776b104eb | |
parent | 60cf097ffdac13fffc1bc9cba2d986b28049daf2 (diff) | |
download | ofono-7633a54ffd0e017cd73914d65ebc690ec70e97c2.tar.bz2 |
Add g_at_server_register and unregister callback
-rw-r--r-- | gatchat/gatserver.c | 48 | ||||
-rw-r--r-- | gatchat/gatserver.h | 6 |
2 files changed, 54 insertions, 0 deletions
diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c index 3cf6200f..4ba2e436 100644 --- a/gatchat/gatserver.c +++ b/gatchat/gatserver.c @@ -898,3 +898,51 @@ gboolean g_at_server_set_debug(GAtServer *server, GAtDebugFunc func, return TRUE; } + +gboolean g_at_server_register(GAtServer *server, char *prefix, + GAtServerNotifyFunc notify, + gpointer user_data, + GDestroyNotify destroy_notify) +{ + struct at_command *node; + + if (server == NULL || server->command_list == NULL) + return FALSE; + + if (notify == NULL) + return FALSE; + + if (prefix == NULL || strlen(prefix) == 0) + return FALSE; + + node = g_try_new0(struct at_command, 1); + if (!node) + return FALSE; + + node->notify = notify; + node->user_data = user_data; + node->destroy_notify = destroy_notify; + + g_hash_table_replace(server->command_list, g_strdup(prefix), node); + + return TRUE; +} + +gboolean g_at_server_unregister(GAtServer *server, const char *prefix) +{ + struct at_command *node; + + if (server == NULL || server->command_list == NULL) + return FALSE; + + if (prefix == NULL || strlen(prefix) == 0) + return FALSE; + + node = g_hash_table_lookup(server->command_list, prefix); + if (!node) + return FALSE; + + g_hash_table_remove(server->command_list, prefix); + + return TRUE; +} diff --git a/gatchat/gatserver.h b/gatchat/gatserver.h index 1c12a0df..5e9eb621 100644 --- a/gatchat/gatserver.h +++ b/gatchat/gatserver.h @@ -81,6 +81,12 @@ gboolean g_at_server_set_debug(GAtServer *server, GAtDebugFunc func, gpointer user); +gboolean g_at_server_register(GAtServer *server, char *prefix, + GAtServerNotifyFunc notify, + gpointer user_data, + GDestroyNotify destroy_notify); +gboolean g_at_server_unregister(GAtServer *server, const char *prefix); + #ifdef __cplusplus } #endif |