static void impl_activate(PeasActivatable *activatable) { XmrMprisPlugin *plugin; GError *error = NULL; GDBusInterfaceInfo *ifaceinfo; plugin = XMR_MPRIS_PLUGIN(activatable); g_object_get(plugin, "object", &plugin->window, NULL); g_object_get(plugin->window, "player", &plugin->player, NULL); g_signal_connect(plugin->window, "track-changed", G_CALLBACK(track_changed), plugin); g_signal_connect(plugin->player, "tick", G_CALLBACK(player_tick), plugin); g_signal_connect(plugin->player, "state-changed", G_CALLBACK(player_state_changed), plugin); plugin->connection = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error); if (error != NULL) { xmr_debug("Unable to connect to D-Bus session bus: %s", error->message); return ; } /* parse introspection data */ plugin->node_info = g_dbus_node_info_new_for_xml(mpris_introspection_xml, &error); if (error != NULL) { xmr_debug("Unable to read MPRIS interface specificiation: %s", error->message); return; } /* register root interface */ ifaceinfo = g_dbus_node_info_lookup_interface (plugin->node_info, MPRIS_ROOT_INTERFACE); plugin->root_id = g_dbus_connection_register_object(plugin->connection, MPRIS_OBJECT_NAME, ifaceinfo, &root_vtable, plugin, NULL, &error); if (error != NULL) { xmr_debug("unable to register MPRIS root interface: %s", error->message); g_error_free (error); } /* register player interface */ ifaceinfo = g_dbus_node_info_lookup_interface(plugin->node_info, MPRIS_PLAYER_INTERFACE); plugin->player_id = g_dbus_connection_register_object(plugin->connection, MPRIS_OBJECT_NAME, ifaceinfo, &player_vtable, plugin, NULL, &error); if (error != NULL) { xmr_debug("Unable to register MPRIS player interface: %s", error->message); g_error_free (error); } plugin->name_own_id = g_bus_own_name(G_BUS_TYPE_SESSION, MPRIS_BUS_NAME_PREFIX ".xmradio", G_BUS_NAME_OWNER_FLAGS_NONE, NULL, (GBusNameAcquiredCallback) name_acquired_cb, (GBusNameLostCallback) name_lost_cb, g_object_ref(plugin), g_object_unref); }
int main (int argc, char *argv[]) { GOptionContext *opt_context; GError *error; GMainLoop *loop; GDBusServer *server; gchar *guid; GDBusServerFlags server_flags; gchar *action; gchar *message; gint ret; introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (introspection_data != NULL); users = g_array_new (FALSE,TRUE,sizeof (GUser)); guid = g_dbus_generate_guid (); server_flags = G_DBUS_SERVER_FLAGS_NONE; ret = 1; g_type_init (); error = NULL; opt_context = g_option_context_new ("ksr-chat-server() usage:"); g_option_context_set_summary (opt_context, "To start a local server located under tcp:host=0.0.0.0, use:\n" " \"ksr-chat-server -a tcp:host=0.0.0.0\""); 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\n", error->message); goto out; } if (!input_is_valid()) goto out; server = g_dbus_server_new_sync (opt_address, server_flags, guid, NULL, /* GDBusAuthObserver */ NULL, /* GCancellable */ &error); g_dbus_server_start (server); g_free (guid); if (server == NULL) { g_printerr ("Error creating server at address %s: %s\n", opt_address, error->message); g_error_free (error); goto out; } g_print ("Server is listening at: %s\n", g_dbus_server_get_client_address (server)); g_signal_connect (server, "new-connection", G_CALLBACK (on_new_connection), NULL); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_main_loop_unref (loop); ret = 0; out: return ret; }
static gboolean tracker_controller_dbus_start (TrackerController *controller, GError **error) { TrackerControllerPrivate *priv; GError *err = NULL; GDBusInterfaceVTable interface_vtable = { handle_method_call, NULL, NULL }; priv = controller->priv; priv->connection = tracker_sparql_connection_get (NULL, &err); if (!priv->connection) { g_propagate_error (error, err); return FALSE; } priv->d_connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &err); if (!priv->d_connection) { g_propagate_error (error, err); return FALSE; } priv->introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &err); if (!priv->introspection_data) { g_propagate_error (error, err); return FALSE; } g_message ("Registering D-Bus object..."); g_message (" Path:'" TRACKER_WRITEBACK_PATH "'"); g_message (" Object Type:'%s'", G_OBJECT_TYPE_NAME (controller)); priv->registration_id = g_dbus_connection_register_object (priv->d_connection, TRACKER_WRITEBACK_PATH, priv->introspection_data->interfaces[0], &interface_vtable, controller, NULL, &err); if (err) { g_critical ("Could not register the D-Bus object "TRACKER_WRITEBACK_PATH", %s", err ? err->message : "no error given."); g_propagate_error (error, err); return FALSE; } priv->bus_name_id = g_bus_own_name_on_connection (priv->d_connection, TRACKER_WRITEBACK_SERVICE, G_BUS_NAME_OWNER_FLAGS_NONE, bus_name_acquired_cb, bus_name_vanished_cb, controller, NULL); if (err) { g_critical ("Could not own the D-Bus name "TRACKER_WRITEBACK_SERVICE", %s", err ? err->message : "no error given."); g_propagate_error (error, err); return FALSE; } return TRUE; }
int main (int argc, char **argv) { GError *error; GOptionContext *opt_context; GMainLoop *main_loop; gint ret; guint name_owner_id; GIOChannel *stdin_channel; ret = 1; opt_context = NULL; name_owner_id = 0; stdin_channel = NULL; introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (introspection_data != NULL); opt_context = g_option_context_new ("gnome-shell calendar server"); g_option_context_add_main_entries (opt_context, opt_entries, NULL); error = NULL; if (!g_option_context_parse (opt_context, &argc, &argv, &error)) { g_printerr ("Error parsing options: %s", error->message); g_error_free (error); goto out; } main_loop = g_main_loop_new (NULL, FALSE); stdin_channel = g_io_channel_unix_new (STDIN_FILENO); g_io_add_watch_full (stdin_channel, G_PRIORITY_DEFAULT, G_IO_HUP, stdin_channel_io_func, g_main_loop_ref (main_loop), (GDestroyNotify) g_main_loop_unref); name_owner_id = g_bus_own_name (G_BUS_TYPE_SESSION, BUS_NAME, 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, g_main_loop_ref (main_loop), (GDestroyNotify) g_main_loop_unref); g_main_loop_run (main_loop); g_main_loop_unref (main_loop); ret = 0; out: if (stdin_channel != NULL) g_io_channel_unref (stdin_channel); if (_global_app != NULL) app_free (_global_app); if (name_owner_id != 0) g_bus_unown_name (name_owner_id); if (opt_context != NULL) g_option_context_free (opt_context); return ret; }
static void ev_application_init(EvApplication* ev_application) { GError* error = NULL; userdir = g_getenv("MATE22_USER_DIR"); if (userdir) { ev_application->dot_dir = g_build_filename(userdir, "atril", NULL); } else { ev_application->dot_dir = g_build_filename(g_get_user_config_dir(), "atril", NULL); } #ifdef G_OS_WIN32 { gchar *dir; dir = g_win32_get_package_installation_directory_of_module (NULL); ev_application->data_dir = g_build_filename (dir, "share", "atril", NULL); g_free (dir); } #else ev_application->data_dir = g_strdup (ATRILDATADIR); #endif ev_application_init_session (ev_application); ev_application_accel_map_load (ev_application); #ifdef ENABLE_DBUS ev_application->connection = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, &error); if (ev_application->connection != NULL) { introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, NULL); g_assert (introspection_data != NULL); ev_application->registration_id = g_dbus_connection_register_object (ev_application->connection, APPLICATION_DBUS_OBJECT_PATH, introspection_data->interfaces[0], &interface_vtable, ev_application, NULL, &error); if (ev_application->registration_id == 0) { g_printerr ("Failed to register bus object: %s\n", error->message); g_error_free (error); } } else { g_printerr ("Failed to get bus connection: %s\n", error->message); g_error_free (error); } ev_application->keys = ev_media_player_keys_new (); #endif /* ENABLE_DBUS */ ev_application->scr_saver = totem_scrsaver_new (); g_object_set (ev_application->scr_saver, "reason", _("Running in presentation mode"), NULL); }
int main(int argc, char *argv[]) { GDBusConnection *connection; GError *error = NULL; GDBusProxy *proxy; gchar *name; gchar *object_path; gchar *interface_name; GDBusProxyFlags flags; g_type_init(); connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); if (connection == NULL) { if (error != NULL) { g_printerr("get connection error: %s\n", error->message); g_error_free(error); } else { g_printerr("get connection error: unknown error\n"); } return -1; } else { g_print("get connection success\n"); } name = "net.connman"; object_path = "/"; interface_name = "net.connman.Manager"; #if 0 GDBusProxy *g_dbus_proxy_new_sync (GDBusConnection *connection, GDBusProxyFlags flags, GDBusInterfaceInfo *info, const gchar *name, const gchar *object_path, const gchar *interface_name, GCancellable *cancellable, GError **error); #endif proxy = g_dbus_proxy_new_sync(connection, G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, NULL, name, object_path, interface_name, NULL, &error); if (proxy == NULL) { if (error != NULL) { g_printerr("get proxy failed: %s\n", error->message); } else { g_printerr("get proxy failed: %s\n", "unknown error"); } } g_print("get proxy success\n"); flags = g_dbus_proxy_get_flags(proxy); g_print("flags: %d\n", (int)flags); proxy_flags_print(flags); /** * get cached property */ GVariant *val; #if 0 GDBusNodeInfo *introspection_data; GDBusInterfaceInfo *info; introspection_data = g_dbus_node_info_new_for_xml(connman_manager_xml, NULL); if (introspection_data == NULL) { g_printerr("get introspection_data failed\n"); return -1; } info = introspection_data->interfaces[0]; g_dbus_proxy_set_interface_info(proxy, info); #endif //GVariant *g_dbus_proxy_get_cached_property (GDBusProxy *proxy, //const gchar *property_name); val = g_dbus_proxy_get_cached_property(proxy, "ActiveProfile"); if (val == NULL) { g_print("get val failed\n"); return -1; } g_print("get val success\n"); return 0; }
gboolean gnome_media_keys_will_be_useful() { GDBusConnection *bus = NULL; GVariant *response = NULL; GDBusNodeInfo *node_info = NULL; GDBusInterfaceInfo *interface_info; GDBusMethodInfo *method_info; const gchar *xml_data; gboolean result = TRUE; bus = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, NULL); if (!bus) { result = FALSE; goto out; } response = g_dbus_connection_call_sync(bus, "org.gnome.SettingsDaemon", "/org/gnome/SettingsDaemon/MediaKeys", "org.freedesktop.DBus.Introspectable", "Introspect", NULL, G_VARIANT_TYPE ("(s)"), G_DBUS_CALL_FLAGS_NO_AUTO_START, -1, NULL, NULL); if (!response) { result = FALSE; goto out; } g_variant_get(response, "(&s)", &xml_data); node_info = g_dbus_node_info_new_for_xml(xml_data, NULL); if (!node_info) { result = FALSE; goto out; } interface_info = g_dbus_node_info_lookup_interface(node_info, "org.gnome.SettingsDaemon.MediaKeys"); if (!interface_info) { result = FALSE; goto out; } method_info = g_dbus_interface_info_lookup_method(interface_info, "GrabMediaPlayerKeys"); if (!method_info) { result = FALSE; goto out; } out: if (bus) g_object_unref(bus); if (response) g_variant_unref(response); if (node_info) g_dbus_node_info_unref(node_info); return result; }
int main (int argc, char **argv) { ServiceData svc = {0,}; GError *error = NULL; const char *address = NULL; char *guid; #ifdef ENABLE_NLS /* initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif g_type_init (); gst_init (NULL, NULL); g_set_prgname ("rhythmbox-metadata"); if (argv[1] != NULL && strcmp(argv[1], "--debug") == 0) { argv++; rb_debug_init (TRUE); } else if (argv[1] != NULL && strcmp (argv[1], "--debug-match") == 0) { rb_debug_init_match (argv[2]); argv += 2; } else { rb_debug_init (FALSE); } /* bug report modes */ if (argv[1] != NULL && strcmp(argv[1], "--load") == 0) { return test_load (argv[2]); } if (argv[1] != NULL && strcmp(argv[1], "--saveable-types") == 0) { return test_saveable_types (); } if (argv[1] != NULL && strcmp (argv[1], "--external") == 0) { argv++; svc.external = TRUE; } if (argv[1] == NULL) { address = "unix:tmpdir=/tmp"; } else { address = argv[1]; } rb_debug ("initializing metadata service; pid = %d; address = %s", getpid (), address); svc.metadata = rb_metadata_new (); svc.loop = g_main_loop_new (NULL, TRUE); /* create the server */ guid = g_dbus_generate_guid (); svc.server = g_dbus_server_new_sync (address, G_DBUS_SERVER_FLAGS_NONE, guid, NULL, NULL, &error); g_free (guid); if (error != NULL) { g_warning ("D-Bus server init failed: %s", error->message); return -1; } /* set up interface info */ svc.node_info = g_dbus_node_info_new_for_xml (rb_metadata_iface_xml, &error); if (error != NULL) { g_warning ("D-Bus server init failed: %s", error->message); return -1; } g_signal_connect (svc.server, "new-connection", G_CALLBACK (new_connection_cb), &svc); g_dbus_server_start (svc.server); /* write the server address back to the parent process */ { const char *addr; addr = g_dbus_server_get_client_address (svc.server); rb_debug ("D-BUS server listening on address %s", addr); printf ("%s\n", addr); fflush (stdout); } /* run main loop until we get bored */ if (!svc.external) g_timeout_add_seconds (ATTENTION_SPAN / 2, (GSourceFunc) electromagnetic_shotgun, &svc); g_main_loop_run (svc.loop); if (svc.connection) { g_dbus_connection_close_sync (svc.connection, NULL, NULL); g_object_unref (svc.connection); } g_object_unref (svc.metadata); g_main_loop_unref (svc.loop); g_dbus_server_stop (svc.server); g_object_unref (svc.server); gst_deinit (); return 0; }
int main (int argc, char *argv[]) { gint ret; gboolean opt_server; gchar *opt_address; GOptionContext *opt_context; gboolean opt_allow_anonymous; GError *error; GOptionEntry opt_entries[] = { { "server", 's', 0, G_OPTION_ARG_NONE, &opt_server, "Start a server instead of a client", NULL }, { "address", 'a', 0, G_OPTION_ARG_STRING, &opt_address, "D-Bus address to use", NULL }, { "allow-anonymous", 'n', 0, G_OPTION_ARG_NONE, &opt_allow_anonymous, "Allow anonymous authentication", NULL }, { NULL} }; ret = 1; g_type_init (); opt_address = NULL; opt_server = FALSE; opt_allow_anonymous = FALSE; opt_context = g_option_context_new ("peer-to-peer example"); error = NULL; 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\n", error->message); g_error_free (error); goto out; } if (opt_address == NULL) { g_printerr ("Incorrect usage, try --help.\n"); goto out; } if (!opt_server && opt_allow_anonymous) { g_printerr ("The --allow-anonymous option only makes sense when used with --server.\n"); goto out; } /* 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); if (opt_server) { GDBusServer *server; gchar *guid; GMainLoop *loop; GDBusServerFlags server_flags; guid = g_dbus_generate_guid (); server_flags = G_DBUS_SERVER_FLAGS_NONE; if (opt_allow_anonymous) server_flags |= G_DBUS_SERVER_FLAGS_AUTHENTICATION_ALLOW_ANONYMOUS; error = NULL; server = g_dbus_server_new_sync (opt_address, server_flags, guid, NULL, /* GDBusAuthObserver */ NULL, /* GCancellable */ &error); g_dbus_server_start (server); g_free (guid); if (server == NULL) { g_printerr ("Error creating server at address %s: %s\n", opt_address, error->message); g_error_free (error); goto out; } g_print ("Server is listening at: %s\n", g_dbus_server_get_client_address (server)); g_signal_connect (server, "new-connection", G_CALLBACK (on_new_connection), NULL); loop = g_main_loop_new (NULL, FALSE); g_main_loop_run (loop); g_object_unref (server); g_main_loop_unref (loop); } else { GDBusConnection *connection; const gchar *greeting_response; GVariant *value; gchar *greeting; error = NULL; connection = g_dbus_connection_new_for_address_sync (opt_address, G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT, NULL, /* GDBusAuthObserver */ NULL, /* GCancellable */ &error); if (connection == NULL) { g_printerr ("Error connecting to D-Bus address %s: %s\n", opt_address, error->message); g_error_free (error); goto out; } g_print ("Connected.\n" "Negotiated capabilities: unix-fd-passing=%d\n", g_dbus_connection_get_capabilities (connection) & G_DBUS_CAPABILITY_FLAGS_UNIX_FD_PASSING); greeting = g_strdup_printf ("Hey, it's %" G_GUINT64_FORMAT " already!", (guint64) time (NULL)); value = g_dbus_connection_call_sync (connection, NULL, /* bus_name */ "/org/gtk/GDBus/TestObject", "org.gtk.GDBus.TestPeerInterface", "HelloWorld", g_variant_new ("(s)", greeting), G_VARIANT_TYPE ("(s)"), G_DBUS_CALL_FLAGS_NONE, -1, NULL, &error); if (value == NULL) { g_printerr ("Error invoking HelloWorld(): %s\n", error->message); g_error_free (error); goto out; } g_variant_get (value, "(&s)", &greeting_response); g_print ("Server said: %s\n", greeting_response); g_variant_unref (value); g_object_unref (connection); } g_dbus_node_info_unref (introspection_data); ret = 0; out: return ret; }
static void on_poke_introspected (GObject *source_object, GAsyncResult *result, gpointer user_data) { PokeContext *poke = user_data; CockpitFakeManager *self = poke->manager; GError *error = NULL; GDBusNodeInfo *node; gboolean expected; const gchar *xml; GVariant *retval; gchar *remote; retval = g_dbus_connection_call_finish (self->connection, result, &error); /* Bail fast if cancelled */ if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { poke_context_finish (self, poke); g_error_free (error); return; } if (retval) { g_variant_get (retval, "(&s)", &xml); node = g_dbus_node_info_new_for_xml (xml, &error); process_introspect_node (self, poke, node); g_dbus_node_info_unref (node); g_variant_unref (retval); } if (error) { /* * Note that many DBus implementations don't return errors when * an unknown object path is introspected. They just return empty * introspect data. GDBus is one of these. */ expected = FALSE; remote = g_dbus_error_get_remote_error (error); if (remote) { /* * DBus used to only have the UnknownMethod error. It didn't have * specific errors for UnknownObject and UnknownInterface. So we're * pretty liberal on what we treat as an expected error here. * * HACK: GDBus also doesn't understand the newer error codes :S * * https://bugzilla.gnome.org/show_bug.cgi?id=727900 */ expected = (g_str_equal (remote, "org.freedesktop.DBus.Error.UnknownMethod") || g_str_equal (remote, "org.freedesktop.DBus.Error.UnknownObject") || g_str_equal (remote, "org.freedesktop.DBus.Error.UnknownInterface")); g_free (remote); } if (!expected) { g_warning ("Couldn't look up introspection data on %s at %s: %s", self->bus_name, poke->object_path, error->message); } g_error_free (error); poke_remove_object_and_finish (self, poke); return; } }