static gboolean skype_connect() { GError *error = NULL; DBusObjectPathVTable vtable; //Initialise threading dbus_threads_init_default(); if (connection == NULL) { connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL && error != NULL) { skype_debug_info("skype_dbus", "Error: %s\n", error->message); g_error_free(error); return FALSE; } } if (proxy == NULL) { proxy = dbus_g_proxy_new_for_name_owner (connection, "com.Skype.API", "/com/Skype", "com.Skype.API", &error); if (proxy == NULL && error != NULL) { skype_debug_warning("skype_dbus", "%s\n", error->message); g_error_free(error); return FALSE; } g_signal_connect(G_OBJECT(proxy), "destroy", G_CALLBACK(skype_destroy_handler), NULL); #ifdef DBUS_MAJOR_VERSION dbus_g_proxy_set_default_timeout(proxy, 3000); #endif vtable.message_function = &skype_notify_handler; dbus_connection_register_object_path(dbus_g_connection_get_connection(connection), "/com/Skype/Client", &vtable, NULL); } return TRUE; }
/** * main: **/ int main (int argc, char *argv[]) { GOptionContext *context; gboolean ret; GError *error = NULL; gchar **files = NULL; gchar *tmp; gchar *current_dir; guint i; DBusGConnection *connection; DBusGProxy *proxy = NULL; const GOptionEntry options[] = { { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files, /* TRANSLATORS: command line option: a list of files to install */ _("Files to install"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); gtk_init (&argc, &argv); /* TRANSLATORS: program name: application to install a package to provide a file */ g_set_application_name (_("Software Install")); context = g_option_context_new ("gpk-install-local-file"); g_option_context_set_summary (context, _("PackageKit File Installer")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, gpk_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* TRANSLATORS: title to pass to to the user if there are not enough privs */ ret = gpk_check_privileged_user (_("Local file installer"), TRUE); if (!ret) goto out; if (files == NULL) { /* TRANSLATORS: could not install a package that contained the file we wanted */ gpk_error_dialog (_("Failed to install a package to provide a file"), /* TRANSLATORS: nothing selected */ _("You need to specify a file to install"), NULL); goto out; } /* make sure we don't pass relative paths to the session-interface */ /* (this is needed if install-local-files is executed from the command-line) */ current_dir = g_get_current_dir (); for (i = 0; files[i] != NULL; i++) { if (!g_str_has_prefix (files[i], "/")) { tmp = g_build_filename (current_dir, files[i], NULL); g_free (files[i]); files[i] = tmp; } } g_free (current_dir); /* check dbus connections, exit if not valid */ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { g_warning ("%s", error->message); goto out; } /* get a connection */ proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.PackageKit", "/org/freedesktop/PackageKit", "org.freedesktop.PackageKit.Modify"); if (proxy == NULL) { g_warning ("Cannot connect to session service"); goto out; } /* don't timeout, as dbus-glib sets the timeout ~25 seconds */ dbus_g_proxy_set_default_timeout (proxy, INT_MAX); /* do method */ ret = dbus_g_proxy_call (proxy, "InstallPackageFiles", &error, G_TYPE_UINT, 0, /* xid */ G_TYPE_STRV, files, /* data */ G_TYPE_STRING, "hide-finished,show-warnings", /* interaction */ G_TYPE_INVALID, G_TYPE_INVALID); if (!ret) { g_warning ("%s", error->message); goto out; } out: if (error != NULL) g_error_free (error); if (proxy != NULL) g_object_unref (proxy); g_strfreev (files); return !ret; }
static GObject * constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { GObject *object; BMRemoteSettingsPrivate *priv; const char *service = BM_DBUS_SERVICE_USER_SETTINGS; GError *error = NULL; object = G_OBJECT_CLASS (bm_remote_settings_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = BM_REMOTE_SETTINGS_GET_PRIVATE (object); /* D-Bus proxy for clearing connections on NameOwnerChanged */ priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); g_assert (priv->dbus_proxy); dbus_g_object_register_marshaller (_bm_marshal_VOID__STRING_STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->dbus_proxy, "NameOwnerChanged", G_CALLBACK (name_owner_changed), object, NULL); /* Settings service proxy */ if (priv->scope == BM_CONNECTION_SCOPE_SYSTEM) service = BM_DBUS_SERVICE_SYSTEM_SETTINGS; if (!dbus_g_proxy_call (priv->dbus_proxy, "NameHasOwner", &error, G_TYPE_STRING, service, G_TYPE_INVALID, G_TYPE_BOOLEAN, &priv->service_running, G_TYPE_INVALID)) { g_warning ("%s (BMRemoteSettings) error getting remote settings service status: (%d) %s\n", __func__, error ? error->code : -1, error && error->message ? error->message : "(unknown)"); g_error_free (error); priv->service_running = FALSE; } priv->proxy = dbus_g_proxy_new_for_name (priv->bus, service, BM_DBUS_PATH_SETTINGS, BM_DBUS_IFACE_SETTINGS); g_assert (priv->proxy); dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT); dbus_g_proxy_add_signal (priv->proxy, "NewConnection", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "NewConnection", G_CALLBACK (new_connection_cb), object, NULL); priv->fetch_id = g_idle_add (fetch_connections, object); return object; }
static gboolean pk_install_fonts_idle_cb (gpointer data G_GNUC_UNUSED) { DBusGConnection *connection; DBusGProxy *proxy = NULL; guint xid; gchar **font_tags; GError *error = NULL; DBusGProxyCall *call; g_return_val_if_fail (tags->len > 0, FALSE); /* get a strv out of the array that we will then own */ g_ptr_array_add (tags, NULL); font_tags = (gchar **) g_ptr_array_free (tags, FALSE); tags = NULL; /* try to get the window XID */ xid = guess_xid (); /* get bus */ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { g_warning ("Could not connect to session bus: %s\n", error->message); g_error_free (error); goto out; } /* get proxy */ proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.PackageKit", "/org/freedesktop/PackageKit", "org.freedesktop.PackageKit.Modify"); if (proxy == NULL) { g_warning ("Could not connect to PackageKit session service\n"); goto out; } /* don't timeout, as dbus-glib sets the timeout ~25 seconds */ dbus_g_proxy_set_default_timeout (proxy, INT_MAX); /* invoke the method */ call = dbus_g_proxy_begin_call (proxy, "InstallFontconfigResources", pk_install_fonts_dbus_notify_cb, NULL, NULL, G_TYPE_UINT, xid, G_TYPE_STRV, font_tags, G_TYPE_STRING, "hide-finished", G_TYPE_INVALID); if (call == NULL) { g_warning ("Could not send method"); goto out; } g_debug ("InstallFontconfigResources method invoked"); out: g_strfreev (font_tags); if (proxy != NULL) g_object_unref (proxy); return FALSE; }
/* activesyncd entry point */ int main (int argc, char** argv) { DBusGConnection* bus = NULL; DBusGProxy* busProxy = NULL; EasSync* EasSyncObj = NULL; EasCommon* EasCommonObj = NULL; EasMail*EasMailObj = NULL; EasTest* EasTestObj = NULL; GMainLoop* loop = NULL; guint result; GError* error = NULL; #if !GLIB_CHECK_VERSION(2,36,0) g_type_init(); #endif dbus_g_thread_init(); #if 0 g_log_set_handler (NULL, G_LOG_LEVEL_DEBUG | G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL, eas_logger, NULL); #endif g_log_set_default_handler (eas_logger, NULL); signal (SIGABRT, &signalHandler); signal (SIGTERM, &signalHandler); signal (SIGINT, &signalHandler); loop = g_main_loop_new (NULL, FALSE); if (loop == NULL) { g_debug ("Error: Couldn't create GMainLoop"); exit (EXIT_FAILURE); } // Give signalHandler() access to the main loop. g_mainloop = loop; //Creating all the GObjects g_debug ("activesyncd Daemon Started"); g_debug ("Creating eas_sync gobject."); EasSyncObj = eas_sync_new(); if (EasSyncObj == NULL) { g_debug ("Error: Failed to create calendar instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Creating common gobject."); EasCommonObj = g_object_new (EAS_TYPE_COMMON , NULL); if (EasCommonObj == NULL) { g_debug ("Error: Failed to create common instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Creating mail gobject."); EasMailObj = eas_mail_new (); if (EasMailObj == NULL) { g_debug ("Error: Failed to create common instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } EasTestObj = eas_test_new (); if (NULL == EasTestObj) { g_debug ("Failed to make EasTest instance"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Connecting to the session DBus"); bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (error != NULL) { g_debug ("Error: Connecting to the session DBus (%s)", error->message); g_clear_error (&error); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("Registering the well-known name (%s)", EAS_SERVICE_NAME); busProxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (busProxy == NULL) { g_debug ("Error: Failed to get a proxy for D-Bus"); g_main_loop_quit (loop); exit (EXIT_FAILURE); } dbus_g_proxy_set_default_timeout (busProxy, 1000000); /* register the well-known name.*/ g_debug ("D-Bus RequestName RPC "); if (!dbus_g_proxy_call (busProxy, "RequestName", &error, G_TYPE_STRING, EAS_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { g_debug ("Error: D-Bus RequestName RPC failed (%s)", error->message); g_clear_error (&error); g_main_loop_quit (loop); exit (EXIT_FAILURE); } g_debug ("RequestName returned %d", result); if (result != 1) { g_debug ("Error: Failed to get the primary well-known name"); exit (EXIT_FAILURE); } // Registering sync Gobject dbus_g_connection_register_g_object (bus, EAS_SERVICE_SYNC_OBJECT_PATH, G_OBJECT (EasSyncObj)); // Registering common Gobject dbus_g_connection_register_g_object (bus, EAS_SERVICE_COMMON_OBJECT_PATH, G_OBJECT (EasCommonObj)); // Registering mail Gobject dbus_g_connection_register_g_object (bus, EAS_SERVICE_MAIL_OBJECT_PATH, G_OBJECT (EasMailObj)); dbus_g_connection_register_g_object (bus, EAS_SERVICE_TEST_OBJECT_PATH, G_OBJECT (EasTestObj)); g_debug ("Ready to serve requests"); #ifndef DISABLE_EAS_DAEMON if (daemon (0, 0) != 0) { g_debug ("Failed to daemonize"); } #else g_debug ("Not daemonizing (built with DISABLE_EAS_DAEMON)"); #endif g_main_loop_run (loop); // Clean up g_debug ("Main Cleanup"); g_mainloop = NULL; g_main_loop_unref (loop); // clean up dbus and all its objects if (EasSyncObj) { g_debug ("Unregister and unref EasSyncObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasSyncObj)); g_object_unref(EasSyncObj); } if (EasCommonObj) { g_debug ("Unregister and unref EasCommonObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasCommonObj)); g_object_unref(EasCommonObj); } if (EasMailObj) { g_debug ("Unregister and unref EasMailObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasMailObj)); g_object_unref(EasMailObj); } if (EasTestObj) { g_debug ("Unregister and unref EasTestObj"); dbus_g_connection_unregister_g_object (bus, G_OBJECT (EasTestObj)); g_object_unref(EasTestObj); } if (busProxy) { g_debug ("Unref busProxy"); g_object_unref(busProxy); } if(bus) { g_debug ("Flush and unref DBusConnection bus"); dbus_g_connection_flush (bus); dbus_g_connection_unref(bus); } g_debug ("Exiting main()"); return 0; }
static GObject * constructor (GType type, guint n_construct_params, GObjectConstructParam *construct_params) { GObject *object; NMRemoteSettingsPrivate *priv; GError *error = NULL; object = G_OBJECT_CLASS (nm_remote_settings_parent_class)->constructor (type, n_construct_params, construct_params); if (!object) return NULL; priv = NM_REMOTE_SETTINGS_GET_PRIVATE (object); /* D-Bus proxy for clearing connections on NameOwnerChanged */ priv->dbus_proxy = dbus_g_proxy_new_for_name (priv->bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); g_assert (priv->dbus_proxy); dbus_g_object_register_marshaller (_nm_marshal_VOID__STRING_STRING_STRING, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->dbus_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->dbus_proxy, "NameOwnerChanged", G_CALLBACK (name_owner_changed), object, NULL); if (!dbus_g_proxy_call (priv->dbus_proxy, "NameHasOwner", &error, G_TYPE_STRING, NM_DBUS_SERVICE, G_TYPE_INVALID, G_TYPE_BOOLEAN, &priv->service_running, G_TYPE_INVALID)) { g_warning ("%s (NMRemoteSettings) error getting remote settings service status: (%d) %s\n", __func__, error ? error->code : -1, error && error->message ? error->message : "(unknown)"); g_error_free (error); priv->service_running = FALSE; } priv->proxy = dbus_g_proxy_new_for_name (priv->bus, NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, NM_DBUS_IFACE_SETTINGS); g_assert (priv->proxy); dbus_g_proxy_set_default_timeout (priv->proxy, G_MAXINT); dbus_g_proxy_add_signal (priv->proxy, "NewConnection", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "NewConnection", G_CALLBACK (new_connection_cb), object, NULL); priv->fetch_id = g_idle_add (fetch_connections, object); /* D-Bus properties proxy */ priv->props_proxy = dbus_g_proxy_new_for_name (priv->bus, NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, "org.freedesktop.DBus.Properties"); g_assert (priv->props_proxy); /* Monitor properties */ dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->proxy, "PropertiesChanged", DBUS_TYPE_G_MAP_OF_VARIANT, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "PropertiesChanged", G_CALLBACK (properties_changed_cb), object, NULL); /* Get properties */ dbus_g_proxy_begin_call (priv->props_proxy, "GetAll", get_all_cb, object, NULL, G_TYPE_STRING, NM_DBUS_IFACE_SETTINGS, G_TYPE_INVALID); return object; }
/** * main: **/ int main (int argc, char *argv[]) { GOptionContext *context; gboolean ret; GError *error = NULL; DBusGConnection *connection; DBusGProxy *proxy = NULL; gchar **files = NULL; const GOptionEntry options[] = { { G_OPTION_REMAINING, '\0', 0, G_OPTION_ARG_FILENAME_ARRAY, &files, /* TRANSLATORS: command line option: a list of files to install */ _("Local files to install"), NULL }, { NULL} }; setlocale (LC_ALL, ""); bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); if (! g_thread_supported ()) g_thread_init (NULL); g_type_init (); gtk_init (&argc, &argv); /* TRANSLATORS: program name, an application to install a file that is needed by an application and is provided by packages */ g_set_application_name (_("Single File Installer")); context = g_option_context_new ("gpk-install-provide-file"); g_option_context_set_summary (context, _("Single File Installer")); g_option_context_add_main_entries (context, options, NULL); g_option_context_add_group (context, egg_debug_get_option_group ()); g_option_context_add_group (context, gtk_get_option_group (TRUE)); g_option_context_parse (context, &argc, &argv, NULL); g_option_context_free (context); /* TRANSLATORS: application name to pass to to the user if there are not enough privs */ ret = gpk_check_privileged_user (_("Single File Installer"), TRUE); if (!ret) goto out; if (files == NULL) { /* TRANSLATORS: nothing done */ gpk_error_dialog (_("Failed to install a package to provide a file"), /* TRANSLATORS: nothig was specified */ _("You need to specify a filename to install"), NULL); goto out; } /* check dbus connections, exit if not valid */ connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { egg_warning ("%s", error->message); goto out; } /* get a connection */ proxy = dbus_g_proxy_new_for_name (connection, "org.freedesktop.PackageKit", "/org/freedesktop/PackageKit", "org.freedesktop.PackageKit.Modify"); if (proxy == NULL) { egg_warning ("Cannot connect to session service"); goto out; } /* don't timeout, as dbus-glib sets the timeout ~25 seconds */ dbus_g_proxy_set_default_timeout (proxy, INT_MAX); /* do method */ ret = dbus_g_proxy_call (proxy, "InstallProvideFiles", &error, G_TYPE_UINT, 0, /* xid */ G_TYPE_STRV, files, /* data */ G_TYPE_STRING, "hide-finished,hide-warnings", /* interaction */ G_TYPE_INVALID, G_TYPE_INVALID); if (!ret && !gpk_ignore_session_error (error)) { /* TRANSLATORS: This is when the specified DBus method did not execute successfully */ gpk_error_dialog (_("The action could not be completed"), /* TRANSLATORS: we don't have anything more useful to translate. sorry. */ _("The request failed. More details are available in the detailed report."), error->message); egg_warning ("%s", error->message); goto out; } out: if (error != NULL) g_error_free (error); if (proxy != NULL) g_object_unref (proxy); g_strfreev (files); return !ret; }