diff options
author | Dan Winship <danw@redhat.com> | 2015-04-20 10:48:57 -0400 |
---|---|---|
committer | Dan Winship <danw@redhat.com> | 2015-07-24 13:25:47 -0400 |
commit | 1bcf42f37b2b69e37ecb41d34f16765119c25348 (patch) | |
tree | cbdb638760beef92818adb3f25d9b726d8ded1f9 /src | |
parent | 94078a139a4353518875aade615b087f546310af (diff) | |
download | NetworkManager-1bcf42f37b2b69e37ecb41d34f16765119c25348.tar.gz |
bluetooth, vpn-manager: use GDBusProxies to monitor services
Create a GDBusProxy for the service to be monitored and use that to
tell whether it is running, rather than using NMDBusManager and the
global NameOwnerChanged signal.
Diffstat (limited to 'src')
-rw-r--r-- | src/devices/bluetooth/nm-bluez5-manager.c | 65 | ||||
-rw-r--r-- | src/devices/bluetooth/nm-device-bt.c | 68 | ||||
-rw-r--r-- | src/vpn-manager/nm-vpn-service.c | 54 |
3 files changed, 81 insertions, 106 deletions
diff --git a/src/devices/bluetooth/nm-bluez5-manager.c b/src/devices/bluetooth/nm-bluez5-manager.c index 7fe0c074ba..ceb8d484d6 100644 --- a/src/devices/bluetooth/nm-bluez5-manager.c +++ b/src/devices/bluetooth/nm-bluez5-manager.c @@ -33,13 +33,9 @@ #include "nm-bluez-device.h" #include "nm-bluez-common.h" -#include "nm-dbus-manager.h" #include "nm-core-internal.h" typedef struct { - NMDBusManager *dbus_mgr; - gulong name_owner_changed_id; - NMConnectionProvider *provider; GDBusProxy *proxy; @@ -224,6 +220,8 @@ get_managed_objects_cb (GDBusProxy *proxy, g_variant_unref (variant); } +static void name_owner_changed_cb (GObject *object, GParamSpec *pspec, gpointer user_data); + static void on_proxy_acquired (GObject *object, GAsyncResult *res, @@ -241,6 +239,9 @@ on_proxy_acquired (GObject *object, return; } + g_signal_connect (priv->proxy, "notify::g-name-owner", + G_CALLBACK (name_owner_changed_cb), self); + /* Get already managed devices. */ g_dbus_proxy_call (priv->proxy, "GetManagedObjects", NULL, @@ -275,24 +276,19 @@ bluez_connect (NMBluez5Manager *self) } static void -name_owner_changed_cb (NMDBusManager *dbus_mgr, - const char *name, - const char *old_owner, - const char *new_owner, +name_owner_changed_cb (GObject *object, + GParamSpec *pspec, gpointer user_data) { NMBluez5Manager *self = NM_BLUEZ5_MANAGER (user_data); NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); - gboolean old_owner_good = (old_owner && strlen (old_owner)); - gboolean new_owner_good = (new_owner && strlen (new_owner)); - - /* Can't handle the signal if its not from the Bluez */ - if (strcmp (BLUEZ_SERVICE, name)) - return; + char *owner; - if (old_owner_good && !new_owner_good) { - if (priv->devices) + if (priv->devices) { + owner = g_dbus_proxy_get_name_owner (priv->proxy); + if (!owner) remove_all_devices (self); + g_free (owner); } } @@ -302,8 +298,8 @@ bluez_cleanup (NMBluez5Manager *self, gboolean do_signal) NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); if (priv->proxy) { - g_object_unref (priv->proxy); - priv->proxy = NULL; + g_signal_handlers_disconnect_by_func (priv->proxy, G_CALLBACK (name_owner_changed_cb), self); + g_clear_object (&priv->proxy); } if (do_signal) @@ -312,19 +308,6 @@ bluez_cleanup (NMBluez5Manager *self, gboolean do_signal) g_hash_table_remove_all (priv->devices); } -static void -dbus_connection_changed_cb (NMDBusManager *dbus_mgr, - DBusGConnection *connection, - gpointer user_data) -{ - NMBluez5Manager *self = NM_BLUEZ5_MANAGER (user_data); - - if (!connection) - bluez_cleanup (self, TRUE); - else - bluez_connect (self); -} - /****************************************************************/ NMBluez5Manager * @@ -342,19 +325,6 @@ nm_bluez5_manager_init (NMBluez5Manager *self) { NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); - priv->dbus_mgr = nm_dbus_manager_get (); - g_assert (priv->dbus_mgr); - - g_signal_connect (priv->dbus_mgr, - NM_DBUS_MANAGER_NAME_OWNER_CHANGED, - G_CALLBACK (name_owner_changed_cb), - self); - - g_signal_connect (priv->dbus_mgr, - NM_DBUS_MANAGER_DBUS_CONNECTION_CHANGED, - G_CALLBACK (dbus_connection_changed_cb), - self); - bluez_connect (self); priv->devices = g_hash_table_new_full (g_str_hash, g_str_equal, @@ -365,16 +335,9 @@ static void dispose (GObject *object) { NMBluez5Manager *self = NM_BLUEZ5_MANAGER (object); - NMBluez5ManagerPrivate *priv = NM_BLUEZ5_MANAGER_GET_PRIVATE (self); bluez_cleanup (self, FALSE); - if (priv->dbus_mgr) { - g_signal_handlers_disconnect_by_func (priv->dbus_mgr, name_owner_changed_cb, self); - g_signal_handlers_disconnect_by_func (priv->dbus_mgr, dbus_connection_changed_cb, self); - priv->dbus_mgr = NULL; - } - G_OBJECT_CLASS (nm_bluez5_manager_parent_class)->dispose (object); } diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c index 7fd793b451..55b8d0aef5 100644 --- a/src/devices/bluetooth/nm-device-bt.c +++ b/src/devices/bluetooth/nm-device-bt.c @@ -28,7 +28,6 @@ #include "nm-glib.h" #include "nm-bluez-common.h" #include "nm-bluez-device.h" -#include "nm-dbus-manager.h" #include "nm-device-bt.h" #include "nm-device-private.h" #include "nm-logging.h" @@ -46,7 +45,9 @@ #include "nm-bt-error.h" #include "nm-bt-enum-types.h" -#define MM_DBUS_SERVICE "org.freedesktop.ModemManager1" +#define MM_DBUS_SERVICE "org.freedesktop.ModemManager1" +#define MM_DBUS_PATH "/org/freedesktop/ModemManager1" +#define MM_DBUS_INTERFACE "org.freedesktop.ModemManager1" #include "nm-device-logging.h" _LOG_DECLARE_SELF(NMDeviceBt); @@ -58,8 +59,7 @@ G_DEFINE_TYPE (NMDeviceBt, nm_device_bt, NM_TYPE_DEVICE) static gboolean modem_stage1 (NMDeviceBt *self, NMModem *modem, NMDeviceStateReason *reason); typedef struct { - NMDBusManager *dbus_mgr; - guint mm_watch_id; + GDBusProxy *mm_proxy; gboolean mm_running; NMBluezDevice *bt_device; @@ -966,25 +966,17 @@ set_mm_running (NMDeviceBt *self, gboolean running) } static void -mm_name_owner_changed (NMDBusManager *dbus_mgr, - const char *name, - const char *old_owner, - const char *new_owner, +mm_name_owner_changed (GObject *object, + GParamSpec *pspec, NMDeviceBt *self) { - gboolean old_owner_good; - gboolean new_owner_good; + char *owner; - /* Can't handle the signal if its not from the modem service */ - if (strcmp (MM_DBUS_SERVICE, name) != 0) - return; - - old_owner_good = (old_owner && strlen (old_owner)); - new_owner_good = (new_owner && strlen (new_owner)); - - if (!old_owner_good && new_owner_good) + owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (object)); + if (owner) { set_mm_running (self, TRUE); - else if (old_owner_good && !new_owner_good) + g_free (owner); + } else set_mm_running (self, FALSE); } @@ -1020,18 +1012,27 @@ static void nm_device_bt_init (NMDeviceBt *self) { NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (self); - gboolean mm_running; - - priv->dbus_mgr = nm_dbus_manager_get (); - - priv->mm_watch_id = g_signal_connect (priv->dbus_mgr, - NM_DBUS_MANAGER_NAME_OWNER_CHANGED, - G_CALLBACK (mm_name_owner_changed), - self); + GError *error = NULL; - /* Initial check to see if ModemManager is running */ - mm_running = nm_dbus_manager_name_has_owner (priv->dbus_mgr, MM_DBUS_SERVICE); - set_mm_running (self, mm_running); + priv->mm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, + MM_DBUS_SERVICE, + MM_DBUS_PATH, + MM_DBUS_INTERFACE, + NULL, &error); + if (priv->mm_proxy) { + g_signal_connect (priv->mm_proxy, "notify::g-name-owner", + G_CALLBACK (mm_name_owner_changed), + self); + mm_name_owner_changed (G_OBJECT (priv->mm_proxy), NULL, self); + } else { + _LOGW (LOGD_MB, "Could not create proxy for '%s': %s", + MM_DBUS_SERVICE, error->message); + g_clear_error (&error); + } } static void @@ -1112,11 +1113,10 @@ dispose (GObject *object) g_signal_handlers_disconnect_matched (priv->bt_device, G_SIGNAL_MATCH_DATA, 0, 0, NULL, NULL, object); - if (priv->dbus_mgr && priv->mm_watch_id) { - g_signal_handler_disconnect (priv->dbus_mgr, priv->mm_watch_id); - priv->mm_watch_id = 0; + if (priv->mm_proxy) { + g_signal_handlers_disconnect_by_func (priv->mm_proxy, G_CALLBACK (mm_name_owner_changed), object); + g_clear_object (&priv->mm_proxy); } - priv->dbus_mgr = NULL; modem_cleanup (NM_DEVICE_BT (object)); g_clear_object (&priv->bt_device); diff --git a/src/vpn-manager/nm-vpn-service.c b/src/vpn-manager/nm-vpn-service.c index 3eb0e2e398..56cb6abe74 100644 --- a/src/vpn-manager/nm-vpn-service.c +++ b/src/vpn-manager/nm-vpn-service.c @@ -29,7 +29,6 @@ #include "nm-glib.h" #include "nm-vpn-service.h" -#include "nm-dbus-manager.h" #include "nm-logging.h" #include "nm-vpn-manager.h" @@ -45,6 +44,7 @@ typedef struct { GSList *pending; guint start_timeout; + GDBusProxy *proxy; gboolean service_running; } NMVpnServicePrivate; @@ -54,6 +54,8 @@ typedef struct { static gboolean start_pending_vpn (NMVpnService *self, GError **error); +static void _name_owner_changed (GObject *object, GParamSpec *pspec, gpointer user_data); + NMVpnService * nm_vpn_service_new (const char *namefile, GError **error) { @@ -86,7 +88,21 @@ nm_vpn_service_new (const char *namefile, GError **error) if (!priv->name) goto error; - priv->service_running = nm_dbus_manager_name_has_owner (nm_dbus_manager_get (), priv->dbus_service); + priv->proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | + G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS | + G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START, + NULL, + priv->dbus_service, + NM_VPN_DBUS_PLUGIN_PATH, + NM_VPN_DBUS_PLUGIN_INTERFACE, + NULL, error); + if (!priv->proxy) + goto error; + + g_signal_connect (priv->proxy, "notify::g-name-owner", + G_CALLBACK (_name_owner_changed), self); + _name_owner_changed (G_OBJECT (priv->proxy), NULL, self); g_key_file_free (kf); return self; @@ -288,18 +304,16 @@ nm_vpn_service_activate (NMVpnService *service, } static void -_name_owner_changed (NMDBusManager *mgr, - const char *name, - const char *old, - const char *new, +_name_owner_changed (GObject *object, + GParamSpec *pspec, gpointer user_data) { NMVpnService *service = NM_VPN_SERVICE (user_data); NMVpnServicePrivate *priv = NM_VPN_SERVICE_GET_PRIVATE (service); - gboolean old_owner_good, new_owner_good, success; + gboolean success; + char *owner; - if (strcmp (name, priv->dbus_service)) - return; + owner = g_dbus_proxy_get_name_owner (G_DBUS_PROXY (object)); /* Service changed, no need to wait for the timeout any longer */ if (priv->start_timeout) { @@ -307,22 +321,21 @@ _name_owner_changed (NMDBusManager *mgr, priv->start_timeout = 0; } - old_owner_good = (old && old[0]); - new_owner_good = (new && new[0]); - - if (!old_owner_good && new_owner_good) { + if (owner && !priv->service_running) { /* service appeared */ priv->service_running = TRUE; nm_log_info (LOGD_VPN, "VPN service '%s' appeared; activating connections", priv->name); /* Expect success because the VPN service has already appeared */ success = start_active_vpn (service, NULL); g_warn_if_fail (success); - } else if (old_owner_good && !new_owner_good) { + } else if (!owner && priv->service_running) { /* service went away */ priv->service_running = FALSE; nm_log_info (LOGD_VPN, "VPN service '%s' disappeared", priv->name); nm_vpn_service_stop_connections (service, FALSE, NM_VPN_CONNECTION_STATE_REASON_SERVICE_STOPPED); } + + g_free (owner); } /******************************************************************************/ @@ -330,10 +343,6 @@ _name_owner_changed (NMDBusManager *mgr, static void nm_vpn_service_init (NMVpnService *self) { - g_signal_connect (nm_dbus_manager_get (), - NM_DBUS_MANAGER_NAME_OWNER_CHANGED, - G_CALLBACK (_name_owner_changed), - self); } static void @@ -351,9 +360,12 @@ dispose (GObject *object) g_assert (priv->active == NULL); g_assert (priv->pending == NULL); - g_signal_handlers_disconnect_by_func (nm_dbus_manager_get (), - G_CALLBACK (_name_owner_changed), - self); + if (priv->proxy) { + g_signal_handlers_disconnect_by_func (priv->proxy, + G_CALLBACK (_name_owner_changed), + self); + g_clear_object (&priv->proxy); + } G_OBJECT_CLASS (nm_vpn_service_parent_class)->dispose (object); } |