linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/2 v2] Add handling of pending D-Bus calls in maemo6
@ 2011-03-25 16:44 Dmitriy Paliy
  2011-03-25 16:44 ` [PATCH 1/2] " Dmitriy Paliy
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Dmitriy Paliy @ 2011-03-25 16:44 UTC (permalink / raw)
  To: linux-bluetooth

Hi,

Canceling of requests to csd is done in more correct way in this proposal.

BR,
Dmitriy


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

* [PATCH 1/2] Add handling of pending D-Bus calls in maemo6
  2011-03-25 16:44 [PATCH 0/2 v2] Add handling of pending D-Bus calls in maemo6 Dmitriy Paliy
@ 2011-03-25 16:44 ` Dmitriy Paliy
  2011-03-25 16:44 ` [PATCH 2/2] Add ERROR response on AT+BLDN command for maemo6 Dmitriy Paliy
  2011-03-27 19:50 ` [PATCH 0/2 v2] Add handling of pending D-Bus calls in maemo6 Johan Hedberg
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitriy Paliy @ 2011-03-25 16:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Dmitriy Paliy

Handling of pending D-Bus calls to csd back-end is added maemo6
telephony driver.
---
 audio/telephony-maemo6.c |   65 +++++++++++++++++++++++++++++++++++++++------
 1 files changed, 56 insertions(+), 9 deletions(-)

diff --git a/audio/telephony-maemo6.c b/audio/telephony-maemo6.c
index 55f6a30..9650cba 100644
--- a/audio/telephony-maemo6.c
+++ b/audio/telephony-maemo6.c
@@ -134,6 +134,11 @@ static struct {
 	.signal_bars = 0,
 };
 
+struct pending_req {
+	DBusPendingCall *call;
+	void *user_data;
+};
+
 static int get_property(const char *iface, const char *prop);
 
 static DBusConnection *connection = NULL;
@@ -443,10 +448,31 @@ void telephony_device_connected(void *telephony_device)
 	}
 }
 
+static void pending_req_finalize(struct pending_req *req)
+{
+	if (!dbus_pending_call_get_completed(req->call))
+		dbus_pending_call_cancel(req->call);
+
+	dbus_pending_call_unref(req->call);
+	g_free(req);
+}
+
+static void remove_pending_by_data(gpointer data, gpointer user_data)
+{
+	struct pending_req *req = data;
+
+	if (req->user_data == user_data) {
+		pending = g_slist_remove(pending, req);
+		pending_req_finalize(req);
+	}
+}
+
 void telephony_device_disconnected(void *telephony_device)
 {
 	DBG("telephony-maemo6: device %p disconnected", telephony_device);
 	events_enabled = FALSE;
+
+	g_slist_foreach(pending, remove_pending_by_data, telephony_device);
 }
 
 void telephony_event_reporting_req(void *telephony_device, int ind)
