Commit 3c7f267f authored by Dan Williams's avatar Dan Williams

core: use wrappers for DBus object registration/unregistration

When providing a service on the bus daemon and a private connection,
we'll need to track objects so we can register them with the
private connection too.  Thus all registration/unregistration
calls have to go through the NMDBusManager, not straight to
dbus-glib.
parent 1fec50cc
......@@ -217,8 +217,7 @@ nm_active_connection_export (NMActiveConnection *self)
priv->path = g_strdup_printf (NM_DBUS_PATH "/ActiveConnection/%d", counter++);
dbus_mgr = nm_dbus_manager_get ();
dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (dbus_mgr),
priv->path, G_OBJECT (self));
nm_dbus_manager_register_object (dbus_mgr, priv->path, self);
g_object_unref (dbus_mgr);
}
......
......@@ -48,6 +48,7 @@ G_DEFINE_TYPE(NMDBusManager, nm_dbus_manager, G_TYPE_OBJECT)
typedef struct {
DBusConnection *connection;
DBusGConnection *g_connection;
GHashTable *exported;
gboolean started;
DBusGProxy *proxy;
......@@ -59,6 +60,7 @@ typedef struct {
static gboolean nm_dbus_manager_init_bus (NMDBusManager *self);
static void nm_dbus_manager_cleanup (NMDBusManager *self, gboolean dispose);
static void start_reconnection_timeout (NMDBusManager *self);
static void object_destroyed (NMDBusManager *self, gpointer object);
NMDBusManager *
nm_dbus_manager_get (void)
......@@ -80,14 +82,29 @@ nm_dbus_manager_get (void)
static void
nm_dbus_manager_init (NMDBusManager *self)
{
NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
priv->exported = g_hash_table_new (g_direct_hash, g_direct_equal);
}
static void
nm_dbus_manager_dispose (GObject *object)
{
NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (object);
NMDBusManager *self = NM_DBUS_MANAGER (object);
NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
GHashTableIter iter;
GObject *exported;
if (priv->exported) {
g_hash_table_iter_init (&iter, priv->exported);
while (g_hash_table_iter_next (&iter, (gpointer) &exported, NULL))
g_object_weak_unref (exported, (GWeakNotify) object_destroyed, self);
g_hash_table_destroy (priv->exported);
priv->exported = NULL;
}
nm_dbus_manager_cleanup (NM_DBUS_MANAGER (object), TRUE);
nm_dbus_manager_cleanup (self, TRUE);
if (priv->reconnect_id) {
g_source_remove (priv->reconnect_id);
......@@ -358,3 +375,38 @@ nm_dbus_manager_get_connection (NMDBusManager *self)
return NM_DBUS_MANAGER_GET_PRIVATE (self)->g_connection;
}
static void
object_destroyed (NMDBusManager *self, gpointer object)
{
g_hash_table_remove (NM_DBUS_MANAGER_GET_PRIVATE (self)->exported, object);
}
void
nm_dbus_manager_register_object (NMDBusManager *self,
const char *path,
gpointer object)
{
NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
g_assert (G_IS_OBJECT (object));
g_warn_if_fail (g_hash_table_lookup (priv->exported, object) == NULL);
g_hash_table_insert (priv->exported, G_OBJECT (object), GUINT_TO_POINTER (1));
dbus_g_connection_register_g_object (priv->g_connection, path, G_OBJECT (object));
g_object_weak_ref (G_OBJECT (object), (GWeakNotify) object_destroyed, self);
}
void
nm_dbus_manager_unregister_object (NMDBusManager *self, gpointer object)
{
NMDBusManagerPrivate *priv = NM_DBUS_MANAGER_GET_PRIVATE (self);
g_assert (G_IS_OBJECT (object));
g_hash_table_remove (NM_DBUS_MANAGER_GET_PRIVATE (self)->exported, G_OBJECT (object));
g_object_weak_unref (G_OBJECT (object), (GWeakNotify) object_destroyed, self);
dbus_g_connection_unregister_g_object (priv->g_connection, G_OBJECT (object));
}
......@@ -75,6 +75,12 @@ gboolean nm_dbus_manager_name_has_owner (NMDBusManager *self,
DBusConnection * nm_dbus_manager_get_dbus_connection (NMDBusManager *self);
DBusGConnection * nm_dbus_manager_get_connection (NMDBusManager *self);
void nm_dbus_manager_register_object (NMDBusManager *self,
const char *path,
gpointer object);
void nm_dbus_manager_unregister_object (NMDBusManager *self, gpointer object);
G_END_DECLS
#endif /* __NM_DBUS_MANAGER_H__ */
......@@ -140,13 +140,11 @@ nm_dhcp4_config_init (NMDHCP4Config *self)
{
NMDHCP4ConfigPrivate *priv = NM_DHCP4_CONFIG_GET_PRIVATE (self);
static guint32 counter = 0;
DBusGConnection *connection;
NMDBusManager *dbus_mgr;
dbus_mgr = nm_dbus_manager_get ();
connection = nm_dbus_manager_get_connection (dbus_mgr);
priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/DHCP4Config/%d", counter++);
dbus_g_connection_register_g_object (connection, priv->dbus_path, G_OBJECT (self));
nm_dbus_manager_register_object (dbus_mgr, priv->dbus_path, self);
g_object_unref (dbus_mgr);
priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy);
......
......@@ -140,13 +140,11 @@ nm_dhcp6_config_init (NMDHCP6Config *self)
{
NMDHCP6ConfigPrivate *priv = NM_DHCP6_CONFIG_GET_PRIVATE (self);
static guint32 counter = 0;
DBusGConnection *connection;
NMDBusManager *dbus_mgr;
dbus_mgr = nm_dbus_manager_get ();
connection = nm_dbus_manager_get_connection (dbus_mgr);
priv->dbus_path = g_strdup_printf (NM_DBUS_PATH "/DHCP6Config/%d", counter++);
dbus_g_connection_register_g_object (connection, priv->dbus_path, G_OBJECT (self));
nm_dbus_manager_register_object (dbus_mgr, priv->dbus_path, self);
g_object_unref (dbus_mgr);
priv->options = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, nm_gvalue_destroy);
......
......@@ -102,7 +102,6 @@ nm_ip4_config_export (NMIP4Config *config)
{
NMIP4ConfigPrivate *priv;
NMDBusManager *dbus_mgr;
DBusGConnection *connection;
static guint32 counter = 0;
g_return_if_fail (NM_IS_IP4_CONFIG (config));
......@@ -111,10 +110,8 @@ nm_ip4_config_export (NMIP4Config *config)
g_return_if_fail (priv->path == NULL);
dbus_mgr = nm_dbus_manager_get ();
connection = nm_dbus_manager_get_connection (dbus_mgr);
priv->path = g_strdup_printf (NM_DBUS_PATH "/IP4Config/%d", counter++);
dbus_g_connection_register_g_object (connection, priv->path, G_OBJECT (config));
nm_dbus_manager_register_object (dbus_mgr, priv->path, config);
g_object_unref (dbus_mgr);
}
......
......@@ -99,7 +99,6 @@ nm_ip6_config_export (NMIP6Config *config)
{
NMIP6ConfigPrivate *priv;
NMDBusManager *dbus_mgr;
DBusGConnection *connection;
static guint32 counter = 0;
g_return_if_fail (NM_IS_IP6_CONFIG (config));
......@@ -108,10 +107,8 @@ nm_ip6_config_export (NMIP6Config *config)
g_return_if_fail (priv->path == NULL);
dbus_mgr = nm_dbus_manager_get ();
connection = nm_dbus_manager_get_connection (dbus_mgr);
priv->path = g_strdup_printf (NM_DBUS_PATH "/IP6Config/%d", counter++);
dbus_g_connection_register_g_object (connection, priv->path, G_OBJECT (config));
nm_dbus_manager_register_object (dbus_mgr, priv->path, config);
g_object_unref (dbus_mgr);
}
......
......@@ -1892,9 +1892,7 @@ add_device (NMManager *self, NMDevice *device)
path = g_strdup_printf ("/org/freedesktop/NetworkManager/Devices/%d", devcount++);
nm_device_set_path (device, path);
dbus_g_connection_register_g_object (nm_dbus_manager_get_connection (priv->dbus_mgr),
path,
G_OBJECT (device));
nm_dbus_manager_register_object (priv->dbus_mgr, path, device);
nm_log_info (LOGD_CORE, "(%s): exported as %s", iface, path);
g_free (path);
......@@ -4124,7 +4122,7 @@ nm_manager_new (NMSettings *settings,
g_signal_connect (priv->settings, NM_SETTINGS_SIGNAL_CONNECTION_VISIBILITY_CHANGED,
G_CALLBACK (connection_changed), singleton);
dbus_g_connection_register_g_object (bus, NM_DBUS_PATH, G_OBJECT (singleton));
nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH, singleton);
priv->udev_mgr = nm_udev_manager_new ();
g_signal_connect (priv->udev_mgr,
......
......@@ -318,7 +318,6 @@ nm_ap_export_to_dbus (NMAccessPoint *ap)
{
NMAccessPointPrivate *priv;
NMDBusManager *mgr;
DBusGConnection *g_connection;
static guint32 counter = 0;
g_return_if_fail (NM_IS_AP (ap));
......@@ -331,14 +330,8 @@ nm_ap_export_to_dbus (NMAccessPoint *ap)
}
mgr = nm_dbus_manager_get ();
g_assert (mgr);
g_connection = nm_dbus_manager_get_connection (mgr);
g_assert (g_connection);
priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_ACCESS_POINT "/%d", counter++);
dbus_g_connection_register_g_object (g_connection, priv->dbus_path, G_OBJECT (ap));
nm_dbus_manager_register_object (mgr, priv->dbus_path, ap);
g_object_unref (mgr);
}
......
......@@ -1402,7 +1402,6 @@ nm_agent_manager_get (void)
{
static NMAgentManager *singleton = NULL;
NMAgentManagerPrivate *priv;
DBusGConnection *connection;
if (singleton)
return g_object_ref (singleton);
......@@ -1414,10 +1413,7 @@ nm_agent_manager_get (void)
priv->session_monitor = nm_session_monitor_get ();
priv->dbus_mgr = nm_dbus_manager_get ();
connection = nm_dbus_manager_get_connection (priv->dbus_mgr);
dbus_g_connection_register_g_object (connection,
NM_DBUS_PATH_AGENT_MANAGER,
G_OBJECT (singleton));
nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_AGENT_MANAGER, singleton);
g_signal_connect (priv->dbus_mgr,
NM_DBUS_MANAGER_NAME_OWNER_CHANGED,
......
......@@ -117,7 +117,6 @@ G_DEFINE_TYPE_EXTENDED (NMSettings, nm_settings, G_TYPE_OBJECT, 0,
typedef struct {
NMDBusManager *dbus_mgr;
DBusGConnection *bus;
NMAgentManager *agent_mgr;
......@@ -707,7 +706,7 @@ connection_unregister (NMSettingsConnection *obj, gpointer user_data)
guint id;
/* Make sure it's unregistered from the bus now that's removed */
dbus_g_connection_unregister_g_object (priv->bus, connection);
nm_dbus_manager_unregister_object (priv->dbus_mgr, connection);
id = GPOINTER_TO_UINT (g_object_get_data (connection, UNREG_ID_TAG));
if (id)
......@@ -856,7 +855,7 @@ claim_connection (NMSettings *self,
g_warn_if_fail (nm_connection_get_path (NM_CONNECTION (connection)) == NULL);
path = g_strdup_printf ("%s/%u", NM_DBUS_PATH_SETTINGS, ec_counter++);
nm_connection_set_path (NM_CONNECTION (connection), path);
dbus_g_connection_register_g_object (priv->bus, path, G_OBJECT (connection));
nm_dbus_manager_register_object (priv->dbus_mgr, path, G_OBJECT (connection));
g_free (path);
g_hash_table_insert (priv->connections,
......@@ -1615,7 +1614,6 @@ nm_settings_new (GError **error)
priv->config = nm_config_get ();
priv->dbus_mgr = nm_dbus_manager_get ();
priv->bus = nm_dbus_manager_get_connection (priv->dbus_mgr);
/* Load the plugins; fail if a plugin is not found. */
if (!load_plugins (self, nm_config_get_plugins (priv->config), error)) {
......@@ -1625,7 +1623,7 @@ nm_settings_new (GError **error)
unmanaged_specs_changed (NULL, self);
dbus_g_connection_register_g_object (priv->bus, NM_DBUS_PATH_SETTINGS, G_OBJECT (self));
nm_dbus_manager_register_object (priv->dbus_mgr, NM_DBUS_PATH_SETTINGS, self);
return self;
}
......
......@@ -96,7 +96,6 @@ nm_wimax_nsp_export_to_dbus (NMWimaxNsp *self)
{
NMWimaxNspPrivate *priv;
NMDBusManager *mgr;
DBusGConnection *g_connection;
static guint32 counter = 0;
g_return_if_fail (NM_IS_WIMAX_NSP (self));
......@@ -106,14 +105,8 @@ nm_wimax_nsp_export_to_dbus (NMWimaxNsp *self)
g_return_if_fail (priv->dbus_path == NULL);
mgr = nm_dbus_manager_get ();
g_assert (mgr);
g_connection = nm_dbus_manager_get_connection (mgr);
g_assert (g_connection);
priv->dbus_path = g_strdup_printf (NM_DBUS_PATH_WIMAX_NSP "/%d", counter++);
dbus_g_connection_register_g_object (g_connection, priv->dbus_path, G_OBJECT (self));
nm_dbus_manager_register_object (mgr, priv->dbus_path, self);
g_object_unref (mgr);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment