All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/4] gatchat: Emit notification when command is sent to modem.
@ 2010-04-29 11:32 Andrzej Zaborowski
  2010-04-30  3:00 ` Denis Kenzior
  0 siblings, 1 reply; 8+ messages in thread
From: Andrzej Zaborowski @ 2010-04-29 11:32 UTC (permalink / raw)
  To: ofono

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

Function g_at_chat_send_with_callback takes an additional parameter
that is a function to call when command is sent to hardware.
---
 gatchat/gatchat.c |   35 +++++++++++++++++++++++++++--------
 gatchat/gatchat.h |   17 +++++++++++++++++
 2 files changed, 44 insertions(+), 8 deletions(-)

diff --git a/gatchat/gatchat.c b/gatchat/gatchat.c
index 4552767..000b624 100644
--- a/gatchat/gatchat.c
+++ b/gatchat/gatchat.c
@@ -49,6 +49,7 @@ struct at_command {
 	guint id;
 	GAtResultFunc callback;
 	GAtNotifyFunc listing;
+	GAtSubmitNotifyFunc submit_callback;
 	gpointer user_data;
 	GDestroyNotify notify;
 };
@@ -148,6 +149,7 @@ static struct at_command *at_command_create(const char *cmd,
 						const char **prefix_list,
 						gboolean expect_pdu,
 						GAtNotifyFunc listing,
+						GAtSubmitNotifyFunc sent,
 						GAtResultFunc func,
 						gpointer user_data,
 						GDestroyNotify notify,
@@ -203,6 +205,7 @@ static struct at_command *at_command_create(const char *cmd,
 	c->prefixes = prefixes;
 	c->callback = func;
 	c->listing = listing;
+	c->submit_callback = sent;
 	c->user_data = user_data;
 	c->notify = notify;
 
@@ -700,7 +703,7 @@ static gboolean wakeup_no_response(gpointer user_data)
 
 	g_at_chat_finish_command(chat, FALSE, NULL);
 	cmd = at_command_create(chat->wakeup, none_prefix, FALSE,
-				NULL, wakeup_cb, chat, NULL, TRUE);
+				NULL, NULL, wakeup_cb, chat, NULL, TRUE);
 
 	if (!cmd) {
 		chat->timeout_source = 0;
@@ -752,7 +755,8 @@ static gboolean can_write_data(gpointer data)
 
 	if (chat->cmd_bytes_written == 0 && wakeup_first == TRUE) {
 		cmd = at_command_create(chat->wakeup, none_prefix, FALSE,
-					NULL, wakeup_cb, chat, NULL, TRUE);
+					NULL, NULL, wakeup_cb, chat, NULL,
+					TRUE);
 
 		if (!cmd)
 			return FALSE;
@@ -789,6 +793,9 @@ static gboolean can_write_data(gpointer data)
 	if (bytes_written < towrite)
 		return TRUE;
 
+	if (cmd->submit_callback)
+		cmd->submit_callback(cmd->id, cmd->user_data);
+
 	/* Full command submitted, update timer */
 	if (chat->wakeup_timer)
 		g_timer_start(chat->wakeup_timer);
@@ -967,7 +974,8 @@ gboolean g_at_chat_set_debug(GAtChat *chat,
 static guint send_common(GAtChat *chat, const char *cmd,
 			const char **prefix_list,
 			gboolean expect_pdu,
-			GAtNotifyFunc listing, GAtResultFunc func,
+			GAtNotifyFunc listing, GAtSubmitNotifyFunc sent,
+			GAtResultFunc func,
 			gpointer user_data, GDestroyNotify notify)
 {
 	struct at_command *c;
@@ -975,8 +983,8 @@ static guint send_common(GAtChat *chat, const char *cmd,
 	if (chat == NULL || chat->command_queue == NULL)
 		return 0;
 
-	c = at_command_create(cmd, prefix_list, expect_pdu, listing, func,
-				user_data, notify, FALSE);
+	c = at_command_create(cmd, prefix_list, expect_pdu, listing,
+				sent, func, user_data, notify, FALSE);
 
 	if (!c)
 		return 0;
@@ -995,7 +1003,7 @@ guint g_at_chat_send(GAtChat *chat, const char *cmd,
 			const char **prefix_list, GAtResultFunc func,
 			gpointer user_data, GDestroyNotify notify)
 {
-	return send_common(chat, cmd, prefix_list, FALSE, NULL, func,
+	return send_common(chat, cmd, prefix_list, FALSE, NULL, NULL, func,
 				user_data, notify);
 }
 
@@ -1007,7 +1015,7 @@ guint g_at_chat_send_listing(GAtChat *chat, const char *cmd,
 	if (listing == NULL)
 		return 0;
 
-	return send_common(chat, cmd, prefix_list, FALSE, listing, func,
+	return send_common(chat, cmd, prefix_list, FALSE, listing, NULL, func,
 				user_data, notify);
 }
 
@@ -1019,7 +1027,18 @@ guint g_at_chat_send_pdu_listing(GAtChat *chat, const char *cmd,
 	if (listing == NULL)
 		return 0;
 
-	return send_common(chat, cmd, prefix_list, TRUE, listing, func,
+	return send_common(chat, cmd, prefix_list, TRUE, listing, NULL, func,
+				user_data, notify);
+}
+
+guint g_at_chat_send_with_callback(GAtChat *chat, const char *cmd,
+					const char **valid_resp,
+					GAtSubmitNotifyFunc sent,
+					GAtResultFunc func,
+					gpointer user_data,
+					GDestroyNotify notify)
+{
+	return send_common(chat, cmd, valid_resp, TRUE, NULL, sent, func,
 				user_data, notify);
 }
 
diff --git a/gatchat/gatchat.h b/gatchat/gatchat.h
index ea6626e..80d87be 100644
--- a/gatchat/gatchat.h
+++ b/gatchat/gatchat.h
@@ -37,6 +37,7 @@ typedef struct _GAtChat GAtChat;
 typedef void (*GAtResultFunc)(gboolean success, GAtResult *result,
 				gpointer user_data);
 typedef void (*GAtNotifyFunc)(GAtResult *result, gpointer user_data);
+typedef void (*GAtSubmitNotifyFunc)(guint id, gpointer user_data);
 
 GAtChat *g_at_chat_new(GIOChannel *channel, GAtSyntax *syntax);
 GAtChat *g_at_chat_new_blocking(GIOChannel *channel, GAtSyntax *syntax);
@@ -117,6 +118,22 @@ guint g_at_chat_send_pdu_listing(GAtChat *chat, const char *cmd,
 				GAtNotifyFunc listing, GAtResultFunc func,
 				gpointer user_data, GDestroyNotify notify);
 
+/*!
+ * Same as g_at_chat_send but with an ability to return a notification the
+ * moment the command finally leaves the queue and is submitted to lower
+ * layer.
+ *
+ * This is useful for cases where the modem's response time needs to be
+ * measured, assuming that the lower layers processing time is shorter
+ * than the minimum accuracy needed.
+ */
+guint g_at_chat_send_with_callback(GAtChat *chat, const char *cmd,
+					const char **valid_resp,
+					GAtSubmitNotifyFunc sent,
+					GAtResultFunc func,
+					gpointer user_data,
+					GDestroyNotify notify);
+
 gboolean g_at_chat_cancel(GAtChat *chat, guint id);
 gboolean g_at_chat_cancel_all(GAtChat *chat);
 
-- 
1.6.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2010-05-04 13:11 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-04-29 11:32 [PATCH 3/4] gatchat: Emit notification when command is sent to modem Andrzej Zaborowski
2010-04-30  3:00 ` Denis Kenzior
2010-04-30  5:48   ` Marcel Holtmann
2010-04-30 13:31     ` Denis Kenzior
2010-04-30 13:41       ` Marcel Holtmann
2010-05-03 18:22     ` andrzej zaborowski
2010-05-04  9:07       ` Marcel Holtmann
2010-05-04 13:11         ` Andrzej Zaborowski

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.