From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH 3/3] Fix telephony maemo6 driver deinitialization
Date: Thu, 25 Nov 2010 17:22:31 +0200 [thread overview]
Message-ID: <1290698551-8706-3-git-send-email-luiz.dentz@gmail.com> (raw)
In-Reply-To: <1290698551-8706-1-git-send-email-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.dentz-von@nokia.com>
Remove all match rules and unregister its interface when telephony_exit
is called.
---
audio/telephony-maemo6.c | 198 +++++++++++++++++++++++++++-------------------
1 files changed, 116 insertions(+), 82 deletions(-)
diff --git a/audio/telephony-maemo6.c b/audio/telephony-maemo6.c
index 72c8e36..542fab9 100644
--- a/audio/telephony-maemo6.c
+++ b/audio/telephony-maemo6.c
@@ -149,6 +149,7 @@ static int get_property(const char *iface, const char *prop);
static DBusConnection *connection = NULL;
static GSList *calls = NULL;
+static GSList *watches = NULL;
/* Reference count for determining the call indicator status */
static GSList *active_calls = NULL;
@@ -1616,59 +1617,6 @@ done:
dbus_message_unref(reply);
}
-static void hal_find_device_reply(DBusPendingCall *call, void *user_data)
-{
- DBusError err;
- DBusMessage *reply;
- DBusMessageIter iter, sub;
- const char *path;
- char match_string[256];
- int type;
-
- reply = dbus_pending_call_steal_reply(call);
-
- dbus_error_init(&err);
- if (dbus_set_error_from_message(&err, reply)) {
- error("hald replied with an error: %s, %s",
- err.name, err.message);
- dbus_error_free(&err);
- goto done;
- }
-
- dbus_message_iter_init(reply, &iter);
-
- if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
- error("Unexpected signature in FindDeviceByCapability return");
- goto done;
- }
-
- dbus_message_iter_recurse(&iter, &sub);
-
- type = dbus_message_iter_get_arg_type(&sub);
-
- if (type != DBUS_TYPE_OBJECT_PATH && type != DBUS_TYPE_STRING) {
- error("No hal device with battery capability found");
- goto done;
- }
-
- dbus_message_iter_get_basic(&sub, &path);
-
- DBG("telephony-maemo6: found battery device at %s", path);
-
- snprintf(match_string, sizeof(match_string),
- "type='signal',"
- "path='%s',"
- "interface='org.freedesktop.Hal.Device',"
- "member='PropertyModified'", path);
- dbus_bus_add_match(connection, match_string, NULL);
-
- hal_get_integer(path, "battery.charge_level.last_full", &battchg_last);
- hal_get_integer(path, "battery.charge_level.current", &battchg_cur);
- hal_get_integer(path, "battery.charge_level.design", &battchg_design);
-
-done:
- dbus_message_unref(reply);
-}
static void phonebook_read_reply(DBusPendingCall *call, void *user_data)
{
@@ -1897,14 +1845,11 @@ static void modem_state_reply(DBusPendingCall *call, void *user_data)
dbus_message_unref(reply);
}
-static DBusHandlerResult signal_filter(DBusConnection *conn,
- DBusMessage *msg, void *data)
+static gboolean signal_filter(DBusConnection *conn, DBusMessage *msg,
+ void *data)
{
const char *path = dbus_message_get_path(msg);
- if (dbus_message_get_type(msg) != DBUS_MESSAGE_TYPE_SIGNAL)
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
-
if (dbus_message_is_signal(msg, CSD_CALL_INTERFACE, "Coming"))
handle_incoming_call(msg);
else if (dbus_message_is_signal(msg, CSD_CALL_INTERFACE, "Created"))
@@ -1934,7 +1879,61 @@ static DBusHandlerResult signal_filter(DBusConnection *conn,
"modem_state_changed_ind"))
handle_modem_state(msg);
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ return TRUE;
+}
+
+static void hal_find_device_reply(DBusPendingCall *call, void *user_data)
+{
+ DBusError err;
+ DBusMessage *reply;
+ DBusMessageIter iter, sub;
+ const char *path;
+ int type;
+ guint watch;
+
+ reply = dbus_pending_call_steal_reply(call);
+
+ dbus_error_init(&err);
+ if (dbus_set_error_from_message(&err, reply)) {
+ error("hald replied with an error: %s, %s",
+ err.name, err.message);
+ dbus_error_free(&err);
+ goto done;
+ }
+
+ dbus_message_iter_init(reply, &iter);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_ARRAY) {
+ error("Unexpected signature in FindDeviceByCapability return");
+ goto done;
+ }
+
+ dbus_message_iter_recurse(&iter, &sub);
+
+ type = dbus_message_iter_get_arg_type(&sub);
+
+ if (type != DBUS_TYPE_OBJECT_PATH && type != DBUS_TYPE_STRING) {
+ error("No hal device with battery capability found");
+ goto done;
+ }
+
+ dbus_message_iter_get_basic(&sub, &path);
+
+ DBG("telephony-maemo6: found battery device at %s", path);
+
+ watch = g_dbus_add_signal_watch(connection, NULL, path,
+ "org.freedesktop.Hal.Device",
+ "PropertyModified", signal_filter,
+ NULL, NULL);
+
+ watches = g_slist_prepend(watches, GINT_TO_POINTER(watch));
+
+ hal_get_integer(path, "battery.charge_level.last_full", &battchg_last);
+ hal_get_integer(path, "battery.charge_level.current", &battchg_cur);
+ hal_get_integer(path, "battery.charge_level.design", &battchg_design);
+
+done:
+ dbus_message_unref(reply);
}
int telephony_init(void)
@@ -1947,31 +1946,54 @@ int telephony_init(void)
AG_FEATURE_ENHANCED_CALL_CONTROL |
AG_FEATURE_EXTENDED_ERROR_RESULT_CODES |
AG_FEATURE_THREE_WAY_CALLING;
+ guint watch;
+
+ DBG("");
connection = dbus_bus_get(DBUS_BUS_SYSTEM, NULL);
- if (!dbus_connection_add_filter(connection, signal_filter,
- NULL, NULL))
- error("Can't add signal filter");
-
- dbus_bus_add_match(connection,
- "type=signal,interface=" CSD_CALL_INTERFACE, NULL);
- dbus_bus_add_match(connection,
- "type=signal,interface=" CSD_CALL_INSTANCE, NULL);
- dbus_bus_add_match(connection,
- "type=signal,interface=" CSD_CALL_CONFERENCE, NULL);
- dbus_bus_add_match(connection,
- "type=signal,interface=" CSD_CSNET_REGISTRATION,
- NULL);
- dbus_bus_add_match(connection,
- "type=signal,interface=" CSD_CSNET_OPERATOR,
- NULL);
- dbus_bus_add_match(connection,
- "type=signal,interface=" CSD_CSNET_SIGNAL,
- NULL);
- dbus_bus_add_match(connection,
- "type=signal,interface=" SSC_DBUS_IFACE
- ",member=modem_state_changed_ind", NULL);
+ watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ CSD_CALL_INTERFACE, NULL,
+ signal_filter, NULL, NULL);
+
+ watches = g_slist_prepend(watches, GUINT_TO_POINTER(watch));
+
+ watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ CSD_CALL_INSTANCE, NULL,
+ signal_filter, NULL, NULL);
+
+ watches = g_slist_prepend(watches, GUINT_TO_POINTER(watch));
+
+ watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ CSD_CALL_CONFERENCE, NULL,
+ signal_filter, NULL, NULL);
+
+ watches = g_slist_prepend(watches, GUINT_TO_POINTER(watch));
+
+ watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ CSD_CSNET_REGISTRATION, NULL,
+ signal_filter, NULL, NULL);
+
+ watches = g_slist_prepend(watches, GUINT_TO_POINTER(watch));
+
+ watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ CSD_CSNET_OPERATOR, NULL,
+ signal_filter, NULL, NULL);
+
+ watches = g_slist_prepend(watches, GUINT_TO_POINTER(watch));
+
+ watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ CSD_CSNET_SIGNAL, NULL,
+ signal_filter, NULL, NULL);
+
+ watches = g_slist_prepend(watches, GUINT_TO_POINTER(watch));
+
+ watch = g_dbus_add_signal_watch(connection, NULL, NULL,
+ SSC_DBUS_IFACE,
+ "modem_state_changed_ind",
+ signal_filter, NULL, NULL);
+
+ watches = g_slist_prepend(watches, GUINT_TO_POINTER(watch));
if (send_method_call(SSC_DBUS_NAME, SSC_DBUS_PATH, SSC_DBUS_IFACE,
"get_modem_state", modem_state_reply,
@@ -2005,8 +2027,15 @@ int telephony_init(void)
return 0;
}
+static void remove_watch(gpointer data)
+{
+ g_dbus_remove_watch(connection, GPOINTER_TO_UINT(data));
+}
+
void telephony_exit(void)
{
+ DBG("");
+
g_free(net.operator_name);
net.operator_name = NULL;
@@ -2017,7 +2046,12 @@ void telephony_exit(void)
g_slist_free(calls);
calls = NULL;
- dbus_connection_remove_filter(connection, signal_filter, NULL);
+ g_slist_foreach(watches, (GFunc) remove_watch, NULL);
+ g_slist_free(watches);
+ watches = NULL;
+
+ g_dbus_unregister_interface(connection, TELEPHONY_MAEMO_PATH,
+ TELEPHONY_MAEMO_INTERFACE);
dbus_connection_unref(connection);
connection = NULL;
--
1.7.1
next prev parent reply other threads:[~2010-11-25 15:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-11-25 15:22 [PATCH 1/3] Fix not deinitializing telephony driver when there is no adapter powered Luiz Augusto von Dentz
2010-11-25 15:22 ` [PATCH 2/3] Fix telephony dummy driver Luiz Augusto von Dentz
2010-11-25 15:22 ` Luiz Augusto von Dentz [this message]
2010-11-25 20:01 ` [PATCH 1/3] Fix not deinitializing telephony driver when there is no adapter powered Johan Hedberg
-- strict thread matches above, loose matches on Subject: below --
2010-11-23 11:33 Luiz Augusto von Dentz
2010-11-23 11:33 ` [PATCH 3/3] Fix telephony maemo6 driver deinitialization Luiz Augusto von Dentz
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=1290698551-8706-3-git-send-email-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.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 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).