int main(int argc, char *argv[]) { GMainLoop *loop; guint bus; loop = g_main_loop_new(NULL, FALSE); bus = g_bus_own_name(G_BUS_TYPE_SYSTEM, "org.freedesktop.login1", G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, on_name_acquired, on_name_lost, loop, NULL); /* create /run/systemd/seats, since that's how GDM checks whether logind is * running - see LOGIND_RUNNING() */ if (-1 == g_mkdir_with_parents("/run/systemd/seats", 0755)) goto cleanup; g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "entering the main loop"); g_main_loop_run(loop); g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "exited the main loop"); cleanup: signals_unsubscribe(); bus_close(); g_main_loop_unref(loop); g_bus_unown_name(bus); return 0; }
gint main (gint argc, gchar *argv[]) { GMainLoop *loop; cmdline cmd; cmd.argc = argc; cmd.argv = argv; guint id; loop = g_main_loop_new (NULL, FALSE); id = g_bus_own_name (DBUS_TYPE, dbus_name, G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | G_BUS_NAME_OWNER_FLAGS_REPLACE, on_bus_acquired, on_name_acquired, on_name_lost, &cmd, NULL); g_main_loop_run (loop); g_bus_unown_name (id); g_main_loop_unref (loop); return 0; }
int main (int argc, char *argv[]) { guint owner_id; GMainLoop *loop; g_type_init (); /* We are lazy here - we don't want to manually provide * the introspection data structures - so we just build * them from XML. */ introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (introspection_data != NULL); owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.gtk.GDBus.TestServer", G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_bus_unown_name (owner_id); g_dbus_node_info_unref (introspection_data); return 0; }
static void _on_bus_acquired ( GDBusConnection *connection, const gchar *name, gpointer user_data ) { g_debug(" on bus acquired ...\n"); lock_connection = connection; //register object GError *error = NULL; lock_service_reg_id = g_dbus_connection_register_object( connection, DBUS_PYSQL_PATH, interface_info, &interface_table, user_data, NULL, &error ); if ( error != NULL ) { g_critical ( "Unable to register object to the dbus: %s\n", error->message ); g_error_free(error); g_bus_unown_name(lock_service_owner_id); lock_service_owner_id = 0; retry_reg_timeout_id = g_timeout_add_seconds(1, _retry_registration, NULL ); return; } return; }
void dbus_tear_down(int owner_id) { if (introspection_data) g_dbus_node_info_unref(introspection_data); g_bus_unown_name(owner_id); }
void dt_dbus_destroy(const dt_dbus_t *dbus) { g_bus_unown_name(dbus->owner_id); g_dbus_node_info_unref(dbus->introspection_data); g_free((dt_dbus_t*)dbus); }
static void on_client_disappeared (const gchar *bus_name, gpointer user_data) { StorageDaemon *self = user_data; g_assert (self->num_clients > 0); self->num_clients--; if (self->num_clients > 0) { g_debug ("Client went away: %s", bus_name); } else { g_info ("Last client went away: %s", bus_name); /* When last client, force release of name */ if (!self->persist && self->name_owner_id) { g_bus_unown_name (self->name_owner_id); self->name_owner_id = 0; self->name_owned = FALSE; } } maybe_finished (self); }
static void free_orientation_data (SensorData *data) { guint i; if (data == NULL) return; if (data->name_id != 0) { g_bus_unown_name (data->name_id); data->name_id = 0; } for (i = 0; i < NUM_SENSOR_TYPES; i++) { if (driver_type_exists (data, i)) driver_close (DRIVER_FOR_TYPE(i)); g_clear_object (&DEVICE_FOR_TYPE(i)); g_clear_pointer (&data->clients[i], g_hash_table_unref); } g_clear_pointer (&data->introspection_data, g_dbus_node_info_unref); g_clear_object (&data->connection); g_clear_pointer (&data->loop, g_main_loop_unref); g_free (data); }
static void tracker_controller_dbus_stop (TrackerController *controller) { TrackerControllerPrivate *priv; priv = controller->priv; if (priv->registration_id != 0) { g_dbus_connection_unregister_object (priv->d_connection, priv->registration_id); } if (priv->bus_name_id != 0) { g_bus_unown_name (priv->bus_name_id); } if (priv->introspection_data) { g_dbus_node_info_unref (priv->introspection_data); } if (priv->d_connection) { g_object_unref (priv->d_connection); } if (priv->connection) { g_object_unref (priv->connection); } }
static void indicator_workrave_stop(IndicatorWorkrave *self) { IndicatorWorkravePrivate *priv = INDICATOR_WORKRAVE_GET_PRIVATE(self); if (priv->alive) { if (priv->timer != 0) { g_source_remove(priv->timer); priv->timer = 0; } if (priv->startup_timer != 0) { g_source_remove(priv->startup_timer); priv->startup_timer = 0; } if (priv->owner_id != 0) { g_bus_unown_name(priv->owner_id); priv->owner_id = 0; } workrave_timerbox_set_enabled(priv->timerbox, FALSE); workrave_timerbox_set_force_icon(priv->timerbox, FALSE); workrave_timerbox_update(priv->timerbox, priv->image); priv->alive = FALSE; } }
int main (int argc, char **argv) { GError *error; GOptionContext *opt_context = NULL; gint ret = 1; guint name_owner_id = 0; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); opt_context = g_option_context_new ("GNOME Online Accounts daemon"); g_option_context_add_main_entries (opt_context, opt_entries, NULL); error = NULL; if (!g_option_context_parse (opt_context, &argc, &argv, &error)) { g_critical ("Error parsing options: %s", error->message); g_error_free (error); goto out; } g_message ("goa-daemon version %s starting", PACKAGE_VERSION); loop = g_main_loop_new (NULL, FALSE); if (!opt_no_sigint) { g_unix_signal_add (SIGINT, on_sigint, NULL); } name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.gnome.OnlineAccounts", G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0), on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); g_debug ("Entering main event loop"); g_main_loop_run (loop); ret = 0; out: g_clear_object (&the_daemon); if (name_owner_id != 0) g_bus_unown_name (name_owner_id); g_clear_pointer (&loop, (GDestroyNotify) g_main_loop_unref); g_clear_pointer (&opt_context, (GDestroyNotify) g_option_context_free); g_message ("goa-daemon version %s exiting", PACKAGE_VERSION); return ret; }
int main (int argc, char **argv) { guint name_owner_id; g_type_init (); introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (introspection_data != NULL); ensure_autoquit_on (); loop = g_main_loop_new (NULL, FALSE); name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, BUS_NAME, 0, on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); g_main_loop_run (loop); if (name_owner_id != 0) g_bus_unown_name (name_owner_id); if (loop != NULL) g_main_loop_unref (loop); return 0; }
int main(int argc, char * argv[]) { guint owner_id; GMainLoop *loop; introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (introspection_data != NULL); printf("g_bus_own_name\n"); owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, GSTSWITCH_BUS_NAME, G_BUS_NAME_OWNER_FLAGS_NONE, &bus_acquired_cb, &bus_name_acquired_cb, &bus_name_lost_cb, /*user_data*/ NULL, /*user_data_free_func*/ NULL); printf("g_bus_own_name done, entering mainloop\n"); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_bus_unown_name (owner_id); g_dbus_node_info_unref (introspection_data); return 0; }
int main (int argc, char *argv[]) { guint owner_id; GMainLoop *loop; GBusNameOwnerFlags flags; gboolean opt_replace; gboolean opt_allow_replacement; gchar *opt_name; GOptionContext *opt_context; GError *error; GOptionEntry opt_entries[] = { { "replace", 'r', 0, G_OPTION_ARG_NONE, &opt_replace, "Replace existing name if possible", NULL }, { "allow-replacement", 'a', 0, G_OPTION_ARG_NONE, &opt_allow_replacement, "Allow replacement", NULL }, { "name", 'n', 0, G_OPTION_ARG_STRING, &opt_name, "Name to acquire", NULL }, { NULL} }; g_type_init (); error = NULL; opt_name = NULL; opt_replace = FALSE; opt_allow_replacement = FALSE; opt_context = g_option_context_new ("g_bus_own_name() example"); g_option_context_add_main_entries (opt_context, opt_entries, NULL); if (!g_option_context_parse (opt_context, &argc, &argv, &error)) { g_printerr ("Error parsing options: %s", error->message); return 1; } if (opt_name == NULL) { g_printerr ("Incorrect usage, try --help.\n"); return 1; } flags = G_BUS_NAME_OWNER_FLAGS_NONE; if (opt_replace) flags |= G_BUS_NAME_OWNER_FLAGS_REPLACE; if (opt_allow_replacement) flags |= G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT; owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, opt_name, flags, on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_bus_unown_name (owner_id); return 0; }
gint main (gint argc, const gchar * const argv[]) { EmerDaemon *daemon = make_daemon (argc, argv); if (daemon == NULL) return EXIT_FAILURE; GMainLoop *main_loop = g_main_loop_new (NULL, TRUE); // Shut down on any of these signals. g_unix_signal_add (SIGHUP, (GSourceFunc) quit_main_loop, main_loop); g_unix_signal_add (SIGINT, (GSourceFunc) quit_main_loop, main_loop); g_unix_signal_add (SIGTERM, (GSourceFunc) quit_main_loop, main_loop); g_unix_signal_add (SIGUSR1, (GSourceFunc) quit_main_loop, main_loop); g_unix_signal_add (SIGUSR2, (GSourceFunc) quit_main_loop, main_loop); guint name_id = g_bus_own_name (G_BUS_TYPE_SYSTEM, "com.endlessm.Metrics", G_BUS_NAME_OWNER_FLAGS_NONE, on_bus_acquired, NULL /* name_acquired_callback */, on_name_lost, daemon, NULL /* user data free func */); g_main_loop_run (main_loop); g_object_unref (daemon); g_bus_unown_name (name_id); g_main_loop_unref (main_loop); return EXIT_SUCCESS; }
int main (int argc, char *argv[]) { GMainLoop *loop = NULL; guint name_owner_id = 0; GduSdMonitor *monitor = NULL; notify_init ("test-gdusdplugin"); loop = g_main_loop_new (NULL, FALSE); /* The reason for claiming a unique name is so it's easier to test * code changes - it helps ensure that only one instance of * GduSdMonitor is running at any one time. See also * gdusdplugin.c:impl_activate(). */ name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.gnome.Disks.NotificationMonitor", G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | G_BUS_NAME_OWNER_FLAGS_REPLACE, NULL, /* bus_acquired_handler */ name_acquired_handler, name_lost_handler, &monitor, NULL); /* GDestroyNotify */ g_main_loop_run (loop); g_bus_unown_name (name_owner_id); g_main_loop_unref (loop); g_object_unref (monitor); return 0; }
/* Builds up the core objects and puts us spinning into a main loop. */ int main (int argc, char ** argv) { guint nameownership = g_bus_own_name(G_BUS_TYPE_SESSION, INDICATOR_APPLICATION_DBUS_ADDR, G_BUS_NAME_OWNER_FLAGS_NONE, bus_acquired, name_acquired, name_lost, NULL, NULL); /* Building and executing our main loop */ mainloop = g_main_loop_new(NULL, FALSE); g_main_loop_run(mainloop); g_debug("Finishing Main Loop"); g_bus_unown_name(nameownership); /* Unref'ing all the objects */ g_main_loop_unref(mainloop); g_object_unref(G_OBJECT(watcher)); g_object_unref(G_OBJECT(appstore)); return 0; }
gint main(gint argc, gchar *argv[]) { GMainLoop *loop; ObjectSkeleton *newobject; newobject = object_skeleton_new(object_name); guint id; loop = g_main_loop_new(NULL, FALSE); id = g_bus_own_name(DBUS_TYPE, dbus_name, G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | G_BUS_NAME_OWNER_FLAGS_REPLACE, on_bus_acquired, on_name_acquired, on_name_lost, newobject, NULL); g_main_loop_run(loop); g_bus_unown_name(id); g_object_unref(newobject); g_main_loop_unref(loop); return 0; }
/***************************************************************************** * neardal_agent_stop_owning_dbus_name: Stops owning a dbus name ****************************************************************************/ void neardal_agent_stop_owning_dbus_name(void) { NEARDAL_TRACEIN(); if (neardalMgr.OwnerId > 0) g_bus_unown_name (neardalMgr.OwnerId); neardalMgr.OwnerId = 0; }
static void prv_connector_disconnect(void) { if (g_context.owner_id) { g_bus_unown_name(g_context.owner_id); g_context.owner_id = 0; } }
/* Destroy a service object */ void service_free(struct service *service) { START_FUNC g_bus_unown_name(service->owner_id); g_dbus_node_info_unref(service->introspection_data); g_free(service); END_FUNC }
static gpointer infinoted_plugin_dbus_thread_func(gpointer plugin_info) { InfinotedPluginDbus* plugin; plugin = (InfinotedPluginDbus*)plugin_info; g_mutex_lock(&plugin->mutex); if(plugin->thread == NULL) { g_mutex_unlock(&plugin->mutex); return NULL; } plugin->context = g_main_context_new(); g_main_context_push_thread_default(plugin->context); plugin->loop = g_main_loop_new(plugin->context, FALSE); g_mutex_unlock(&plugin->mutex); plugin->id = g_bus_own_name( plugin->bus_type, plugin->bus_name, G_BUS_NAME_OWNER_FLAGS_NONE, infinoted_plugin_dbus_bus_acquired_func, infinoted_plugin_dbus_name_acquired_func, infinoted_plugin_dbus_name_lost_func, plugin, NULL ); g_main_loop_run(plugin->loop); g_bus_unown_name(plugin->id); plugin->id = 0; /* TODO: This is an enormous hack. Apparently, g_bus_own_name starts some * thread internally, and that thread is not stopped by g_bus_unown_name. * When the plugin is then unloaded, it leads to a crash because the thread * is still doing some cleanup work. I don't see a possibility for us here * to wait for that thread to finish, so we simply wait 100ms. * * Waiting with quitting the main loop until either bus_acquired or * name_lost are called does not help. * * A solution might be to not use the g_bus_own_name and g_bus_unown_name * APIs, but some more low-level APIs. */ g_usleep(100000); g_mutex_lock(&plugin->mutex); g_main_loop_unref(plugin->loop); plugin->loop = NULL; g_main_context_unref(plugin->context); plugin->context = NULL; g_mutex_unlock(&plugin->mutex); return NULL; }
gboolean close_dlna (SnappyMP * mp) { g_bus_unown_name (mp->owner_id); g_dbus_node_info_unref (introspection_data); g_free (mp->name); return TRUE; }
static void evd_dbus_agent_free_name_owner_data (gpointer data) { NameOwnerData *owner_data = (NameOwnerData *) data; g_bus_unown_name (owner_data->owner_id); g_slice_free (NameOwnerData, owner_data); }
int main (int argc, char *argv[]) { guint owner_id; g_autoptr(GError) error = NULL; GDBusConnection *session_bus; GOptionContext *context; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); /* Avoid even loading gvfs to avoid accidental confusion */ g_setenv ("GIO_USE_VFS", "local", TRUE); gtk_init (&argc, &argv); context = g_option_context_new ("- file chooser portal"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s\n", error->message); return 1; } if (opt_verbose) g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG, message_handler, NULL); g_set_prgname (argv[0]); loop = g_main_loop_new (NULL, FALSE); outstanding_handles = g_hash_table_new (g_str_hash, g_str_equal); session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (session_bus == NULL) { g_printerr ("No session bus: %s\n", error->message); return 2; } owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.freedesktop.impl.portal.desktop.gtk", G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0), on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); g_main_loop_run (loop); g_bus_unown_name (owner_id); return 0; }
void korva_server_run (KorvaServer *self) { g_return_if_fail (self != NULL); g_return_if_fail (KORVA_IS_SERVER (self)); g_main_loop_run (self->priv->loop); g_bus_unown_name (self->priv->bus_id); }
int main (int argc, char **argv) { guint owner_id; GMainLoop *loop; GOptionContext *context; g_autoptr(GError) error = NULL; setlocale (LC_ALL, ""); g_setenv ("GIO_USE_VFS", "local", TRUE); g_set_prgname (argv[0]); flatpak_migrate_from_xdg_app (); g_set_printerr_handler (printerr_handler); context = g_option_context_new ("- permission store"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Option parsing failed: %s", error->message); return 1; } if (opt_version) { g_print ("%s\n", PACKAGE_STRING); exit (EXIT_SUCCESS); } if (opt_verbose) g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL); g_set_prgname (argv[0]); owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.freedesktop.impl.portal.PermissionStore", G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0), on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_bus_unown_name (owner_id); return 0; }
int main (int argc, char *argv[]) { guint owner_id; g_autoptr(GError) error = NULL; GDBusConnection *session_bus; GOptionContext *context; setlocale (LC_ALL, ""); /* Avoid even loading gvfs to avoid accidental confusion */ g_setenv ("GIO_USE_VFS", "local", TRUE); g_set_printerr_handler (printerr_handler); context = g_option_context_new ("- desktop portal"); g_option_context_add_main_entries (context, entries, NULL); if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("Option parsing failed: %s", error->message); return 1; } if (opt_verbose) g_log_set_handler (G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, message_handler, NULL); g_set_prgname (argv[0]); load_installed_portals (); loop = g_main_loop_new (NULL, FALSE); session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (session_bus == NULL) { g_printerr ("No session bus: %s", error->message); return 2; } owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, "org.freedesktop.portal.Desktop", G_BUS_NAME_OWNER_FLAGS_ALLOW_REPLACEMENT | (opt_replace ? G_BUS_NAME_OWNER_FLAGS_REPLACE : 0), on_bus_acquired, on_name_acquired, on_name_lost, NULL, NULL); g_main_loop_run (loop); g_bus_unown_name (owner_id); return 0; }
static void fr_application_finalize (GObject *object) { FrApplication *self = FR_APPLICATION (object); if (self->introspection_data != NULL) g_dbus_node_info_unref (self->introspection_data); if (self->owner_id != 0) g_bus_unown_name (self->owner_id); G_OBJECT_CLASS (fr_application_parent_class)->finalize (object); }
static gboolean shutdown_handler(GtkApplication *app, gpointer data) { gmpv_mpris *inst = data; g_signal_handler_disconnect(app, inst->shutdown_sig_id); unregister(inst); g_bus_unown_name(inst->name_id); g_free(inst); return FALSE; }