All of lore.kernel.org
 help / color / mirror / Atom feed
From: Zhenhua Zhang <zhenhua.zhang@intel.com>
To: ofono@ofono.org
Subject: [PATCH 02/11] Add framework of server parser
Date: Wed, 17 Mar 2010 22:30:32 +0800	[thread overview]
Message-ID: <1268836241-4834-2-git-send-email-zhenhua.zhang@intel.com> (raw)
In-Reply-To: <1268836241-4834-1-git-send-email-zhenhua.zhang@intel.com>

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

a. The parser fetch and parse one command per loop. The prefix is
the command prefix without parameter. For example, the prefix of
"AT+CLIP=1" is "+CLIP".

b. Search registered notification node in command_list. Invoke the
callback if found.

c. Termiate the execution if the result is an error. Otherwise,
parse next command.
---
 gatchat/gatserver.c |   95 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 95 insertions(+), 0 deletions(-)

diff --git a/gatchat/gatserver.c b/gatchat/gatserver.c
index 46fa423..fb82ad4 100644
--- a/gatchat/gatserver.c
+++ b/gatchat/gatserver.c
@@ -173,8 +173,103 @@ static void g_at_server_send_final(GAtServer *server, GAtServerResult result)
 	send_common(server, buf, MIN(len, sizeof(buf)-1));
 }
 
+static inline gboolean is_extended_command_prefix(const char c)
+{
+	switch (c) {
+	case '+':
+	case '*':
+	case '!':
+	case '%':
+		return TRUE;
+	default:
+		return FALSE;
+	}
+}
+
+static gboolean is_basic_command_prefix(const char *buf)
+{
+	if (g_ascii_isalpha(buf[0]))
+		return TRUE;
+
+	if (buf[0] == '&' && g_ascii_isalpha(buf[1]))
+		return TRUE;
+
+	return FALSE;
+}
+
+static GAtServerResult at_command_notify(GAtServer *server, char *command,
+						char *prefix)
+{
+	GAtServerResult res = G_AT_SERVER_RESULT_ERROR;
+
+	return res;
+}
+
+static char *parse_extended_command(GAtServer *server, const char *buf,
+					char *prefix)
+{
+	return NULL;
+}
+
+static char *parse_basic_command(GAtServer *server, const char *buf,
+					char *prefix)
+{
+	return NULL;
+}
+
+static char *parse_next_command(GAtServer *server, const char *buf,
+					char *prefix)
+{
+	char *command = NULL;
+	char c = *buf;
+
+	/* fetch one command and get its prefix */
+	if (is_extended_command_prefix(c))
+		command = parse_extended_command(server, buf, prefix);
+	else if (is_basic_command_prefix(buf))
+		command = parse_basic_command(server, buf, prefix);
+
+	return command;
+}
+
 static void server_parse_line(GAtServer *server, char *line)
 {
+	GAtServerResult res = G_AT_SERVER_RESULT_ERROR;
+	char *buf = line;
+	char *command = NULL;
+	char prefix[20];
+
+	while (buf) {
+		char c = *buf;
+
+		/* skip semicolon */
+		if (c == ';')
+			c = *(++buf);
+
+		if (c == '\0') {
+			res = G_AT_SERVER_RESULT_OK;
+			break;
+		}
+
+		command = parse_next_command(server, buf, prefix);
+		if (!command) {
+			res = G_AT_SERVER_RESULT_ERROR;
+			break;
+		}
+
+		res = at_command_notify(server, command, prefix);
+		if (res != G_AT_SERVER_RESULT_OK) {
+			g_free(command);
+			break;
+		}
+
+		buf += strlen(command);
+
+		g_free(command);
+	}
+
+	g_at_server_send_final(server, res);
+
 	g_free(line);
 }
 
-- 
1.6.6.1


  reply	other threads:[~2010-03-17 14:30 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-17 14:30 [PATCH 01/11] Rename g_at_server_send_result Zhenhua Zhang
2010-03-17 14:30 ` Zhenhua Zhang [this message]
2010-03-17 14:30   ` [PATCH 03/11] Add basic command parsing Zhenhua Zhang
2010-03-17 14:30     ` [PATCH 04/11] Add extended " Zhenhua Zhang
2010-03-17 14:30       ` [PATCH 05/11] Add server at command data structure Zhenhua Zhang
2010-03-17 14:30         ` [PATCH 06/11] Add notify at command callback Zhenhua Zhang
2010-03-17 14:30           ` [PATCH 07/11] Add g_at_server_register and unregister callback Zhenhua Zhang
2010-03-17 14:30             ` [PATCH 08/11] Add G_AT_SERVER_RESULT_EXT_ERROR Zhenhua Zhang
2010-03-17 14:30               ` [PATCH 09/11] Fix do not emit error if extended error has emitted Zhenhua Zhang
2010-03-17 14:30                 ` [PATCH 10/11] Refactor g_at_server_send_final Zhenhua Zhang
2010-03-17 14:30                   ` [PATCH 11/11] Add utilities to send server response Zhenhua Zhang
2010-03-17 18:23           ` [PATCH 06/11] Add notify at command callback Denis Kenzior
2010-03-17 18:02     ` [PATCH 03/11] Add basic command parsing Denis Kenzior
2010-03-17 17:55   ` [PATCH 02/11] Add framework of server parser Denis Kenzior
2010-03-17 14:38 ` [PATCH 01/11] Rename g_at_server_send_result Zhenhua Zhang
2010-03-17 18:24   ` Denis Kenzior

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=1268836241-4834-2-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.