Skip to contentSkip to conversation

gatserver: add command finished functions

PATCH In review Frédéric Danis 2 participants 5 messages Aug 4, 2011 – Aug 15, 2011

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 gatserver: add command finished functions

---
 gatchat/gatserver.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 gatchat/gatserver.h |    7 +++++++
 2 files changed, 51 insertions(+), 0 deletions(-)
gatchat/gatserver.c +44 -0
index ab785f7..8e92071 100644
@@ -115,6 +115,9 @@ struct _GAtServer {
 	gpointer user_disconnect_data;		/* User disconnect data */
 	GAtDebugFunc debugf;			/* Debugging output function */
 	gpointer debug_data;			/* Data to pass to debug func */
+	GAtServerFinishFunc finishf;		/* Command finish function */
+	gpointer finish_data;			/* Finish func data */
+	guint finish_source;
 	GHashTable *command_list;		/* List of AT commands */
 	GQueue *write_queue;			/* Write buffer queue */
 	guint max_read_attempts;		/* Max reads per select */
@@ -1177,12 +1180,27 @@ static void server_wakeup_writer(GAtServer *server)
 	g_at_io_set_write_handler(server->io, can_write_data, server);
 }
 
+static gboolean notify_finish(void *user_data)
+{
+	GAtServer *server = user_data;
+
+	server->finishf(server, server->finish_data);
+	server->finish_source = 0;
+
+	return FALSE;
+}
+
 static void server_resume(GAtServer *server)
 {
 	if (server->suspended == FALSE)
 		return;
 
 	server->suspended = FALSE;
+
+	if (server->finishf)
+		server->finish_source = g_timeout_add_seconds(0, notify_finish,
+								server);
+
 	g_at_io_set_read_handler(server->io, new_bytes, server);
 }
 
@@ -1336,6 +1354,11 @@ void g_at_server_unref(GAtServer *server)
 	if (server == NULL)
 		return;
 
+	if (server->finish_source) {
+		g_source_remove(server->finish_source);
+		server->finish_source = 0;
+	}
+
 	is_zero = g_atomic_int_dec_and_test(&server->ref_count);
 
 	if (is_zero == FALSE)
@@ -1455,3 +1478,24 @@ gboolean g_at_server_unregister(GAtServer *server, const char *prefix)
 
 	return TRUE;
 }
+
+gboolean g_at_server_set_finish_callback(GAtServer *server,
+					GAtServerFinishFunc finish,
+					gpointer user_data)
+{
+	if (server == NULL)
+		return FALSE;
+
+	server->finishf = finish;
+	server->finish_data = user_data;
+
+	return TRUE;
+}
+
+gboolean g_at_server_command_pending(GAtServer *server)
+{
+	if (server == NULL)
+		return FALSE;
+
+	return server->suspended;
+}
gatchat/gatserver.h +7 -0
index bb0ae84..599c992 100644
@@ -69,6 +69,8 @@ typedef void (*GAtServerNotifyFunc)(GAtServer *server,
 					GAtServerRequestType type,
 					GAtResult *result, gpointer user_data);
 
+typedef void (*GAtServerFinishFunc)(GAtServer *server, gpointer user_data);
+
 GAtServer *g_at_server_new(GIOChannel *io);
 GIOChannel *g_at_server_get_channel(GAtServer *server);
 GAtIO *g_at_server_get_io(GAtServer *server);
@@ -94,6 +96,11 @@ gboolean g_at_server_register(GAtServer *server, const char *prefix,
 					GDestroyNotify destroy_notify);
 gboolean g_at_server_unregister(GAtServer *server, const char *prefix);
 
+gboolean g_at_server_set_finish_callback(GAtServer *server,
+					GAtServerFinishFunc finish,
+					gpointer user_data);
+gboolean g_at_server_command_pending(GAtServer *server);
+
 /* Send a final result code. E.g. G_AT_SERVER_RESULT_NO_DIALTONE */
 void g_at_server_send_final(GAtServer *server, GAtServerResult result);
 
Signature · 1 line
1.7.1
#1 lore raw

PATCH v2 2/2 emulator: fix indicator notification

---
 src/emulator.c  |   33 +++++++++++++++++++++++++++++++--
 src/voicecall.c |   11 -----------
 2 files changed, 31 insertions(+), 13 deletions(-)
src/emulator.c +31 -2
index deb4780..06ec06c 100644
@@ -59,6 +59,7 @@ struct indicator {
 	int value;
 	int min;
 	int max;
+	gboolean deferred;
 };
 
 static void emulator_debug(const char *str, void *data)
@@ -345,6 +346,29 @@ static struct ofono_call *find_call_with_status(struct ofono_emulator *em,
 	return __ofono_voicecall_find_call_with_status(vc, status);
 }
 
