void storage_daemon_publish (StorageDaemon *self, const gchar *path, gboolean uniquely, gpointer thing) { GDBusInterface *prev; GDBusInterfaceInfo *info; GDBusObjectSkeleton *object; GQuark detail; g_return_if_fail (STORAGE_IS_DAEMON (self)); g_return_if_fail (path != NULL); if (G_IS_DBUS_INTERFACE (thing)) { g_debug ("%spublishing iface: %s %s", uniquely ? "uniquely " : "", path, g_dbus_interface_get_info(thing)->name); object = G_DBUS_OBJECT_SKELETON (g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (self->object_manager), path)); if (object != NULL) { if (uniquely) { info = g_dbus_interface_get_info (thing); prev = g_dbus_object_get_interface (G_DBUS_OBJECT (object), info->name); if (prev) { g_object_unref (prev); g_object_unref (object); object = NULL; } } } if (object == NULL) object = g_dbus_object_skeleton_new (path); g_dbus_object_skeleton_add_interface (object, thing); } else { g_critical ("Unsupported type to publish: %s", G_OBJECT_TYPE_NAME (thing)); return; } if (uniquely) g_dbus_object_manager_server_export_uniquely (self->object_manager, object); else g_dbus_object_manager_server_export (self->object_manager, object); detail = g_quark_from_static_string (G_OBJECT_TYPE_NAME (thing)); g_signal_emit (self, signals[PUBLISHED], detail, thing); g_object_unref (object); }
void storage_daemon_unpublish (StorageDaemon *self, const gchar *path, gpointer thing) { GDBusObject *object; gboolean unexport = FALSE; GList *interfaces, *l; g_return_if_fail (STORAGE_IS_DAEMON (self)); g_return_if_fail (path != NULL); object = g_dbus_object_manager_get_object (G_DBUS_OBJECT_MANAGER (self->object_manager), path); if (object == NULL) return; path = g_dbus_object_get_object_path (G_DBUS_OBJECT (object)); if (G_IS_DBUS_INTERFACE (thing)) { g_debug ("unpublishing interface: %s %s", path, g_dbus_interface_get_info(thing)->name); unexport = TRUE; interfaces = g_dbus_object_get_interfaces (object); for (l = interfaces; l != NULL; l = g_list_next (l)) { if (G_DBUS_INTERFACE (l->data) != G_DBUS_INTERFACE (thing)) unexport = FALSE; } g_list_free_full (interfaces, g_object_unref); /* * HACK: GDBusObjectManagerServer is broken ... and sends InterfaceRemoved * too many times, if you remove all interfaces manually, and then unexport * a GDBusObject. So only do it here if we're not unexporting the object. */ if (!unexport) g_dbus_object_skeleton_remove_interface (G_DBUS_OBJECT_SKELETON (object), thing); else g_debug ("(unpublishing object, too)"); } else if (thing == NULL) { unexport = TRUE; } else { g_critical ("Unsupported type to unpublish: %s", G_OBJECT_TYPE_NAME (thing)); } if (unexport) g_dbus_object_manager_server_unexport (self->object_manager, path); g_object_unref (object); }
static void print_objects (GDBusObjectManager *manager) { GList *objects; GList *l; g_print ("Object manager at %s\n", g_dbus_object_manager_get_object_path (manager)); objects = g_dbus_object_manager_get_objects (manager); for (l = objects; l != NULL; l = l->next) { ExampleObject *object = EXAMPLE_OBJECT (l->data); GList *interfaces; GList *ll; g_print (" - Object at %s\n", g_dbus_object_get_object_path (G_DBUS_OBJECT (object))); interfaces = g_dbus_object_get_interfaces (G_DBUS_OBJECT (object)); for (ll = interfaces; ll != NULL; ll = ll->next) { GDBusInterface *interface = G_DBUS_INTERFACE (ll->data); g_print (" - Interface %s\n", g_dbus_interface_get_info (interface)->name); /* Note that @interface is really a GDBusProxy instance - and additionally also * an ExampleAnimal or ExampleCat instance - either of these can be used to * invoke methods on the remote object. For example, the generated function * * void example_animal_call_poke_sync (ExampleAnimal *proxy, * gboolean make_sad, * gboolean make_happy, * GCancellable *cancellable, * GError **error); * * can be used to call the Poke() D-Bus method on the .Animal interface. * Additionally, the generated function * * const gchar *example_animal_get_mood (ExampleAnimal *object); * * can be used to get the value of the :Mood property. */ } g_list_free_full (interfaces, g_object_unref); } g_list_free_full (objects, g_object_unref); }
static gboolean update_iface (StoragedObject *object, const gchar *uevent_action, StoragedObjectHasInterfaceFunc has_func, StoragedObjectConnectInterfaceFunc connect_func, StoragedObjectUpdateInterfaceFunc update_func, GType skeleton_type, gpointer _interface_pointer) { gboolean ret = FALSE; gboolean has; gboolean add; GDBusInterface **interface_pointer = _interface_pointer; GDBusInterfaceInfo *interface_info = NULL; g_return_val_if_fail (object != NULL, FALSE); g_return_val_if_fail (has_func != NULL, FALSE); g_return_val_if_fail (update_func != NULL, FALSE); g_return_val_if_fail (g_type_is_a (skeleton_type, G_TYPE_OBJECT), FALSE); g_return_val_if_fail (g_type_is_a (skeleton_type, G_TYPE_DBUS_INTERFACE), FALSE); g_return_val_if_fail (interface_pointer != NULL, FALSE); g_return_val_if_fail (*interface_pointer == NULL || G_IS_DBUS_INTERFACE (*interface_pointer), FALSE); add = FALSE; has = has_func (object); if (*interface_pointer == NULL) { if (has) { *interface_pointer = g_object_new (skeleton_type, NULL); if (connect_func != NULL) connect_func (object); add = TRUE; } } else { if (!has) { /* Check before we remove interface from object */ interface_info = g_dbus_interface_get_info (*interface_pointer); if (g_dbus_object_get_interface ((GDBusObject *) object, interface_info->name)) g_dbus_object_skeleton_remove_interface (G_DBUS_OBJECT_SKELETON (object), G_DBUS_INTERFACE_SKELETON (*interface_pointer)); g_object_unref (*interface_pointer); *interface_pointer = NULL; } } if (*interface_pointer != NULL) { if (update_func (object, uevent_action, G_DBUS_INTERFACE (*interface_pointer))) ret = TRUE; if (add) g_dbus_object_skeleton_add_interface (G_DBUS_OBJECT_SKELETON (object), G_DBUS_INTERFACE_SKELETON (*interface_pointer)); } return ret; }