@@ -529,6 +555,7 @@ static int send_method_call(const char *dest, const char *path,
 	DBusMessage *msg;
 	DBusPendingCall *call;
 	va_list args;
+	struct pending_req *req;
 
 	msg = dbus_message_new_method_call(dest, path, interface, method);
 	if (!msg) {
@@ -558,12 +585,39 @@ static int send_method_call(const char *dest, const char *path,
 	}
 
 	dbus_pending_call_set_notify(call, cb, user_data, NULL);
-	pending = g_slist_prepend(pending, call);
+
+	req = g_new0(struct pending_req, 1);
+	req->call = call;
+	req->user_data = user_data;
+
+	pending = g_slist_prepend(pending, req);
 	dbus_message_unref(msg);
 
 	return 0;
 }
 
+static struct pending_req *find_request(const DBusPendingCall *call)
+{
+	GSList *l;
+
+	for (l = pending; l; l = l->next) {
+		struct pending_req *req = l->data;
+
+		if (req->call == call)
+			return req;
+	}
+
+	return NULL;
+}
+
+static void remove_pending(DBusPendingCall *call)
+{
+	struct pending_req *req = find_request(call);
+
+	pending = g_slist_remove(pending, req);
+	pending_req_finalize(req);
+}
+
 void telephony_last_dialed_number_req(void *telephony_device)
 {
 	int ret;
@@ -1295,12 +1349,6 @@ static gboolean iter_get_basic_args(DBusMessageIter *iter,
 	return type == DBUS_TYPE_INVALID ? TRUE : FALSE;
 }
 
-static void remove_pending(DBusPendingCall *call)
-{
-	pending = g_slist_remove(pending, call);
-	dbus_pending_call_unref(call);
-}
-
 static void hal_battery_level_reply(DBusPendingCall *call, void *user_data)
 {
 	DBusError err;
@@ -1910,8 +1958,7 @@ void telephony_exit(void)
 	g_slist_free(calls);
 	calls = NULL;
 
-	g_slist_foreach(pending, (GFunc) dbus_pending_call_cancel, NULL);
-	g_slist_foreach(pending, (GFunc) dbus_pending_call_unref, NULL);
+	g_slist_foreach(pending, (GFunc) pending_req_finalize, NULL);
 	g_slist_free(pending);
 	pending = NULL;
 
-- 
1.7.1


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

* [PATCH 2/2] Add ERROR response on AT+BLDN command for maemo6
  2011-03-25 16:44 [PATCH 0/2 v2] Add handling of pending D-Bus calls in maemo6 Dmitriy Paliy
  2011-03-25 16:44 ` [PATCH 1/2] " Dmitriy Paliy
@ 2011-03-25 16:44 ` Dmitriy Paliy
  2011-03-27 19:50 ` [PATCH 0/2 v2] Add handling of pending D-Bus calls in maemo6 Johan Hedberg
  2 siblings, 0 replies; 4+ messages in thread
From: Dmitriy Paliy @ 2011-03-25 16:44 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Dmitriy Paliy

Response on AT+BLDN command in maemo6 telephony driver is added to be
sent after confirmation from csd back-end. Both ERROR or OK codes are
sent only after asynchronous response on D-Bus call is available.
---
 audio/telephony-maemo6.c |   26 +++++++++++++++++++++++---
 1 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/audio/telephony-maemo6.c b/audio/telephony-maemo6.c
index 9650cba..0cef7dd 100644
--- a/audio/telephony-maemo6.c
+++ b/audio/telephony-maemo6.c
@@ -618,6 +618,28 @@ static void remove_pending(DBusPendingCall *call)
 	pending_req_finalize(req);
 }
 
+static void last_number_call_reply(DBusPendingCall *call, void *user_data)
+{
+	DBusError err;
+	DBusMessage *reply;
+	void *telephony_device = user_data;
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	dbus_error_init(&err);
+	if (dbus_set_error_from_message(&err, reply)) {
+		error("csd replied with an error: %s, %s",
+				err.name, err.message);
+		dbus_error_free(&err);
+		telephony_dial_number_rsp(telephony_device,
+							CME_ERROR_AG_FAILURE);
+	} else
+		telephony_dial_number_rsp(telephony_device, CME_ERROR_NONE);
+
+	dbus_message_unref(reply);
+	remove_pending(call);
+}
+
 void telephony_last_dialed_number_req(void *telephony_device)
 {
 	int ret;
@@ -626,13 +648,11 @@ void telephony_last_dialed_number_req(void *telephony_device)
 
 	ret = send_method_call(CSD_CALL_BUS_NAME, CSD_CALL_PATH,
 				CSD_CALL_INTERFACE, "CreateFromLast",
-				NULL, NULL,
+				last_number_call_reply, telephony_device,
 				DBUS_TYPE_INVALID);
 	if (ret < 0)
 		telephony_dial_number_rsp(telephony_device,
 						CME_ERROR_AG_FAILURE);
-	else
-		telephony_dial_number_rsp(telephony_device, CME_ERROR_NONE);
 }
 
 static const char *memory_dial_lookup(int location)
-- 
1.7.1


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

* Re: [PATCH 0/2 v2] Add handling of pending D-Bus calls in maemo6
  2011-03-25 16:44 [PATCH 0/2 v2] Add handling of pending D-Bus calls in maemo6 Dmitriy Paliy
  2011-03-25 16:44 ` [PATCH 1/2] " Dmitriy Paliy
  2011-03-25 16:44 ` [PATCH 2/2] Add ERROR response on AT+BLDN command for maemo6 Dmitriy Paliy
@ 2011-03-27 19:50 ` Johan Hedberg
  2 siblings, 0 replies; 4+ messages in thread
From: Johan Hedberg @ 2011-03-27 19:50 UTC (permalink / raw)
  To: Dmitriy Paliy; +Cc: linux-bluetooth

Hi Dmitriy,

On Fri, Mar 25, 2011, Dmitriy Paliy wrote:
> Canceling of requests to csd is done in more correct way in this proposal.

Thanks. Both patches have been pushed upstream.

Johan

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

end of thread, other threads:[~2011-03-27 19:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-25 16:44 [PATCH 0/2 v2] Add handling of pending D-Bus calls in maemo6 Dmitriy Paliy
2011-03-25 16:44 ` [PATCH 1/2] " Dmitriy Paliy
2011-03-25 16:44 ` [PATCH 2/2] Add ERROR response on AT+BLDN command for maemo6 Dmitriy Paliy
2011-03-27 19:50 ` [PATCH 0/2 v2] Add handling of pending D-Bus calls in maemo6 Johan Hedberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).