From 65db8f5745ccda4ef8abccfc1e43618838eae032 Mon Sep 17 00:00:00 2001 From: Mike Ruprecht Date: Thu, 1 Nov 2012 00:24:35 -0500 Subject: [PATCH] Update to current ConnMan API ConnMan 0.79 removed the GetState method and StateChanged signal. Use the GetProperties method and PropertyChanged signals as their replacements. Bug: https://bugs.freedesktop.org/show_bug.cgi?id=56600 --- src/connectivity-monitor.c | 57 ++++++++++++++++++++++++++----------- tests/twisted/fakeconnectivity.py | 17 +++++++---- 2 files changed, 52 insertions(+), 22 deletions(-) diff --git a/src/connectivity-monitor.c b/src/connectivity-monitor.c index 5e6e425..7337aa5 100644 --- a/src/connectivity-monitor.c +++ b/src/connectivity-monitor.c @@ -148,7 +148,7 @@ connectivity_monitor_nm_state_change_cb (NMClient *client, #ifdef HAVE_CONNMAN static void -connectivity_monitor_connman_state_changed_cb (DBusGProxy *proxy, +connectivity_monitor_connman_state_changed (DBusGProxy *proxy, const gchar *new_state, McdConnectivityMonitor *connectivity_monitor) { @@ -168,25 +168,47 @@ connectivity_monitor_connman_state_changed_cb (DBusGProxy *proxy, } static void +connectivity_monitor_connman_property_changed_cb (DBusGProxy *proxy, + const gchar *prop_name, + const GValue *new_value, + McdConnectivityMonitor *connectivity_monitor) +{ + if (!tp_strdiff (prop_name, "State")) + connectivity_monitor_connman_state_changed (proxy, + g_value_get_string (new_value), connectivity_monitor); +} + +static void connectivity_monitor_connman_check_state_cb (DBusGProxy *proxy, DBusGProxyCall *call_id, gpointer user_data) { McdConnectivityMonitor *connectivity_monitor = (McdConnectivityMonitor *) user_data; GError *error = NULL; - gchar *state; + GHashTable *props; if (dbus_g_proxy_end_call (proxy, call_id, &error, - G_TYPE_STRING, &state, G_TYPE_INVALID)) + dbus_g_type_get_map ("GHashTable", G_TYPE_STRING, G_TYPE_VALUE), + &props, G_TYPE_INVALID)) { - connectivity_monitor_connman_state_changed_cb (proxy, state, - connectivity_monitor); - g_free (state); + const gchar *state = tp_asv_get_string (props, "State"); + + if (state != NULL) + { + connectivity_monitor_connman_state_changed (proxy, state, + connectivity_monitor); + } + else + { + DEBUG ("Failed to get State: not in GetProperties return"); + } + + g_hash_table_unref (props); } else { - DEBUG ("Failed to call GetState: %s", error->message); - connectivity_monitor_connman_state_changed_cb (proxy, "offline", + DEBUG ("Failed to call GetProperties: %s", error->message); + connectivity_monitor_connman_state_changed (proxy, "offline", connectivity_monitor); } } @@ -198,7 +220,7 @@ connectivity_monitor_connman_check_state (McdConnectivityMonitor *connectivity_m priv = connectivity_monitor->priv; - dbus_g_proxy_begin_call (priv->proxy, "GetState", + dbus_g_proxy_begin_call (priv->proxy, "GetProperties", connectivity_monitor_connman_check_state_cb, connectivity_monitor, NULL, G_TYPE_INVALID); } @@ -280,14 +302,14 @@ mcd_connectivity_monitor_init (McdConnectivityMonitor *connectivity_monitor) "net.connman.Manager"); dbus_g_object_register_marshaller ( - g_cclosure_marshal_VOID__STRING, - G_TYPE_NONE, G_TYPE_STRING, G_TYPE_INVALID); + g_cclosure_marshal_generic, + G_TYPE_NONE, G_TYPE_STRING, G_TYPE_BOXED, G_TYPE_INVALID); - dbus_g_proxy_add_signal (priv->proxy, "StateChanged", - G_TYPE_STRING, G_TYPE_INVALID); + dbus_g_proxy_add_signal (priv->proxy, "PropertyChanged", + G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); - dbus_g_proxy_connect_signal (priv->proxy, "StateChanged", - G_CALLBACK (connectivity_monitor_connman_state_changed_cb), + dbus_g_proxy_connect_signal (priv->proxy, "PropertyChanged", + G_CALLBACK (connectivity_monitor_connman_property_changed_cb), connectivity_monitor, NULL); connectivity_monitor_connman_check_state (connectivity_monitor); @@ -336,8 +358,9 @@ connectivity_monitor_finalize (GObject *object) #ifdef HAVE_CONNMAN if (priv->proxy != NULL) { - dbus_g_proxy_disconnect_signal (priv->proxy, "StateChanged", - G_CALLBACK (connectivity_monitor_connman_state_changed_cb), connectivity_monitor); + dbus_g_proxy_disconnect_signal (priv->proxy, "PropertyChanged", + G_CALLBACK (connectivity_monitor_connman_property_changed_cb), + connectivity_monitor); g_object_unref (priv->proxy); priv->proxy = NULL; diff --git a/tests/twisted/fakeconnectivity.py b/tests/twisted/fakeconnectivity.py index e613aca..c144452 100644 --- a/tests/twisted/fakeconnectivity.py +++ b/tests/twisted/fakeconnectivity.py @@ -43,9 +43,9 @@ class FakeConnectivity(object): q.add_dbus_method_impl(self.NM_GetDevices, path=self.NM_PATH, interface=self.NM_INTERFACE, method='GetDevices') - q.add_dbus_method_impl(self.ConnMan_GetState, + q.add_dbus_method_impl(self.ConnMan_GetProperties, path=self.CONNMAN_PATH, interface=self.CONNMAN_INTERFACE, - method='GetState') + method='GetProperties') self.change_state(initially_online) @@ -88,8 +88,15 @@ class FakeConnectivity(object): def NM_GetDevices(self, e): self.q.dbus_return(e.message, [], signature='ao') - def ConnMan_GetState(self, e): - self.q.dbus_return(e.message, self.connman_state, signature='s') + def Connman_props(self): + return { + 'OfflineMode': False, + 'SessionMode': False, + 'State': self.connman_state, + } + + def ConnMan_GetProperties(self, e): + self.q.dbus_return(e.message, self.Connman_props(), signature='a{sv}') def change_state(self, online): if online: @@ -106,7 +113,7 @@ class FakeConnectivity(object): 'StateChanged', self.nm_state, signature='u') self.q.dbus_emit(self.CONNMAN_PATH, self.CONNMAN_INTERFACE, - 'StateChanged', self.connman_state, signature='s') + 'PropertyChanged', "State", self.connman_state, signature='sv') def go_online(self): self.change_state(True) -- 1.7.10.4