All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhenhua Zhang <zhenhua.zhang@intel.com>
To: ofono@ofono.org
Subject: [PATCH 6/7] Add notify at command callback
Date: Wed, 03 Mar 2010 22:56:51 +0800	[thread overview]
Message-ID: <1267628212-14079-6-git-send-email-zhenhua.zhang@intel.com> (raw)
In-Reply-To: <1267628212-14079-5-git-send-email-zhenhua.zhang@intel.com>

[-- Attachment #1: Type: text/plain, Size: 2325 bytes --]

Search command_list to get notification node.

If the command is an action command, the type may be "action" or
"support".

If the command is a parameter command, the type may be either
"support", "query" or "set".
---
 gatchat/gatserver.c |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c
index 829dc1d..bea51f5 100644
--- a/gatchat/gatserver.c
+++ b/gatchat/gatserver.c
@@ -231,10 +231,63 @@ static gboolean is_extended_character(const char c)
 	}
 }
 
+static GAtServerRequestType get_command_type(char *buf, struct at_command *node)
+{
+	GAtServerRequestType type = G_AT_SERVER_REQUEST_TYPE_NONE;
+	char *prefix = node->prefix;
+	GAtServerCommandType cmd_type = node->type;
+
+	buf += strlen(prefix);
+
+	if (cmd_type == G_AT_SERVER_COMMAND_TYPE_ACTION) {
+		if (buf[0] == '=' && buf[1] == '?')
+			type = G_AT_SERVER_REQUEST_TYPE_SUPPORT;
+		else if (buf[0] == '?')
+			type = G_AT_SERVER_REQUEST_TYPE_NONE;
+		else
+			type = G_AT_SERVER_REQUEST_TYPE_ACTION;
+	} else {
+		if (buf[0] == '=' && buf[1] == '?')
+			type = G_AT_SERVER_REQUEST_TYPE_SUPPORT;
+		else if (buf[0] == '?')
+			type = G_AT_SERVER_REQUEST_TYPE_QUERY;
+		else {
+			/* Two cases:
+			 * A valid basic command followed by digits.
+			 * 	If no digit follows, zero is assumed.
+			 * A valid extended command followed by '='.
+			 */
+			if (is_basic_command_prefix(prefix))
+				type = G_AT_SERVER_REQUEST_TYPE_SET;
+			else if (is_extended_command_prefix(*prefix) &&
+					buf[0] == '=')
+				type = G_AT_SERVER_REQUEST_TYPE_SET;
+		}
+	}
+
+	return type;
+}
+
 static GAtServerResult at_notify_callback(GAtServer *server, char *command,
 					char *prefix)
 {
 	int res = G_AT_SERVER_RESULT_ERROR;
+	struct at_command *node;
+
+	node = g_hash_table_lookup(server->command_list, prefix);
+	if (node && node->notify) {
+		GAtServerRequestType type;
+		GAtResult result;
+
+		type = get_command_type(command, node);
+		if (type == G_AT_SERVER_REQUEST_TYPE_NONE)
+			return res;
+
+		result.lines = g_slist_prepend(NULL, command);
+		result.final_or_pdu = 0;
+
+		res = node->notify(type, &result, node->user_data);
+	}
 
 	return res;
 }
-- 
1.6.6.1


  reply	other threads:[~2010-03-03 14:56 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         ` Zhenhua Zhang [this message]
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
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=1267628212-14079-6-git-send-email-zhenhua.zhang@intel.com \
    --to=zhenhua.zhang@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.