+static void notify_deferred_indicators(GAtServer *server, void *user_data)
+{
+	struct ofono_emulator *em = user_data;
+	int i;
+	char buf[20];
+	GSList *l;
+	struct indicator *ind;
+
+	for (i = 1, l = em->indicators; l; l = l->next, i++) {
+		ind = l->data;
+
+		if (!ind->deferred)
+			continue;
+
+		if (em->events_mode == 3 && em->events_ind && em->slc) {
+			sprintf(buf, "+CIEV: %d,%d", i, ind->value);
+			g_at_server_send_unsolicited(em->server, buf);
+		}
+
+		ind->deferred = FALSE;
+	}
+}
+
 static gboolean notify_ccwa(void *user_data)
 {
 	struct ofono_emulator *em = user_data;
@@ -832,6 +856,8 @@ void ofono_emulator_register(struct ofono_emulator *em, int fd)
 	g_at_server_set_debug(em->server, emulator_debug, "Server");
 	g_at_server_set_disconnect_function(em->server,
 						emulator_disconnect, em);
+	g_at_server_set_finish_callback(em->server, notify_deferred_indicators,
+						em);
 
 	if (em->type == OFONO_EMULATOR_TYPE_HFP) {
 		emulator_add_indicator(em, OFONO_EMULATOR_IND_SERVICE, 0, 1, 0);
@@ -1124,8 +1150,11 @@ void ofono_emulator_set_indicator(struct ofono_emulator *em,
 		notify_ccwa(em);
 
 	if (em->events_mode == 3 && em->events_ind && em->slc) {
-		sprintf(buf, "+CIEV: %d,%d", i, ind->value);
-		g_at_server_send_unsolicited(em->server, buf);
+		if (!g_at_server_command_pending(em->server)) {
+			sprintf(buf, "+CIEV: %d,%d", i, ind->value);
+			g_at_server_send_unsolicited(em->server, buf);
+		} else
+			ind->deferred = TRUE;
 	}
 
 	/*
src/voicecall.c +0 -11
index 23976af..168ce96 100644
@@ -700,9 +700,6 @@ static void emulator_call_status_cb(struct ofono_atom *atom, void *data)
 	struct ofono_emulator *em = __ofono_atom_get_data(atom);
 	struct emulator_status *s = data;
 
-	if (em == s->vc->pending_em)
-		return;
-
 	ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALL, s->status);
 }
 
@@ -711,9 +708,6 @@ static void emulator_callsetup_status_cb(struct ofono_atom *atom, void *data)
 	struct ofono_emulator *em = __ofono_atom_get_data(atom);
 	struct emulator_status *s = data;
 
-	if (em == s->vc->pending_em)
-		return;
-
 	ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALLSETUP,
 					s->status);
 }
@@ -723,9 +717,6 @@ static void emulator_callheld_status_cb(struct ofono_atom *atom, void *data)
 	struct ofono_emulator *em = __ofono_atom_get_data(atom);
 	struct emulator_status *s = data;
 
-	if (em == s->vc->pending_em)
-		return;
-
 	ofono_emulator_set_indicator(em, OFONO_EMULATOR_IND_CALLHELD,
 					s->status);
 }
@@ -3210,8 +3201,6 @@ static void emulator_dial_callback(const struct ofono_error *error, void *data)
 
 	vc->pending_em = NULL;
 
-	notify_emulator_call_status(vc);
-
 	if (need_to_emit)
 		voicecalls_emit_call_added(vc, v);
 }
Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCH v2 2/2] emulator: fix indicator notification

Hi Frédéric,

Quoted 5 lines · Frédéric Danis
---
 src/emulator.c  |   33 +++++++++++++++++++++++++++++++--
 src/voicecall.c |   11 -----------
 2 files changed, 31 insertions(+), 13 deletions(-)

Patch has been applied, thanks.

Regards,
-Denis

#3 lore raw
In reply to Frédéric Danis

Hi Frédéric,

Quoted 5 lines · Frédéric Danis
---
 gatchat/gatserver.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 gatchat/gatserver.h |    7 +++++++
 2 files changed, 51 insertions(+), 0 deletions(-)

I haven't forgotten about this patch, but I found a nasty corner case in GAtServer that breaks the current implementation. I'm still looking for a nice solution.

Quoted 32 lines
gatchat/gatserver.c +13 -0
index ab785f7..8e92071 100644
@@ -115,6 +115,9 @@ struct _GAtServer {
 	gpointer user_disconnect_data;		/* User disconnect data */
 	GAtDebugFunc debugf;			/* Debugging output function */
 	gpointer debug_data;			/* Data to pass to debug func */
+	GAtServerFinishFunc finishf;		/* Command finish function */
+	gpointer finish_data;			/* Finish func data */
+	guint finish_source;
 	GHashTable *command_list;		/* List of AT commands */
 	GQueue *write_queue;			/* Write buffer queue */
 	guint max_read_attempts;		/* Max reads per select */
@@ -1177,12 +1180,27 @@ static void server_wakeup_writer(GAtServer *server)
 	g_at_io_set_write_handler(server->io, can_write_data, server);
 }
 
+static gboolean notify_finish(void *user_data)
+{
+	GAtServer *server = user_data;
+
+	server->finishf(server, server->finish_data);
+	server->finish_source = 0;
+
+	return FALSE;
+}
+
 static void server_resume(GAtServer *server)
 {
 	if (server->suspended == FALSE)
 		return;

gatchat/gatserver.c static void server_wakeup_writer(GAtServer *server) · line 1206

Quoted 10 lines
gatchat/gatserver.c +5 -0
 
 	server->suspended = FALSE;
+
+	if (server->finishf)
+		server->finish_source = g_timeout_add_seconds(0, notify_finish,
+								server);
+
 	g_at_io_set_read_handler(server->io, new_bytes, server);
 }
 

<snip>

Can you brainstorm some ideas of a way not to use a g_timeout_add and do the finish notify synchronously? I suspect there is a nice(r) solution.

Regards,
-Denis

#4 lore raw
In reply to Frédéric Danis

Hi Frédéric,

Quoted 5 lines · Frédéric Danis
---
 gatchat/gatserver.c |   44 ++++++++++++++++++++++++++++++++++++++++++++
 gatchat/gatserver.h |    7 +++++++
 2 files changed, 51 insertions(+), 0 deletions(-)

I pushed my own version of this patch. I have performed basic testing here on my end and it seems to be working out quite nicely. However, I have not tested the HFP emulator proper, so could you please double check my logic and make sure that I haven't done anything silly?

Thanks,
-Denis