guint bus_watch_namespace (GBusType bus_type, const gchar *name_space, GBusNameAppearedCallback appeared_handler, GBusNameVanishedCallback vanished_handler, gpointer user_data, GDestroyNotify user_data_destroy) { NamespaceWatcher *watcher; /* same rules for interfaces and well-known names */ g_return_val_if_fail (name_space != NULL && g_dbus_is_interface_name (name_space), 0); g_return_val_if_fail (appeared_handler || vanished_handler, 0); watcher = g_new0 (NamespaceWatcher, 1); watcher->id = namespace_watcher_next_id++; watcher->name_space = g_strdup (name_space); watcher->appeared_handler = appeared_handler; watcher->vanished_handler = vanished_handler; watcher->user_data = user_data; watcher->user_data_destroy = user_data_destroy; watcher->cancellable = g_cancellable_new (); watcher->names = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); if (namespace_watcher_watchers == NULL) namespace_watcher_watchers = g_hash_table_new (g_direct_hash, g_direct_equal); g_hash_table_insert (namespace_watcher_watchers, GUINT_TO_POINTER (watcher->id), watcher); g_bus_get (bus_type, watcher->cancellable, got_bus, watcher); return watcher->id; }
/* < internal > * _g_dbus_method_invocation_new: * @sender: The bus name that invoked the method or %NULL if @connection is not a bus connection. * @object_path: The object path the method was invoked on. * @interface_name: The name of the D-Bus interface the method was invoked on. * @method_name: The name of the method that was invoked. * @method_info: Information about the method call or %NULL. * @connection: The #GDBusConnection the method was invoked on. * @message: The D-Bus message as a #GDBusMessage. * @parameters: The parameters as a #GVariant tuple. * @user_data: The @user_data #gpointer passed to g_dbus_connection_register_object(). * * Creates a new #GDBusMethodInvocation object. * * Returns: A #GDBusMethodInvocation. Free with g_object_unref(). * * Since: 2.26 */ GDBusMethodInvocation * _g_dbus_method_invocation_new (const gchar *sender, const gchar *object_path, const gchar *interface_name, const gchar *method_name, const GDBusMethodInfo *method_info, GDBusConnection *connection, GDBusMessage *message, GVariant *parameters, gpointer user_data) { GDBusMethodInvocation *invocation; g_return_val_if_fail (sender == NULL || g_dbus_is_name (sender), NULL); g_return_val_if_fail (g_variant_is_object_path (object_path), NULL); g_return_val_if_fail (interface_name == NULL || g_dbus_is_interface_name (interface_name), NULL); g_return_val_if_fail (g_dbus_is_member_name (method_name), NULL); g_return_val_if_fail (G_IS_DBUS_CONNECTION (connection), NULL); g_return_val_if_fail (G_IS_DBUS_MESSAGE (message), NULL); g_return_val_if_fail (g_variant_is_of_type (parameters, G_VARIANT_TYPE_TUPLE), NULL); invocation = G_DBUS_METHOD_INVOCATION (g_object_new (G_TYPE_DBUS_METHOD_INVOCATION, NULL)); invocation->sender = g_strdup (sender); invocation->object_path = g_strdup (object_path); invocation->interface_name = g_strdup (interface_name); invocation->method_name = g_strdup (method_name); invocation->method_info = g_dbus_method_info_ref ((GDBusMethodInfo *)method_info); invocation->connection = g_object_ref (connection); invocation->message = g_object_ref (message); invocation->parameters = g_variant_ref (parameters); invocation->user_data = user_data; return invocation; }
/** * g_dbus_object_skeleton_remove_interface_by_name: * @object: A #GDBusObjectSkeleton. * @interface_name: A D-Bus interface name. * * Removes the #GDBusInterface with @interface_name from @object. * * If no D-Bus interface of the given interface exists, this function * does nothing. * * Since: 2.30 */ void g_dbus_object_skeleton_remove_interface_by_name (GDBusObjectSkeleton *object, const gchar *interface_name) { GDBusInterface *interface; g_return_if_fail (G_IS_DBUS_OBJECT_SKELETON (object)); g_return_if_fail (g_dbus_is_interface_name (interface_name)); g_mutex_lock (object->priv->lock); interface = g_hash_table_lookup (object->priv->map_name_to_iface, interface_name); if (interface != NULL) { g_object_ref (interface); g_warn_if_fail (g_hash_table_remove (object->priv->map_name_to_iface, interface_name)); g_mutex_unlock (object->priv->lock); g_dbus_interface_set_object (interface, NULL); g_signal_emit_by_name (object, "interface-removed", interface); g_object_unref (interface); } else { g_mutex_unlock (object->priv->lock); } }
static gboolean register_portal (const char *path, GError **error) { g_autoptr(GKeyFile) keyfile = g_key_file_new (); g_autoptr(PortalImplementation) impl = g_new0 (PortalImplementation, 1); int i; g_debug ("loading %s", path); if (!g_key_file_load_from_file (keyfile, path, G_KEY_FILE_NONE, error)) return FALSE; impl->dbus_name = g_key_file_get_string (keyfile, "portal", "DBusName", error); if (impl->dbus_name == NULL) return FALSE; if (!g_dbus_is_name (impl->dbus_name)) { g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE, "Not a valid bus name: %s", impl->dbus_name); return FALSE; } impl->interfaces = g_key_file_get_string_list (keyfile, "portal", "Interfaces", NULL, error); if (impl->interfaces == NULL) return FALSE; for (i = 0; impl->interfaces[i]; i++) { if (!g_dbus_is_interface_name (impl->interfaces[i])) { g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE, "Not a valid interface name: %s", impl->interfaces[i]); return FALSE; } if (!g_str_has_prefix (impl->interfaces[i], "org.freedesktop.impl.portal.")) { g_set_error (error, G_KEY_FILE_ERROR, G_KEY_FILE_ERROR_INVALID_VALUE, "Not a portal backend interface: %s", impl->interfaces[i]); return FALSE; } } impl->use_in = g_key_file_get_string_list (keyfile, "portal", "UseIn", NULL, error); if (impl->use_in == NULL) return FALSE; if (opt_verbose) { g_autofree char *uses = g_strjoinv (", ", impl->use_in); g_debug ("portal implementation for %s", uses); for (i = 0; impl->interfaces[i]; i++) g_debug ("portal implementation supports %s", impl->interfaces[i]); } implementations = g_list_prepend (implementations, impl); impl = NULL; return TRUE; }
static GDBusInterface * g_dbus_object_proxy_get_interface (GDBusObject *object, const gchar *interface_name) { GDBusObjectProxy *proxy = G_DBUS_OBJECT_PROXY (object); GDBusProxy *ret; g_return_val_if_fail (G_IS_DBUS_OBJECT_PROXY (proxy), NULL); g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL); ret = g_hash_table_lookup (proxy->priv->map_name_to_iface, interface_name); if (ret != NULL) g_object_ref (ret); return (GDBusInterface *) ret; /* TODO: proper cast */ }
static GDBusInterface * g_dbus_object_skeleton_get_interface (GDBusObject *_object, const gchar *interface_name) { GDBusObjectSkeleton *object = G_DBUS_OBJECT_SKELETON (_object); GDBusInterface *ret; g_return_val_if_fail (G_IS_DBUS_OBJECT_SKELETON (object), NULL); g_return_val_if_fail (g_dbus_is_interface_name (interface_name), NULL); g_mutex_lock (object->priv->lock); ret = g_hash_table_lookup (object->priv->map_name_to_iface, interface_name); if (ret != NULL) g_object_ref (ret); g_mutex_unlock (object->priv->lock); return ret; }
void _g_dbus_object_proxy_remove_interface (GDBusObjectProxy *proxy, const gchar *interface_name) { GDBusProxy *interface_proxy; g_return_if_fail (G_IS_DBUS_OBJECT_PROXY (proxy)); g_return_if_fail (g_dbus_is_interface_name (interface_name)); interface_proxy = g_hash_table_lookup (proxy->priv->map_name_to_iface, interface_name); if (interface_proxy != NULL) { g_object_ref (interface_proxy); g_warn_if_fail (g_hash_table_remove (proxy->priv->map_name_to_iface, interface_name)); g_signal_emit_by_name (proxy, "interface-removed", interface_proxy); g_object_unref (interface_proxy); } }