Commit a55c87a2 authored by Thomas Haller's avatar Thomas Haller

core: refactor NMBusManager to hold reference to NMExportedObject directly

Previously, nm_bus_manager_register_object() would take various D-Bus
skeleton objects that were associated with one NMExportedObject.
This was confusing, in that these skeleton objects are all for the
same NMObject but correspond to different D-Bus interfaces.

Also, setting the D-Bus property "Managed" of a Device is broken
because we might retrieve the wrong skeleton.

Now, the NMBusManager has a reference to the exported object directly.
The skeleton interface instances instead are now exposed by the NMExportedObject.
parent 30e6c71f
This diff is collapsed.
......@@ -87,13 +87,12 @@ gboolean nm_bus_manager_get_caller_info_from_message (NMBusManager *self,
gulong *out_pid);
void nm_bus_manager_register_object (NMBusManager *self,
const char *path,
gpointer object);
NMExportedObject *object);
void nm_bus_manager_unregister_object (NMBusManager *self, gpointer object);
void nm_bus_manager_unregister_object (NMBusManager *self, NMExportedObject *object);
gpointer nm_bus_manager_get_registered_object (NMBusManager *self,
const char *path);
NMExportedObject *nm_bus_manager_get_registered_object (NMBusManager *self,
const char *path);
void nm_bus_manager_private_server_register (NMBusManager *self,
const char *path,
......
......@@ -36,6 +36,7 @@ G_DEFINE_ABSTRACT_TYPE_WITH_CODE (NMExportedObject, nm_exported_object, G_TYPE_O
typedef struct {
GSList *interfaces;
NMBusManager *bus_mgr;
char *path;
GVariantBuilder pending_notifies;
......@@ -427,15 +428,14 @@ const char *
nm_exported_object_export (NMExportedObject *self)
{
NMExportedObjectPrivate *priv;
NMBusManager *dbus_manager = nm_bus_manager_get ();
const char *class_export_path, *p;
GSList *iter;
GType type;
g_return_val_if_fail (NM_IS_EXPORTED_OBJECT (self), NULL);
priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
g_return_val_if_fail (priv->path == NULL, priv->path);
g_return_val_if_fail (!priv->path, priv->path);
g_return_val_if_fail (!priv->bus_mgr, NULL);
class_export_path = NM_EXPORTED_OBJECT_GET_CLASS (self)->export_path;
p = strchr (class_export_path, '%');
......@@ -461,8 +461,12 @@ nm_exported_object_export (NMExportedObject *self)
type = g_type_parent (type);
}
for (iter = priv->interfaces; iter; iter = iter->next)
nm_bus_manager_register_object (dbus_manager, priv->path, iter->data);
priv->bus_mgr = g_object_ref (nm_bus_manager_get ());
/* Important: priv->path and priv->interfaces must not change while
* the object is registered. */
nm_bus_manager_register_object (priv->bus_mgr, self);
return priv->path;
}
......@@ -510,20 +514,24 @@ void
nm_exported_object_unexport (NMExportedObject *self)
{
NMExportedObjectPrivate *priv;
GSList *iter;
g_return_if_fail (NM_IS_EXPORTED_OBJECT (self));
priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
g_return_if_fail (priv->path != NULL);
g_return_if_fail (priv->path);
g_return_if_fail (priv->bus_mgr);
g_clear_pointer (&priv->path, g_free);
/* Important: priv->path and priv->interfaces must not change while
* the object is registered. */
nm_bus_manager_unregister_object (priv->bus_mgr, self);
for (iter = priv->interfaces; iter; iter = iter->next)
nm_bus_manager_unregister_object (nm_bus_manager_get (), iter->data);
g_slist_free_full (priv->interfaces, g_object_unref);
priv->interfaces = NULL;
g_clear_pointer (&priv->path, g_free);
g_clear_object (&priv->bus_mgr);
if (nm_clear_g_source (&priv->notify_idle_id)) {
/* We had a notification queued. Since we removed all interfaces,
* the notification is obsolete and must be cleaned up. */
......@@ -532,6 +540,21 @@ nm_exported_object_unexport (NMExportedObject *self)
}
}
GSList *
nm_exported_object_get_interfaces (NMExportedObject *self)
{
NMExportedObjectPrivate *priv;
g_return_val_if_fail (NM_IS_EXPORTED_OBJECT (self), NULL);
priv = NM_EXPORTED_OBJECT_GET_PRIVATE (self);
g_return_val_if_fail (priv->path, NULL);
g_return_val_if_fail (priv->interfaces, NULL);
return priv->interfaces;
}
static void
nm_exported_object_init (NMExportedObject *self)
{
......
......@@ -52,6 +52,7 @@ const char *nm_exported_object_export (NMExportedObject *self);
const char *nm_exported_object_get_path (NMExportedObject *self);
gboolean nm_exported_object_is_exported (NMExportedObject *self);
void nm_exported_object_unexport (NMExportedObject *self);
GSList * nm_exported_object_get_interfaces (NMExportedObject *self);
G_END_DECLS
......
......@@ -4465,10 +4465,10 @@ do_set_property_check (gpointer user_data)
const char *error_message = NULL;
if (!pfd->object) {
GObject *object;
NMExportedObject *object;
object = nm_bus_manager_get_registered_object (nm_bus_manager_get (),
g_dbus_message_get_path (pfd->message));
g_dbus_message_get_path (pfd->message));
if (!object) {
reply = g_dbus_message_new_method_error (pfd->message,
"org.freedesktop.DBus.Error.UnknownObject",
......
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