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; }
static void mex_mpris_plugin_init (MexMprisPlugin *self) { MexMprisPluginPrivate *priv = self->priv = MPRIS_PLUGIN_PRIVATE (self); GError *error=NULL; priv->player = mex_player_get_default (); priv->media = mex_player_get_clutter_media (priv->player); g_signal_connect (priv->media, "notify::in-seek", G_CALLBACK (_check_if_seeked), self); g_bus_own_name (G_BUS_TYPE_SESSION, MPRIS_BUS_NAME_PREFIX ".media-explorer", G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL, NULL); if (!(priv->introspection_data = g_dbus_node_info_new_for_xml (mpris_introspection_xml, &error))) g_warning ("Error %s", error->message); g_bus_get (G_BUS_TYPE_SESSION, NULL, on_bus_acquired, self); priv->mimes_supported = g_strsplit (MEX_MIME_TYPES, ";", -1); }
int gtk_module_init(gint argc, char *argv[]) { initialise_logging(); autopilot_introspection = autopilot_introspection_skeleton_new (); g_bus_get (G_BUS_TYPE_SESSION, NULL, bus_acquired, NULL); // always log this: std::cout << "Autopilot GTK interface loaded. Wire protocol version is " << WIRE_PROTO_VERSION << "." << std::endl; return 0; }
static void gclue_modem_source_constructed (GObject *object) { GClueModemSourcePrivate *priv = GCLUE_MODEM_SOURCE (object)->priv; priv->cancellable = g_cancellable_new (); g_bus_get (G_BUS_TYPE_SYSTEM, priv->cancellable, on_bus_get_ready, object); }
void _nm_dbus_new_connection_async (GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data) { GSimpleAsyncResult *simple; simple = g_simple_async_result_new (NULL, callback, user_data, _nm_dbus_new_connection_async); g_bus_get (_nm_dbus_bus_type (), cancellable, new_connection_async_got_system, simple); }
static void connect_system_bus( GIO_ASYNCSEQ_HANDLE async_seq_handle, gpointer previous_result, gpointer callback_context, GAsyncReadyCallback async_callback ) { g_bus_get( G_BUS_TYPE_SYSTEM, NULL, // not cancellable async_callback, async_seq_handle ); }
/** * g_bus_own_name: * @bus_type: The type of bus to own a name on. * @name: The well-known name to own. * @flags: A set of flags from the #GBusNameOwnerFlags enumeration. * @bus_acquired_handler: Handler to invoke when connected to the bus of type @bus_type or %NULL. * @name_acquired_handler: Handler to invoke when @name is acquired or %NULL. * @name_lost_handler: Handler to invoke when @name is lost or %NULL. * @user_data: User data to pass to handlers. * @user_data_free_func: Function for freeing @user_data or %NULL. * * Starts acquiring @name on the bus specified by @bus_type and calls * @name_acquired_handler and @name_lost_handler when the name is * acquired respectively lost. Callbacks will be invoked in the <link * linkend="g-main-context-push-thread-default">thread-default main * loop</link> of the thread you are calling this function from. * * You are guaranteed that one of the @name_acquired_handler and @name_lost_handler * callbacks will be invoked after calling this function - there are three * possible cases: * <itemizedlist> * <listitem><para> * @name_lost_handler with a %NULL connection (if a connection to the bus can't be made). * </para></listitem> * <listitem><para> * @bus_acquired_handler then @name_lost_handler (if the name can't be obtained) * </para></listitem> * <listitem><para> * @bus_acquired_handler then @name_acquired_handler (if the name was obtained). * </para></listitem> * </itemizedlist> * When you are done owning the name, just call g_bus_unown_name() * with the owner id this function returns. * * If the name is acquired or lost (for example another application * could acquire the name if you allow replacement or the application * currently owning the name exits), the handlers are also invoked. If the * #GDBusConnection that is used for attempting to own the name * closes, then @name_lost_handler is invoked since it is no * longer possible for other processes to access the process. * * You cannot use g_bus_own_name() several times for the same name (unless * interleaved with calls to g_bus_unown_name()) - only the first call * will work. * * Another guarantee is that invocations of @name_acquired_handler * and @name_lost_handler are guaranteed to alternate; that * is, if @name_acquired_handler is invoked then you are * guaranteed that the next time one of the handlers is invoked, it * will be @name_lost_handler. The reverse is also true. * * If you plan on exporting objects (using e.g. * g_dbus_connection_register_object()), note that it is generally too late * to export the objects in @name_acquired_handler. Instead, you can do this * in @bus_acquired_handler since you are guaranteed that this will run * before @name is requested from the bus. * * This behavior makes it very simple to write applications that wants * to own names and export objects, see <xref linkend="gdbus-owning-names"/>. * Simply register objects to be exported in @bus_acquired_handler and * unregister the objects (if any) in @name_lost_handler. * * Returns: An identifier (never 0) that an be used with * g_bus_unown_name() to stop owning the name. * * Since: 2.26 */ guint g_bus_own_name (GBusType bus_type, const gchar *name, GBusNameOwnerFlags flags, GBusAcquiredCallback bus_acquired_handler, GBusNameAcquiredCallback name_acquired_handler, GBusNameLostCallback name_lost_handler, gpointer user_data, GDestroyNotify user_data_free_func) { Client *client; g_return_val_if_fail (g_dbus_is_name (name) && !g_dbus_is_unique_name (name), 0); G_LOCK (lock); client = g_new0 (Client, 1); client->ref_count = 1; client->id = next_global_id++; /* TODO: uh oh, handle overflow */ client->name = g_strdup (name); client->flags = flags; client->bus_acquired_handler = bus_acquired_handler; client->name_acquired_handler = name_acquired_handler; client->name_lost_handler = name_lost_handler; client->user_data = user_data; client->user_data_free_func = user_data_free_func; client->main_context = g_main_context_get_thread_default (); if (client->main_context != NULL) g_main_context_ref (client->main_context); if (map_id_to_client == NULL) { map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal); } g_hash_table_insert (map_id_to_client, GUINT_TO_POINTER (client->id), client); g_bus_get (bus_type, NULL, connection_get_cb, client_ref (client)); G_UNLOCK (lock); return client->id; }
DbusInput * pp_dbusinput_new (ClutterStage *stage) { DbusInput *self = g_slice_new0 (DbusInput); self->stage = stage; self->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_bus_own_name (G_BUS_TYPE_SESSION, PP_DBUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, NULL, NULL, NULL, NULL, NULL); g_bus_get (G_BUS_TYPE_SESSION, NULL, on_bus_acquired, self); return self; }
/** * g_bus_watch_name: * @bus_type: The type of bus to watch a name on. * @name: The name (well-known or unique) to watch. * @flags: Flags from the #GBusNameWatcherFlags enumeration. * @name_appeared_handler: (nullable): Handler to invoke when @name is known to exist or %NULL. * @name_vanished_handler: (nullable): Handler to invoke when @name is known to not exist or %NULL. * @user_data: User data to pass to handlers. * @user_data_free_func: (nullable): Function for freeing @user_data or %NULL. * * Starts watching @name on the bus specified by @bus_type and calls * @name_appeared_handler and @name_vanished_handler when the name is * known to have a owner respectively known to lose its * owner. Callbacks will be invoked in the * [thread-default main context][g-main-context-push-thread-default] * of the thread you are calling this function from. * * You are guaranteed that one of the handlers will be invoked after * calling this function. When you are done watching the name, just * call g_bus_unwatch_name() with the watcher id this function * returns. * * If the name vanishes or appears (for example the application owning * the name could restart), the handlers are also invoked. If the * #GDBusConnection that is used for watching the name disconnects, then * @name_vanished_handler is invoked since it is no longer * possible to access the name. * * Another guarantee is that invocations of @name_appeared_handler * and @name_vanished_handler are guaranteed to alternate; that * is, if @name_appeared_handler is invoked then you are * guaranteed that the next time one of the handlers is invoked, it * will be @name_vanished_handler. The reverse is also true. * * This behavior makes it very simple to write applications that want * to take action when a certain [name exists][gdbus-watching-names]. * Basically, the application should create object proxies in * @name_appeared_handler and destroy them again (if any) in * @name_vanished_handler. * * Returns: An identifier (never 0) that an be used with * g_bus_unwatch_name() to stop watching the name. * * Since: 2.26 */ guint g_bus_watch_name (GBusType bus_type, const gchar *name, GBusNameWatcherFlags flags, GBusNameAppearedCallback name_appeared_handler, GBusNameVanishedCallback name_vanished_handler, gpointer user_data, GDestroyNotify user_data_free_func) { Client *client; g_return_val_if_fail (g_dbus_is_name (name), 0); G_LOCK (lock); client = g_new0 (Client, 1); client->ref_count = 1; client->id = g_atomic_int_add (&next_global_id, 1); /* TODO: uh oh, handle overflow */ client->name = g_strdup (name); client->flags = flags; client->name_appeared_handler = name_appeared_handler; client->name_vanished_handler = name_vanished_handler; client->user_data = user_data; client->user_data_free_func = user_data_free_func; client->main_context = g_main_context_ref_thread_default (); if (map_id_to_client == NULL) { map_id_to_client = g_hash_table_new (g_direct_hash, g_direct_equal); } g_hash_table_insert (map_id_to_client, GUINT_TO_POINTER (client->id), client); g_bus_get (bus_type, NULL, connection_get_cb, client_ref (client)); G_UNLOCK (lock); return client->id; }
int main (int argc, char **argv) { GError *error = NULL; GOptionContext *context; setlocale (LC_ALL, ""); textdomain (GETTEXT_PACKAGE); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); g_set_application_name ("GeoClue Agent"); notify_init (_("GeoClue")); context = g_option_context_new ("- Geoclue Agent service"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_critical ("option parsing failed: %s\n", error->message); exit (-1); } if (version) { g_print ("%s\n", PACKAGE_VERSION); exit (0); } g_bus_get (G_BUS_TYPE_SYSTEM, NULL, on_get_bus_ready, NULL); main_loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (main_loop); if (agent != NULL); g_object_unref (agent); g_main_loop_unref (main_loop); return 0; }
static void cc_sharing_panel_setup_label_with_hostname (CcSharingPanel *self, GtkWidget *label) { GtkWidget *menu; GtkWidget *menu_item; GetHostNameData *get_hostname_data; /* create the menu */ menu = gtk_menu_new (); menu_item = gtk_menu_item_new_with_label (_("Copy")); gtk_widget_show (menu_item); g_signal_connect (menu_item, "activate", G_CALLBACK (copy_uri_to_clipboard), menu); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menu_item); /* show the menu when the link is activated */ g_signal_connect (label, "activate-link", G_CALLBACK (cc_sharing_panel_label_activate_link), menu); /* destroy the menu when the label is destroyed */ g_signal_connect_swapped (label, "destroy", G_CALLBACK (gtk_widget_destroy), menu); /* set the hostname */ get_hostname_data = g_new (GetHostNameData, 1); get_hostname_data->panel = self; get_hostname_data->label = label; g_bus_get (G_BUS_TYPE_SYSTEM, NULL, (GAsyncReadyCallback) cc_sharing_panel_bus_ready, get_hostname_data); }
NMBluezDevice * nm_bluez_device_new (const char *path, NMConnectionProvider *provider, int bluez_version) { NMBluezDevice *self; NMBluezDevicePrivate *priv; const char *interface_name = NULL; g_return_val_if_fail (path != NULL, NULL); g_return_val_if_fail (provider != NULL, NULL); g_return_val_if_fail (bluez_version == 4 || bluez_version == 5, NULL); self = (NMBluezDevice *) g_object_new (NM_TYPE_BLUEZ_DEVICE, NM_BLUEZ_DEVICE_PATH, path, NULL); if (!self) return NULL; nm_log_dbg (LOGD_BT, "bluez[%s] create NMBluezDevice", path); priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self); priv->bluez_version = bluez_version; priv->provider = provider; g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_ADDED, G_CALLBACK (cp_connection_added), self); g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_REMOVED, G_CALLBACK (cp_connection_removed), self); g_signal_connect (priv->provider, NM_CP_SIGNAL_CONNECTION_UPDATED, G_CALLBACK (cp_connection_updated), self); g_bus_get (G_BUS_TYPE_SYSTEM, NULL, (GAsyncReadyCallback) on_bus_acquired, g_object_ref (self)); switch (priv->bluez_version) { case 4: interface_name = BLUEZ4_DEVICE_INTERFACE; break; case 5: interface_name = BLUEZ5_DEVICE_INTERFACE; break; } g_dbus_proxy_new_for_bus (G_BUS_TYPE_SYSTEM, G_DBUS_PROXY_FLAGS_NONE, NULL, BLUEZ_SERVICE, priv->path, interface_name, NULL, (GAsyncReadyCallback) on_proxy_acquired, g_object_ref (self)); return self; }