[PATCH 7/7] Add g_at_server_register to register callback

Zhenhua Zhang zhenhua.zhang at intel.com
Wed Mar 3 06:56:52 PST 2010


---
 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);
+	}
+
+	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);
+
+	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);
+
 #ifdef __cplusplus
 }
 #endif
-- 
1.6.6.1



More information about the ofono mailing list