gboolean cpufreq_selector_service_register (CPUFreqSelectorService *service, GError **error) { DBusGConnection *connection; DBusGProxy *bus_proxy; gboolean res; guint result; GError *err = NULL; if (service->system_bus) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_ALREADY_REGISTERED, "Service %s already registered", BUS_NAME); return FALSE; } connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); if (!connection) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_DBUS, "Couldn't connect to system bus: %s", err->message); g_error_free (err); return FALSE; } bus_proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!bus_proxy) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_DBUS, "Could not construct bus_proxy object"); return FALSE; } res = dbus_g_proxy_call (bus_proxy, "RequestName", &err, G_TYPE_STRING, BUS_NAME, G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID); g_object_unref (bus_proxy); if (!res) { if (err) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_DBUS, "Failed to acquire %s: %s", BUS_NAME, err->message); g_error_free (err); } else { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_DBUS, "Failed to acquire %s", BUS_NAME); } return FALSE; } if (result == DBUS_REQUEST_NAME_REPLY_EXISTS) { g_set_error (error, CPUFREQ_SELECTOR_SERVICE_ERROR, SERVICE_ERROR_ALREADY_REGISTERED, "Service %s already registered", BUS_NAME); return FALSE; } service->authority = polkit_authority_get (); service->system_bus = connection; dbus_g_object_type_install_info (CPUFREQ_TYPE_SELECTOR_SERVICE, &dbus_glib_cpufreq_selector_service_object_info); dbus_g_connection_register_g_object (connection, "/org/gnome/cpufreq_selector/selector", G_OBJECT (service)); dbus_g_error_domain_register (CPUFREQ_SELECTOR_SERVICE_ERROR, NULL, CPUFREQ_TYPE_SELECTOR_SERVICE_ERROR); reset_killtimer (); return TRUE; }
static gboolean gsm_consolekit_ensure_ck_connection (GsmConsolekit *manager, GError **error) { GError *connection_error; gboolean is_connected; connection_error = NULL; if (manager->priv->dbus_connection == NULL) { DBusConnection *connection; manager->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &connection_error); if (manager->priv->dbus_connection == NULL) { g_propagate_error (error, connection_error); is_connected = FALSE; goto out; } connection = dbus_g_connection_get_connection (manager->priv->dbus_connection); dbus_connection_set_exit_on_disconnect (connection, FALSE); dbus_connection_add_filter (connection, gsm_consolekit_dbus_filter, manager, NULL); } if (manager->priv->bus_proxy == NULL) { manager->priv->bus_proxy = dbus_g_proxy_new_for_name_owner (manager->priv->dbus_connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &connection_error); if (manager->priv->bus_proxy == NULL) { g_propagate_error (error, connection_error); is_connected = FALSE; goto out; } dbus_g_proxy_add_signal (manager->priv->bus_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (manager->priv->bus_proxy, "NameOwnerChanged", G_CALLBACK (gsm_consolekit_on_name_owner_changed), manager, NULL); } if (manager->priv->ck_proxy == NULL) { manager->priv->ck_proxy = dbus_g_proxy_new_for_name_owner (manager->priv->dbus_connection, "org.freedesktop.ConsoleKit", "/org/freedesktop/ConsoleKit/Manager", "org.freedesktop.ConsoleKit.Manager", &connection_error); if (manager->priv->ck_proxy == NULL) { g_propagate_error (error, connection_error); is_connected = FALSE; goto out; } } is_connected = TRUE; out: if (manager->priv->is_connected != is_connected) { manager->priv->is_connected = is_connected; g_object_notify (G_OBJECT (manager), "is-connected"); } if (!is_connected) { if (manager->priv->dbus_connection == NULL) { if (manager->priv->bus_proxy != NULL) { g_object_unref (manager->priv->bus_proxy); manager->priv->bus_proxy = NULL; } if (manager->priv->ck_proxy != NULL) { g_object_unref (manager->priv->ck_proxy); manager->priv->ck_proxy = NULL; } } else if (manager->priv->bus_proxy == NULL) { if (manager->priv->ck_proxy != NULL) { g_object_unref (manager->priv->ck_proxy); manager->priv->ck_proxy = NULL; } } } return is_connected; }
int main (int argc, char **argv) { DBusGConnection *connection; GError *error; DBusGProxy *driver_proxy; guint32 request_name_ret; g_type_init (); dbus_g_thread_init (); dbus_g_error_domain_register (MY_OBJECT_ERROR, NULL, MY_TYPE_ERROR); g_printerr ("Launching test-service-glib\n"); loop = g_main_loop_new (NULL, FALSE); { GLogLevelFlags fatal_mask; fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; g_log_set_always_fatal (fatal_mask); } error = NULL; connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error); if (connection == NULL) { g_printerr ("Failed to open connection to bus: %s\n", error->message); g_error_free (error); exit (1); } obj = g_object_new (MY_TYPE_OBJECT, NULL); obj2 = g_object_new (MY_TYPE_OBJECT, NULL); subobj = g_object_new (MY_TYPE_OBJECT_SUBCLASS, NULL); dbus_g_connection_register_g_object (connection, "/org/freedesktop/DBus/GLib/Tests/MyTestObject", obj); /* Register a second time; we want the object to also be reachable through this interface */ dbus_g_connection_register_g_object (connection, "/org/freedesktop/DBus/GLib/Tests/Compat/MyTestObjectCompat", obj); dbus_g_connection_register_g_object (connection, "/org/freedesktop/DBus/GLib/Tests/MyTestObject2", obj2); dbus_g_connection_register_g_object (connection, "/org/freedesktop/DBus/GLib/Tests/MyTestObjectSubclass", subobj); driver_proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!org_freedesktop_DBus_request_name (driver_proxy, TEST_SERVICE_NAME, 0, &request_name_ret, &error)) { g_assert (error != NULL); g_printerr ("Failed to get name: %s\n", error->message); g_clear_error (&error); exit (1); } if (!(request_name_ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)) { g_printerr ("Got result code %u from requesting name\n", request_name_ret); exit (1); } g_printerr ("GLib test service has name '%s'\n", TEST_SERVICE_NAME); g_printerr ("GLib test service entering main loop\n"); g_main_loop_run (loop); g_printerr ("Successfully completed %s\n", argv[0]); return 0; }
int main (int argc, char **argv) { DBusGConnection *connection; DBusGProxy *proxy; GError *error = NULL; gchar *str; gboolean success; DBusGProxy *dp_proxy; g_type_init (); connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { g_error ("Failed to make connection to session bus: %s", error->message); g_error_free (error); exit(1); } proxy = dbus_g_proxy_new_for_name (connection, TEST_NAMESPACE, TEST_OBJECT_PATH, "org.freedesktop.DBus.GLib.Test.Interfaces.Song"); success = org_freedesktop_DBus_GLib_Test_Interfaces_Song_get_title (proxy, &str, &error); g_object_unref (proxy); if (!success) { g_print ("Error while calling Parent object method: %s\n", error->message); g_error_free (error); exit(1); } else { g_free (str); g_print ("Called Parent object method with success\n"); } proxy = dbus_g_proxy_new_for_name (connection, TEST_NAMESPACE, TEST_OBJECT_PATH, "org.freedesktop.DBus.GLib.Test.Interfaces.Hello"); g_assert (proxy != NULL); success = org_freedesktop_DBus_GLib_Test_Interfaces_Hello_say_hello (proxy, &str, &error); g_object_unref (proxy); if (!success) { g_print ("Error while calling Parent Interface object method: %s\n", error->message); g_error_free (error); exit(1); } else { g_free (str); g_print ("Called Parent Interface object method with success\n"); } proxy = dbus_g_proxy_new_for_name (connection, TEST_NAMESPACE, TEST_OBJECT_PATH, "org.freedesktop.DBus.GLib.Test.Interfaces.Goodbye"); success = org_freedesktop_DBus_GLib_Test_Interfaces_Goodbye_say_goodbye (proxy, &str, &error); g_object_unref (proxy); if (!success) { g_print ("Error while calling Object Interface object method: %s\n", error->message); g_error_free (error); exit(1); } else { g_free (str); g_print ("Called Object Interface object method with success\n"); } /* Test interfaces with conflicting property names on the same GObject */ dp_proxy = dbus_g_proxy_new_for_name (connection, TEST_NAMESPACE, TEST_DP_OBJECT_PATH, "org.freedesktop.DBus.Properties"); /* test that setting the property and reading it back works */ test_dp_property (dp_proxy, "A", TEST_DP_IFACE_A, 235235, FALSE); test_dp_property (dp_proxy, "B", TEST_DP_IFACE_B, 11981241, FALSE); /* Test that setting A does not change B */ test_dp_property (dp_proxy, "B", TEST_DP_IFACE_B, 11981241, FALSE); test_dp_property (dp_proxy, "A", TEST_DP_IFACE_A, 235235, FALSE); test_dp_property (dp_proxy, "B", TEST_DP_IFACE_B, 11981241, TRUE); /* And test that setting B does not change A */ test_dp_property (dp_proxy, "A", TEST_DP_IFACE_A, 235235, FALSE); test_dp_property (dp_proxy, "B", TEST_DP_IFACE_B, 11981241, FALSE); test_dp_property (dp_proxy, "A", TEST_DP_IFACE_A, 235235, TRUE); g_object_unref (dp_proxy); /* Ensure the properties are introspectable */ dp_proxy = dbus_g_proxy_new_for_name (connection, TEST_NAMESPACE, TEST_DP_OBJECT_PATH, "org.freedesktop.DBus.Introspectable"); g_print ("Testing duplicate property name introspection\n"); if (!dbus_g_proxy_call (dp_proxy, "Introspect", &error, G_TYPE_INVALID, G_TYPE_STRING, &str, G_TYPE_INVALID)) { g_print ("Error while introspecting duplicate properties: %s\n", error->message); g_error_free (error); exit(1); } else g_print ("Introspected duplicate properties with success\n"); { NodeInfo *node; GSList *elt; gboolean found_introspectable = FALSE; gboolean found_properties = FALSE; gboolean found_iface_a = FALSE; gboolean found_iface_a_prop = FALSE; gboolean found_iface_b = FALSE; gboolean found_iface_b_prop = FALSE; node = description_load_from_string (str, strlen (str), &error); if (!node) { g_print ("Failed to parse introspection data: %s\n", error->message); g_error_free (error); exit(1); } for (elt = node_info_get_interfaces (node); elt ; elt = elt->next) { InterfaceInfo *iface = elt->data; if (!found_introspectable && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Introspectable") == 0) found_introspectable = TRUE; else if (!found_properties && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.Properties") == 0) found_properties = TRUE; else if (!found_iface_a && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.GLib.Test.Interfaces.A") == 0) { GSList *elt; found_iface_a = TRUE; for (elt = interface_info_get_properties (iface); elt; elt = elt->next) { PropertyInfo *prop; prop = elt->data; if (strcmp (property_info_get_name (prop), "Foobar") == 0) { found_iface_a_prop = TRUE; break; } } } else if (!found_iface_b && strcmp (interface_info_get_name (iface), "org.freedesktop.DBus.GLib.Test.Interfaces.B") == 0) { GSList *elt; found_iface_b = TRUE; for (elt = interface_info_get_properties (iface); elt; elt = elt->next) { PropertyInfo *prop; prop = elt->data; if (strcmp (property_info_get_name (prop), "Foobar") == 0) { found_iface_b_prop = TRUE; break; } } } } g_free (str); if (!found_iface_a_prop || !found_iface_b_prop) { g_print ("Failed to find Foobar properties in introspection data\n"); g_error_free (error); exit(1); } } exit(0); }
static void on_sms_clicked (GtkWidget *button, MokoHistory *history) { DBusGConnection *conn; DBusGProxy *proxy; GError *err = NULL; MokoHistoryPrivate *priv; GtkTreeSelection *selection; GtkTreeView *treeview; GtkTreeIter iter; GtkTreeModel *model; gchar *number; guint transaction; g_debug ("sms clicked"); g_return_if_fail (MOKO_IS_HISTORY (history)); priv = history->priv; treeview = GTK_TREE_VIEW (priv->treeview); selection = gtk_tree_view_get_selection (treeview); model = gtk_tree_view_get_model (treeview); if (!gtk_tree_selection_get_selected (selection, &model, &iter)) return; gtk_tree_model_get (model, &iter, NUMBER_COLUMN, &number, -1); g_debug ("send SMS to number: %s", number); conn = dbus_g_bus_get (DBUS_BUS_SESSION, &err); if (conn == NULL) { g_warning ("Failed to make DBus connection: %s", err->message); g_error_free (err); return; } proxy = dbus_g_proxy_new_for_name (conn, SMS_NAMESPACE, SMS_OBJECT, SMS_NAMESPACE); if (proxy == NULL) { g_warning ("Unable to get openmoko-messages2 object"); return; } err = NULL; dbus_g_proxy_call (proxy, "SendMessage", &err, G_TYPE_STRING, NULL, G_TYPE_STRING, number, G_TYPE_STRING, NULL, G_TYPE_INVALID, G_TYPE_UINT, &transaction, G_TYPE_INVALID); if (err) { g_warning (err->message); g_error_free (err); } else { g_debug ( "sms: transaction %u started\n", transaction); } }
int main (int argc, char **argv) { GOptionContext *context; gboolean ok; GError *error = NULL; DBusGConnection *bus; DBusGProxy *shell_proxy = NULL; DBusGProxy *player_proxy = NULL; gboolean is_playing; #ifdef ENABLE_NLS /* initialize i18n */ bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); #endif /* setup */ setlocale (LC_ALL, ""); g_type_init (); g_set_prgname ("rhythmbox-client"); /* parse arguments */ context = g_option_context_new (NULL); g_option_context_add_main_entries (context, args, NULL); ok = g_option_context_parse (context, &argc, &argv, &error); if (annoy (&error)) exit (1); rb_debug_init (debug); /* get dbus connection and proxy for rhythmbox shell */ bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (annoy (&error)) exit (1); if (!create_rb_shell_proxies (bus, &shell_proxy, &player_proxy, &error)) { annoy (&error); exit (1); } g_clear_error (&error); /* 1. activate or quit */ if (quit) { if (shell_proxy) { rb_debug ("quitting existing instance"); dbus_g_proxy_call_no_reply (shell_proxy, "quit", G_TYPE_INVALID); } else { rb_debug ("no existing instance to quit"); } exit (0); } if (shell_proxy == NULL) { DBusGProxy *bus_proxy; guint start_service_reply; if (no_start) { rb_debug ("no existing instance, and can't start one"); exit (0); } rb_debug ("starting new instance"); bus_proxy = dbus_g_proxy_new_for_name (bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); if (!dbus_g_proxy_call (bus_proxy, "StartServiceByName", &error, G_TYPE_STRING, "org.gnome.Rhythmbox", G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &start_service_reply, G_TYPE_INVALID)) { g_warning ("%s", error->message); exit (1); } /* hopefully we can get a proxy for the rb shell now.. */ if (!create_rb_shell_proxies (bus, &shell_proxy, &player_proxy, &error)) { annoy (&error); exit (1); } g_clear_error (&error); } /* don't present if we're doing something else */ if (next || previous || clear_queue || play_uri || other_stuff || play || pause || play_pause || stop || print_playing || print_playing_format || notify || (set_volume > -0.01) || volume_up || volume_down || print_volume || mute || unmute) no_present = TRUE; /* 2. present or hide */ if (hide || !no_present) { DBusGProxy *properties_proxy; GValue value = {0,}; rb_debug ("setting visibility property"); g_value_init (&value, G_TYPE_BOOLEAN); g_value_set_boolean (&value, !hide); properties_proxy = dbus_g_proxy_new_from_proxy (shell_proxy, "org.freedesktop.DBus.Properties", "/org/gnome/Rhythmbox/Shell"); dbus_g_proxy_call_no_reply (properties_proxy, "Set", G_TYPE_STRING, "org.gnome.Rhythmbox.Shell", G_TYPE_STRING, "visibility", G_TYPE_VALUE, &value, G_TYPE_INVALID); g_object_unref (G_OBJECT (properties_proxy)); } /* 3. skip to next or previous track */ if (next) { rb_debug ("next track"); org_gnome_Rhythmbox_Player_next (player_proxy, &error); annoy (&error); } else if (previous) { rb_debug ("previous track"); org_gnome_Rhythmbox_Player_previous (player_proxy, &error); annoy (&error); } /* 4. add/enqueue */ if (clear_queue) { org_gnome_Rhythmbox_Shell_clear_queue (shell_proxy, &error); annoy (&error); } if (other_stuff) { int i; for (i = 0; other_stuff[i] != NULL; i++) { GFile *file; char *fileuri; file = g_file_new_for_commandline_arg (other_stuff[i]); fileuri = g_file_get_uri (file); if (fileuri == NULL) { g_warning ("couldn't convert \"%s\" to a URI", other_stuff[i]); continue; } if (enqueue) { rb_debug ("enqueueing %s", fileuri); org_gnome_Rhythmbox_Shell_add_to_queue (shell_proxy, fileuri, &error); } else { rb_debug ("importing %s", fileuri); org_gnome_Rhythmbox_Shell_load_ur_i (shell_proxy, fileuri, FALSE, &error); } annoy (&error); g_free (fileuri); g_object_unref (file); } } /* play uri */ if (play_uri) { GFile *file; char *fileuri; file = g_file_new_for_commandline_arg (play_uri); fileuri = g_file_get_uri (file); if (fileuri == NULL) { g_warning ("couldn't convert \"%s\" to a URI", play_uri); } else { rb_debug ("loading and playing %s", fileuri); org_gnome_Rhythmbox_Shell_load_ur_i (shell_proxy, fileuri, TRUE, &error); annoy (&error); } g_free (fileuri); g_object_unref (file); } /* 5. play/pause/stop */ org_gnome_Rhythmbox_Player_get_playing (player_proxy, &is_playing, &error); if (!annoy (&error)) { rb_debug ("playback state: %d", is_playing); if (play || pause || play_pause) { if (is_playing != play || play_pause) { rb_debug ("calling playPause to change playback state"); org_gnome_Rhythmbox_Player_play_pause (player_proxy, FALSE, &error); annoy (&error); } else { rb_debug ("no need to change playback state"); } } else if (stop) { g_warning ("not implemented yet"); } } /* 6. get/set volume, mute/unmute */ if (set_volume > -0.01) { org_gnome_Rhythmbox_Player_set_volume (player_proxy, set_volume, &error); annoy (&error); } else if (volume_up || volume_down) { org_gnome_Rhythmbox_Player_set_volume_relative (player_proxy, volume_up ? 0.1 : -0.1, &error); annoy (&error); } else if (unmute || mute) { org_gnome_Rhythmbox_Player_set_mute (player_proxy, unmute ? FALSE : TRUE, &error); annoy (&error); } if (print_volume) { gboolean mute = FALSE; gdouble volume = 1.0; org_gnome_Rhythmbox_Player_get_mute (player_proxy, &mute, &error); annoy (&error); org_gnome_Rhythmbox_Player_get_volume (player_proxy, &volume, &error); annoy (&error); if (mute) g_print (_("Playback is muted.\n")); g_print (_("Playback volume is %f.\n"), volume); } /* 7. print playing song */ if (print_playing_format) { print_playing_song (shell_proxy, player_proxy, print_playing_format); } else if (print_playing) { print_playing_song_default (shell_proxy, player_proxy); } /* 8. display notification about playing song */ if (notify) { rb_debug ("show notification"); org_gnome_Rhythmbox_Shell_notify (shell_proxy, TRUE, &error); annoy (&error); } g_object_unref (shell_proxy); g_object_unref (player_proxy); g_option_context_free (context); return 0; }
static HRESULT get_connection_from_udev_or_odccm(SynceInfo *info, int *sockfd) { GError *error = NULL; DBusGConnection *bus = NULL; DBusGProxy *dbus_proxy = NULL; DBusGProxy *dev_proxy = NULL; gboolean dccm_running = FALSE; gchar *unix_path = NULL; gint fd = -1; const gchar *service = NULL; const gchar *dev_iface = NULL; const gchar *dccm_name = NULL; HRESULT result = E_FAIL; /* Ensure that e.g. SYNCE_DCCM_ERROR is registered using g_dbus_error_register_error() */ synce_glib_init(); #if ENABLE_ODCCM_SUPPORT const gchar *transport = synce_info_get_transport(info); if (strcmp(transport, "odccm") == 0) { service = ODCCM_SERVICE; dev_iface = ODCCM_DEV_IFACE; dccm_name = "odccm"; } else #endif { service = DCCM_SERVICE; dev_iface = DCCM_DEV_IFACE; dccm_name = "dccm"; } #if !GLIB_CHECK_VERSION (2, 36, 0) g_type_init(); #endif bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (bus == NULL) { synce_warning("%s: Failed to connect to system bus: %s", G_STRFUNC, error->message); goto ERROR; } dbus_proxy = dbus_g_proxy_new_for_name (bus, DBUS_SERVICE, DBUS_PATH, DBUS_IFACE); if (dbus_proxy == NULL) { synce_warning("%s: Failed to get dbus proxy object", G_STRFUNC); goto ERROR; } if (!(dbus_g_proxy_call(dbus_proxy, "NameHasOwner", &error, G_TYPE_STRING, service, G_TYPE_INVALID, G_TYPE_BOOLEAN, &dccm_running, G_TYPE_INVALID))) { synce_warning("%s: Error checking owner of service %s: %s", G_STRFUNC, service, error->message); g_object_unref(dbus_proxy); goto ERROR; } g_object_unref(dbus_proxy); if (!dccm_running) { synce_info("%s is not running, ignoring", dccm_name); goto ERROR; } dev_proxy = dbus_g_proxy_new_for_name(bus, service, synce_info_get_object_path(info), dev_iface); if (dev_proxy == NULL) { synce_warning("%s: Failed to get proxy for device '%s'", G_STRFUNC, synce_info_get_object_path(info)); goto ERROR; } if (!dbus_g_proxy_call(dev_proxy, "RequestConnection", &error, G_TYPE_INVALID, G_TYPE_STRING, &unix_path, G_TYPE_INVALID)) { synce_warning("%s: Failed to get a connection for %s: %s", G_STRFUNC, synce_info_get_name(info), error->message); /* INVALID_PASSWORD isn't perfect, but seems to be the best we have */ if (dbus_g_error_has_name(error, "org.synce.dccm.Error.DeviceLocked")) result = HRESULT_FROM_WIN32(ERROR_INVALID_PASSWORD); g_object_unref(dev_proxy); goto ERROR; } g_object_unref(dev_proxy); fd = get_socket_from_dccm(unix_path); g_free(unix_path); if (fd < 0) { synce_warning("%s: Failed to get file-descriptor from %s for %s", G_STRFUNC, dccm_name, synce_info_get_name(info)); goto ERROR; } result = S_OK; goto OUT; ERROR: if (error != NULL) g_error_free(error); OUT: if (bus != NULL) dbus_g_connection_unref (bus); *sockfd = fd; return result; }
/** * gpm_session_init: * @session: This class instance **/ static void gpm_session_init (GpmSession *session) { DBusGConnection *connection; GError *error = NULL; session->priv = GPM_SESSION_GET_PRIVATE (session); session->priv->is_idle_old = FALSE; session->priv->is_idle_inhibited_old = FALSE; session->priv->is_suspend_inhibited_old = FALSE; session->priv->proxy_client_private = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); /* get org.mate.Session interface */ session->priv->proxy = dbus_g_proxy_new_for_name_owner (connection, GPM_SESSION_MANAGER_SERVICE, GPM_SESSION_MANAGER_PATH, GPM_SESSION_MANAGER_INTERFACE, &error); if (session->priv->proxy == NULL) { egg_warning ("DBUS error: %s", error->message); g_error_free (error); return; } /* get org.mate.Session.Presence interface */ session->priv->proxy_presence = dbus_g_proxy_new_for_name_owner (connection, GPM_SESSION_MANAGER_SERVICE, GPM_SESSION_MANAGER_PRESENCE_PATH, GPM_SESSION_MANAGER_PRESENCE_INTERFACE, &error); if (session->priv->proxy_presence == NULL) { egg_warning ("DBUS error: %s", error->message); g_error_free (error); return; } /* get properties interface */ session->priv->proxy_prop = dbus_g_proxy_new_for_name_owner (connection, GPM_SESSION_MANAGER_SERVICE, GPM_SESSION_MANAGER_PRESENCE_PATH, GPM_DBUS_PROPERTIES_INTERFACE, &error); if (session->priv->proxy_prop == NULL) { egg_warning ("DBUS error: %s", error->message); g_error_free (error); return; } /* get StatusChanged */ dbus_g_proxy_add_signal (session->priv->proxy_presence, "StatusChanged", G_TYPE_UINT, G_TYPE_INVALID); dbus_g_proxy_connect_signal (session->priv->proxy_presence, "StatusChanged", G_CALLBACK (gpm_session_presence_status_changed_cb), session, NULL); /* get InhibitorAdded */ dbus_g_proxy_add_signal (session->priv->proxy, "InhibitorAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (session->priv->proxy, "InhibitorAdded", G_CALLBACK (gpm_session_inhibit_changed_cb), session, NULL); /* get InhibitorRemoved */ dbus_g_proxy_add_signal (session->priv->proxy, "InhibitorRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (session->priv->proxy, "InhibitorRemoved", G_CALLBACK (gpm_session_inhibit_changed_cb), session, NULL); /* coldplug */ session->priv->is_idle_inhibited_old = gpm_session_is_idle_inhibited (session); session->priv->is_suspend_inhibited_old = gpm_session_is_suspend_inhibited (session); session->priv->is_idle_old = gpm_session_is_idle (session); egg_debug ("idle: %i, idle_inhibited: %i, suspend_inhibited: %i", session->priv->is_idle_old, session->priv->is_idle_inhibited_old, session->priv->is_suspend_inhibited_old); }
static gboolean nm_openssh_send_ip4_config (sshtun_handle_t handle) { DBusGConnection *connection; GError *err = NULL; GHashTable *config; GValue *val; struct in_addr temp_addr; const char *tmp; connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &err); if (!connection) return FALSE; config = g_hash_table_new (g_str_hash, g_str_equal); /* Gateway */ val = addr_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_GW_ADDR)); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_GATEWAY, val); else { helper_failed (connection, "VPN Gateway"); dbus_g_connection_unref (connection); return FALSE; } /* Tunnel device */ val = str_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_TUN_DEV), FALSE); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_TUNDEV, val); else { helper_failed (connection, "Tunnel Device"); dbus_g_connection_unref (connection); return FALSE; } /* IP address */ val = addr_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_ADDR)); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_ADDRESS, val); else { helper_failed (connection, "IP4 Address"); dbus_g_connection_unref (connection); return FALSE; } /* PTP address */ val = addr_to_gvalue (sshtun_get_param (handle, SSHTUN_PARAM_PEER_ADDR)); if (val) g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_PTP, val); /* Netmask */ tmp = sshtun_get_param (handle, SSHTUN_PARAM_NETMASK); if (tmp && inet_pton (AF_INET, tmp, &temp_addr) > 0) { val = uint_to_gvalue (nm_utils_ip4_netmask_to_prefix (temp_addr.s_addr)); g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_PREFIX, val); } /* MTU */ tmp = sshtun_get_param (handle, SSHTUN_PARAM_MTU); if (tmp && strlen (tmp)) { long int mtu; errno = 0; mtu = strtol (tmp, NULL, 10); if (errno || mtu < 0 || mtu > 20000) { nm_warning ("Ignoring invalid tunnel MTU '%s'", tmp); } else { val = uint_to_gvalue ((guint32) mtu); g_hash_table_insert (config, NM_VPN_PLUGIN_IP4_CONFIG_MTU, val); } } send_ip4_config (connection, config); dbus_g_connection_unref (connection); return TRUE; }
NMCResultCode do_add (NmCli *nmc, int argc, char **argv) { DBusGConnection *bus; DBusGProxy *proxy; GError *err = NULL; int i; char *apn = NULL; char *pin = NULL; char *username = NULL; char *password = NULL; char *number = NULL; char *ntype = NULL; char *auth = NULL; char *comp = NULL; char *aut = NULL; char *netid = NULL; char *enc = NULL; char *echofail = NULL; char *echoint = NULL; char *uuid = NULL; char *sbits = NULL; char *stbits = NULL; char *sparity = NULL; char *sbaud = NULL; if ((*argv == NULL) || strcmp(argv[0],"help") == 0 || strcmp(argv[0],"-help") == 0){ usage_add(); } else{ if (!nmc_is_nm_running (nmc, &err)) { if (err) { g_string_printf (nmc->return_text, _("Error: Can't find out if NetworkManager is running: %s."), err->message); nmc->return_value = NMC_RESULT_ERROR_UNKNOWN; g_error_free (err); return nmc->return_value; } else { g_string_printf (nmc->return_text, _("Error: NetworkManager is not running.")); nmc->return_value = NMC_RESULT_ERROR_NM_NOT_RUNNING; return nmc->return_value; } } if (matches(argv[0],"id") != 0){ g_string_printf (nmc->return_text, _("Error: id has to be specified.")); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; return nmc->return_value; } else if (matches(argv[0],"id") == 0){ if(argc == 1){ g_string_printf (nmc->return_text, _("Error: argument missing for parameter id.")); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; return nmc->return_value; } else if (argc % 2!=0){ g_string_printf (nmc->return_text, _("Error: Some arguments are missing.")); nmc->return_value = NMC_RESULT_ERROR_USER_INPUT; return nmc->return_value; } } for (i=0; i<argc; i=i+2){ (matches(argv[i], "apn") == 0) ? apn = argv[i + 1] : NOT_SET; (matches(argv[i], "pin") == 0) ? pin = argv[i + 1] : NOT_SET; (matches(argv[i], "username") == 0) ? username = argv[i + 1] : NOT_SET; (matches(argv[i], "password") == 0) ? password = argv[i + 1] : NOT_SET; (matches(argv[i], "ntype") == 0) ? ntype = argv[i + 1] : NOT_SET; (matches(argv[i], "number") == 0) ? number = argv[i + 1] : NOT_SET; (matches(argv[i], "auth") == 0) ? auth = argv[i + 1] : NOT_SET; (matches(argv[i], "comp") == 0) ? comp = argv[i + 1] : NOT_SET; (matches(argv[i], "auto") == 0) ? aut = argv[i + 1] : NOT_SET; (matches(argv[i], "netid") == 0) ? netid = argv[i + 1] : NOT_SET; (matches(argv[i], "enc") == 0) ? enc = argv[i + 1] : NOT_SET; (matches(argv[i], "echoint") == 0) ? echoint = argv[i + 1] : NOT_SET; (matches(argv[i], "echofail") == 0) ? echofail = argv[i + 1] : NOT_SET; (matches(argv[i], "uuid") == 0) ? uuid = argv[i + 1] : NOT_SET; (matches(argv[i], "sbits") == 0) ? sbits = argv[i + 1] : NOT_SET; (matches(argv[i], "sparity") == 0) ? sparity = argv[i + 1] : NOT_SET; (matches(argv[i], "stbits") == 0) ? stbits = argv[i + 1] : NOT_SET; (matches(argv[i], "sbaud") == 0) ? sbaud = argv[i + 1] : NOT_SET; } g_type_init (); bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL); proxy = dbus_g_proxy_new_for_name (bus, NM_DBUS_SERVICE, NM_DBUS_PATH_SETTINGS, NM_DBUS_IFACE_SETTINGS); if (add_connection (proxy, argv[1], apn, pin, username, password, ((ntype == NULL) ? -1 : atoi(ntype)), number, ((auth == NULL) ? "fffff" : auth), ((comp == NULL) ? "fff" : comp), aut, netid, ((enc == NULL) ? "ff" : enc), ((echoint == NULL) ? 0 : atoi(echoint)), ((echofail == NULL) ? 0 : atoi(echofail)), uuid, ((sbits == NULL) ? 8 : atoi(sbits)), ((sparity!=NULL) ? sparity[0] : 110), ((stbits == NULL) ? 1 : atoi(stbits)), ((sbaud == NULL) ? 57600 : atoi(sbaud))) != 0){ fprintf (stderr,"Error: unable to add new connection."); nmc->return_value = NMC_RESULT_ERROR_CON_ADD; g_object_unref (proxy); dbus_g_connection_unref (bus); return nmc->return_value; } g_object_unref (proxy); dbus_g_connection_unref (bus); } nmc->return_value = NMC_RESULT_SUCCESS; return nmc->return_value; }
static gboolean panel_power_manager_ensure_gpm_connection (PanelPowerManager *manager, GError **error) { GError *connection_error; gboolean is_connected; connection_error = NULL; if (manager->priv->dbus_connection == NULL) { manager->priv->dbus_connection = dbus_g_bus_get (DBUS_BUS_SESSION, &connection_error); if (manager->priv->dbus_connection == NULL) { g_propagate_error (error, connection_error); is_connected = FALSE; goto out; } } if (manager->priv->bus_proxy == NULL) { manager->priv->bus_proxy = dbus_g_proxy_new_for_name_owner (manager->priv->dbus_connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, &connection_error); if (manager->priv->bus_proxy == NULL) { g_propagate_error (error, connection_error); is_connected = FALSE; goto out; } dbus_g_proxy_add_signal (manager->priv->bus_proxy, "NameOwnerChanged", G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (manager->priv->bus_proxy, "NameOwnerChanged", G_CALLBACK (panel_power_manager_on_name_owner_changed), manager, NULL); } if (manager->priv->gpm_proxy == NULL) { manager->priv->gpm_proxy = dbus_g_proxy_new_for_name_owner ( manager->priv->dbus_connection, "org.gnome.PowerManager", "/org/gnome/PowerManager", "org.gnome.PowerManager", &connection_error); if (manager->priv->gpm_proxy == NULL) { g_propagate_error (error, connection_error); is_connected = FALSE; goto out; } } is_connected = TRUE; out: if (manager->priv->is_connected != is_connected) { manager->priv->is_connected = is_connected; g_object_notify (G_OBJECT (manager), "is-connected"); } if (!is_connected) { if (manager->priv->dbus_connection == NULL) { if (manager->priv->bus_proxy != NULL) { g_object_unref (manager->priv->bus_proxy); manager->priv->bus_proxy = NULL; } if (manager->priv->gpm_proxy != NULL) { g_object_unref (manager->priv->gpm_proxy); manager->priv->gpm_proxy = NULL; } } else if (manager->priv->bus_proxy == NULL) { if (manager->priv->gpm_proxy != NULL) { g_object_unref (manager->priv->gpm_proxy); manager->priv->gpm_proxy = NULL; } } } return is_connected; }
static void mojito_client_view_constructed (GObject *object) { MojitoClientViewPrivate *priv = GET_PRIVATE (object); GError *error = NULL; DBusConnection *conn; DBusError derror; priv->connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error); if (!priv->connection) { g_critical (G_STRLOC ": Error getting DBUS connection: %s", error->message); g_clear_error (&error); return; } conn = dbus_g_connection_get_connection (priv->connection); dbus_error_init (&derror); if (!dbus_bus_start_service_by_name (conn, MOJITO_SERVICE_NAME, 0, NULL, &derror)) { g_critical (G_STRLOC ": Error starting mojito service: %s", derror.message); dbus_error_free (&derror); return; } priv->proxy = dbus_g_proxy_new_for_name_owner (priv->connection, MOJITO_SERVICE_NAME, priv->object_path, MOJITO_SERVICE_VIEW_INTERFACE, &error); if (!priv->proxy) { g_critical (G_STRLOC ": Error setting up proxy for remote object: %s", error->message); g_clear_error (&error); return; } dbus_g_proxy_add_signal (priv->proxy, "ItemsAdded", _mojito_items_get_container_type (), NULL); dbus_g_proxy_connect_signal (priv->proxy, "ItemsAdded", (GCallback)_proxy_items_added_cb, object, NULL); dbus_g_proxy_add_signal (priv->proxy, "ItemsChanged", _mojito_items_get_container_type (), NULL); dbus_g_proxy_connect_signal (priv->proxy, "ItemsChanged", (GCallback)_proxy_items_changed_cb, object, NULL); dbus_g_proxy_add_signal (priv->proxy, "ItemsRemoved", _mojito_items_removed_get_container_type (), NULL); dbus_g_proxy_connect_signal (priv->proxy, "ItemsRemoved", (GCallback)_proxy_items_removed_cb, object, NULL); }
int main (int argc, char**argv) { DBusGConnection* bus; UbaCreator * creator; GMainLoop * loop; GError * error = NULL; openlog (g_get_prgname (), LOG_CONS, LOG_USER); g_log_set_default_handler (my_log_func, NULL); syslog (LOG_INFO, "started"); g_type_init (); bus = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (!bus) { g_warning ("Failed to connect to dbus session bus: %s", error->message); g_clear_error (&error); closelog (); return 1; } switch (dbus_bus_request_name (dbus_g_connection_get_connection (bus), "eu.adeal.uba.demo", DBUS_NAME_FLAG_REPLACE_EXISTING, NULL)) { case DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER: /* happy */ break; default: /* unhappy */ break; } gtk_init (&argc, &argv); loop = g_main_loop_new (NULL, FALSE); creator = uba_creator_new (); uba_creator_set_main_loop (creator, loop); g_signal_connect (creator, "connect", G_CALLBACK (connect_cb), NULL); syslog (LOG_INFO, "before registering: %d refs", G_OBJECT (creator)->ref_count); uba_creator_register (creator, bus, "/eu/adeal/uba/demo"); syslog (LOG_INFO, "after registering: %d refs", G_OBJECT (creator)->ref_count); g_main_loop_run (loop); g_main_loop_unref (loop); g_object_unref (creator); closelog (); return 0; }
void hexchat_remote (void) /* TODO: dbus_g_connection_unref (connection) are commented because it makes * dbus to crash. Fixed in dbus >=0.70 ?!? * https://launchpad.net/distros/ubuntu/+source/dbus/+bug/54375 */ { DBusGConnection *connection; DBusGProxy *dbus = NULL; DBusGProxy *remote_object = NULL; gboolean hexchat_running; GError *error = NULL; char *command = NULL; /* GnomeVFS >=2.15 uses D-Bus and threads, so threads should be * initialised before opening for the first time a D-Bus connection */ if (!g_thread_supported ()) { g_thread_init (NULL); } dbus_g_thread_init (); /* if there is nothing to do, return now. */ if (!arg_existing || !(arg_url || arg_command)) { return; } arg_dont_autoconnect = TRUE; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (!connection) { write_error (_("Couldn't connect to session bus"), &error); return; } /* Checks if HexChat is already running */ dbus = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!dbus_g_proxy_call (dbus, "NameHasOwner", &error, G_TYPE_STRING, DBUS_SERVICE, G_TYPE_INVALID, G_TYPE_BOOLEAN, &hexchat_running, G_TYPE_INVALID)) { write_error (_("Failed to complete NameHasOwner"), &error); hexchat_running = FALSE; } g_object_unref (dbus); if (!hexchat_running) { //dbus_g_connection_unref (connection); return; } remote_object = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE, DBUS_REMOTE, DBUS_REMOTE_INTERFACE); if (arg_url) { command = g_strdup_printf ("url %s", arg_url); } else if (arg_command) { command = g_strdup (arg_command); } if (command) { if (!dbus_g_proxy_call (remote_object, "Command", &error, G_TYPE_STRING, command, G_TYPE_INVALID,G_TYPE_INVALID)) { write_error (_("Failed to complete Command"), &error); } g_free (command); } exit (0); }
static DBusGProxy *dbus_connect (MoonshotError **error) { DBusConnection *dbconnection; DBusError dbus_error; DBusGConnection *connection; DBusGProxy *g_proxy; GError *g_error = NULL; dbus_bool_t name_has_owner; g_return_val_if_fail (*error == NULL, NULL); dbus_error_init (&dbus_error); /* Check for moonshot server and start the service if possible. We use * libdbus here because dbus-glib doesn't handle autostarting the service. * If/when we move to GDBus this code can become a one-liner. */ if (is_setid()) { *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR, "Cannot use IPC while setid"); return NULL; } #ifdef IPC_DBUS_GLIB if (getenv("DISPLAY")==NULL) { connection = dbus_launch_moonshot(); if (connection == NULL) { *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR, "Headless dbus launch failed"); return NULL; } } else #endif { connection = dbus_g_bus_get (DBUS_BUS_SESSION, &g_error); if (g_error_matches(g_error, DBUS_GERROR, DBUS_GERROR_NOT_SUPPORTED)) { /*Generally this means autolaunch failed because probably DISPLAY is unset*/ connection = dbus_launch_moonshot(); if (connection != NULL) { g_error_free(g_error); g_error = NULL; } } if (g_error != NULL) { *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR, "DBus error: %s", g_error->message); g_error_free (g_error); return NULL; } } dbconnection = dbus_g_connection_get_connection(connection); name_has_owner = dbus_bus_name_has_owner (dbconnection, MOONSHOT_DBUS_NAME, &dbus_error); if (dbus_error_is_set (&dbus_error)) { *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR, "DBus error: %s", dbus_error.message); dbus_error_free (&dbus_error); return NULL; } if (! name_has_owner) { dbus_bus_start_service_by_name (dbconnection, MOONSHOT_DBUS_NAME, 0, NULL, &dbus_error); if (dbus_error_is_set (&dbus_error)) { if (strcmp (dbus_error.name + 27, "ServiceUnknown") == 0) { /* Missing .service file; the moonshot-ui install is broken */ *error = moonshot_error_new (MOONSHOT_ERROR_UNABLE_TO_START_SERVICE, "The Moonshot service was not found. " "Please make sure that moonshot-ui is " "correctly installed."); } else { *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR, "DBus error: %s", dbus_error.message); } dbus_error_free (&dbus_error); return NULL; } } /* Now the service should be running */ g_error = NULL; g_proxy = dbus_g_proxy_new_for_name_owner (connection, MOONSHOT_DBUS_NAME, MOONSHOT_DBUS_PATH, MOONSHOT_DBUS_NAME, &g_error); if (g_error != NULL) { *error = moonshot_error_new (MOONSHOT_ERROR_IPC_ERROR, "DBus error: %s", g_error->message); g_error_free (g_error); return NULL; } return g_proxy; }
static void sw_client_item_view_constructed (GObject *object) { SwClientItemViewPrivate *priv = GET_PRIVATE (object); GError *error = NULL; DBusConnection *conn; priv->connection = dbus_g_bus_get (DBUS_BUS_STARTER, &error); if (!priv->connection) { g_critical (G_STRLOC ": Error getting DBUS connection: %s", error->message); g_clear_error (&error); return; } conn = dbus_g_connection_get_connection (priv->connection); priv->proxy = dbus_g_proxy_new_for_name_owner (priv->connection, SW_SERVICE_NAME, priv->object_path, SW_SERVICE_ITEM_VIEW_INTERFACE, &error); if (!priv->proxy) { g_critical (G_STRLOC ": Error setting up proxy for remote object: %s", error->message); g_clear_error (&error); return; } dbus_g_proxy_add_signal (priv->proxy, "ItemsAdded", _sw_items_get_container_type (), NULL); dbus_g_proxy_connect_signal (priv->proxy, "ItemsAdded", (GCallback)_proxy_items_added_cb, object, NULL); dbus_g_proxy_add_signal (priv->proxy, "ItemsChanged", _sw_items_get_container_type (), NULL); dbus_g_proxy_connect_signal (priv->proxy, "ItemsChanged", (GCallback)_proxy_items_changed_cb, object, NULL); dbus_g_proxy_add_signal (priv->proxy, "ItemsRemoved", _sw_items_removed_get_container_type (), NULL); dbus_g_proxy_connect_signal (priv->proxy, "ItemsRemoved", (GCallback)_proxy_items_removed_cb, object, NULL); }
static void cinnamon_dbus_init (gboolean replace) { GError *error = NULL; DBusGConnection *session; DBusGProxy *bus; guint32 request_name_flags; guint32 request_name_result; /** TODO: * In the future we should use GDBus for this. However, in * order to do that, we need to port all of the JavaScript * code. Otherwise, the name will be claimed on the wrong * connection. */ session = dbus_g_bus_get (DBUS_BUS_SESSION, NULL); bus = dbus_g_proxy_new_for_name (session, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); request_name_flags = DBUS_NAME_FLAG_DO_NOT_QUEUE | DBUS_NAME_FLAG_ALLOW_REPLACEMENT; if (replace) request_name_flags |= DBUS_NAME_FLAG_REPLACE_EXISTING; if (!dbus_g_proxy_call (bus, "RequestName", &error, G_TYPE_STRING, CINNAMON_DBUS_SERVICE, G_TYPE_UINT, request_name_flags, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID)) { g_printerr ("failed to acquire org.Cinnamon: %s\n", error->message); exit (1); } if (!(request_name_result == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER || request_name_result == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER)) { g_printerr ("%s already exists on bus and --replace not specified\n", CINNAMON_DBUS_SERVICE); exit (1); } /* Also grab org.gnome.Panel to replace any existing panel process */ if (!dbus_g_proxy_call (bus, "RequestName", &error, G_TYPE_STRING, "org.gnome.Panel", G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING | request_name_flags, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID)) { g_print ("failed to acquire org.gnome.Panel: %s\n", error->message); exit (1); } /* ...and the org.gnome.Magnifier service. */ if (!dbus_g_proxy_call (bus, "RequestName", &error, G_TYPE_STRING, MAGNIFIER_DBUS_SERVICE, G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING | request_name_flags, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID)) { g_print ("failed to acquire %s: %s\n", MAGNIFIER_DBUS_SERVICE, error->message); /* Failing to acquire the magnifer service is not fatal. Log the error, * but keep going. */ } /* ...and the org.freedesktop.Notifications service; we always * specify REPLACE_EXISTING to ensure we kill off * notification-daemon if it was running. */ if (!dbus_g_proxy_call (bus, "RequestName", &error, G_TYPE_STRING, "org.freedesktop.Notifications", G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING | request_name_flags, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID)) { g_print ("failed to acquire org.freedesktop.Notifications: %s\n", error->message); } /* ...and the on-screen keyboard service */ if (!dbus_g_proxy_call (bus, "RequestName", &error, G_TYPE_STRING, "org.gnome.Caribou.Keyboard", G_TYPE_UINT, DBUS_NAME_FLAG_REPLACE_EXISTING, G_TYPE_INVALID, G_TYPE_UINT, &request_name_result, G_TYPE_INVALID)) { g_print ("failed to acquire org.gnome.Caribou.Keyboard: %s\n", error->message); } g_object_unref (bus); }
static void hd_hildon_home_dbus_init (HDHildonHomeDBus *dbus) { HDHildonHomeDBusPrivate *priv; DBusGProxy *bus_proxy; GError *error = NULL; guint result; DBusError derror; priv = dbus->priv = HD_HILDON_HOME_DBUS_GET_PRIVATE (dbus); dbus->priv->connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (error != NULL) { g_warning ("Failed to open connection to session bus: %s\n", error->message); g_error_free (error); return; } dbus_error_init (&derror); dbus->priv->sysbus_conn = dbus_bus_get (DBUS_BUS_SYSTEM, &derror); if (dbus_error_is_set (&derror)) { g_warning ("Failed to open connection to system bus: %s\n", derror.message); dbus_error_free (&derror); return; } bus_proxy = dbus_g_proxy_new_for_name (dbus->priv->connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!org_freedesktop_DBus_request_name (bus_proxy, HD_HILDON_HOME_DBUS_DBUS_NAME, DBUS_NAME_FLAG_ALLOW_REPLACEMENT | DBUS_NAME_FLAG_REPLACE_EXISTING | DBUS_NAME_FLAG_DO_NOT_QUEUE, &result, &error)) { g_warning ("Could not register name: %s", error->message); g_error_free (error); return; } g_object_unref (bus_proxy); if (result == DBUS_REQUEST_NAME_REPLY_EXISTS) return; dbus_g_object_type_install_info (HD_TYPE_HILDON_HOME_DBUS, &dbus_glib_hd_hildon_home_dbus_object_info); dbus_g_connection_register_g_object (dbus->priv->connection, HD_HILDON_HOME_DBUS_DBUS_PATH, G_OBJECT (dbus)); g_debug ("%s registered to session bus at %s", HD_HILDON_HOME_DBUS_DBUS_NAME, HD_HILDON_HOME_DBUS_DBUS_PATH); dbus->priv->hd_home_proxy = dbus_g_proxy_new_for_name (dbus->priv->connection, HD_HILDON_DESKTOP_HOME_DBUS_NAME, HD_HILDON_DESKTOP_HOME_DBUS_PATH, HD_HILDON_DESKTOP_HOME_DBUS_NAME); /* listen to shutdown_ind from DSME */ dbus_bus_add_match (dbus->priv->sysbus_conn, "type='signal', " "interface='" DSME_SIGNAL_INTERFACE "', " "member='" DSME_SHUTDOWN_SIGNAL_NAME "'", NULL); dbus_connection_add_filter (dbus->priv->sysbus_conn, hd_hildon_home_system_bus_signal_handler, NULL, NULL); /* * Create menu here so we have a window to listen for * theme changes */ priv->menu = hd_edit_mode_menu_new (); }
static void workrave_dbus_server_init() { DBusGProxy *driver_proxy; GError *err = NULL; guint request_name_result; g_return_if_fail(g_connection == NULL); g_return_if_fail(g_applet != NULL); g_connection = dbus_g_bus_get(DBUS_BUS_SESSION, &err); if (g_connection == NULL) { g_warning("DBUS Service registration failed: %s", err ? err->message : ""); g_error_free(err); return; } dbus_connection_set_exit_on_disconnect(dbus_g_connection_get_connection(g_connection), FALSE); driver_proxy = dbus_g_proxy_new_for_name(g_connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!org_freedesktop_DBus_request_name(driver_proxy, DBUS_SERVICE_APPLET, 0, &request_name_result, &err)) { g_warning("DBUS Service name request failed."); g_clear_error(&err); } if (request_name_result == DBUS_REQUEST_NAME_REPLY_EXISTS) { g_warning("DBUS Service already started elsewhere"); return; } dbus_g_object_type_install_info(WORKRAVE_APPLET_TYPE, &dbus_glib_workrave_object_info); dbus_g_connection_register_g_object(g_connection, "/org/workrave/Workrave/GnomeApplet", G_OBJECT(g_applet)); g_applet->support = dbus_g_proxy_new_for_name(g_connection, "org.workrave.Workrave.Activator", "/org/workrave/Workrave/UI", "org.workrave.GnomeAppletSupportInterface"); g_applet->ui = dbus_g_proxy_new_for_name(g_connection, "org.workrave.Workrave.Activator", "/org/workrave/Workrave/UI", "org.workrave.ControlInterface"); g_applet->core = dbus_g_proxy_new_for_name(g_connection, "org.workrave.Workrave.Activator", "/org/workrave/Workrave/Core", "org.workrave.CoreInterface"); }
int main (int argc, char *argv[]) { DBusGConnection *connection; GError *error; DBusGProxy *proxy; gchar *icon = NULL; gboolean images = FALSE; gboolean toggle_file = FALSE; gboolean toggle_wrap = FALSE; usleep (200000); g_type_init (); GOptionContext *context; GOptionEntry entries[] = { { "images", 'i', 0, G_OPTION_ARG_NONE, &images, "Use IMAGES in the viewportlist. Change the viewport icon with '-v <ICON>.'", NULL }, { "viewport-icon", 'v', 0, G_OPTION_ARG_STRING, &icon, "Use ICON/FILENAME as the viewport icon.", "ICON" }, { "wrap", 'w', 0, G_OPTION_ARG_NONE, &toggle_wrap, "Turn on viewport wrap navigation", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_summary (context, "Calls the daemon to display just a viewportlist"); error = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { g_printerr ("Failed to open connection to bus: %s\n", error->message); g_error_free (error); return 1; } proxy = dbus_g_proxy_new_for_name (connection, DESKMENU_SERVICE_DBUS, DESKMENU_PATH_DBUS, DESKMENU_INTERFACE_DBUS); error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s", error->message); g_error_free (error); return 1; } if (images) { if (icon) { toggle_file = g_regex_match_simple ("/", icon, 0, 0); } else { icon = "user-desktop"; } } if (!dbus_g_proxy_call (proxy, "vplist", &error, G_TYPE_BOOLEAN, toggle_wrap, G_TYPE_BOOLEAN, images, G_TYPE_BOOLEAN, toggle_file, G_TYPE_STRING, icon, G_TYPE_INVALID, G_TYPE_INVALID)) { g_printerr ("Error: %s\n", error->message); g_error_free (error); return 1; } g_option_context_free (context); g_object_unref (proxy); return 0; }
static void sc_plugin_ifcfg_init (SCPluginIfcfg *plugin) { SCPluginIfcfgPrivate *priv = SC_PLUGIN_IFCFG_GET_PRIVATE (plugin); NMInotifyHelper *ih; GError *error = NULL; gboolean success = FALSE; GFile *file; GFileMonitor *monitor; priv->connections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_object_unref); /* We watch SC_NETWORK_FILE via NMInotifyHelper (which doesn't track file creation but * *does* track modifications made via other hard links), since we expect it to always * exist. But we watch HOSTNAME_FILE via GFileMonitor (which has the opposite * semantics), since /etc/hostname might not exist, but is unlikely to have hard * links. bgo 532815 is the bug for being able to just use GFileMonitor for both. */ ih = nm_inotify_helper_get (); priv->ih_event_id = g_signal_connect (ih, "event", G_CALLBACK (sc_network_changed_cb), plugin); priv->sc_network_wd = nm_inotify_helper_add_watch (ih, SC_NETWORK_FILE); file = g_file_new_for_path (HOSTNAME_FILE); monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, NULL); g_object_unref (file); if (monitor) { priv->hostname_monitor_id = g_signal_connect (monitor, "changed", G_CALLBACK (hostname_changed_cb), plugin); priv->hostname_monitor = monitor; } priv->hostname = plugin_get_hostname (plugin); priv->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (!priv->bus) { _LOGW ("Couldn't connect to D-Bus: %s", error->message); g_clear_error (&error); } else { DBusConnection *tmp; DBusGProxy *proxy; int result; tmp = dbus_g_connection_get_connection (priv->bus); dbus_connection_set_exit_on_disconnect (tmp, FALSE); proxy = dbus_g_proxy_new_for_name (priv->bus, "org.freedesktop.DBus", "/org/freedesktop/DBus", "org.freedesktop.DBus"); if (!dbus_g_proxy_call (proxy, "RequestName", &error, G_TYPE_STRING, DBUS_SERVICE_NAME, G_TYPE_UINT, DBUS_NAME_FLAG_DO_NOT_QUEUE, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { _LOGW ("Couldn't acquire D-Bus service: %s", error->message); g_clear_error (&error); } else if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { _LOGW ("Couldn't acquire ifcfgrh1 D-Bus service (already taken)"); } else success = TRUE; } if (!success) { if (priv->bus) { dbus_g_connection_unref (priv->bus); priv->bus = NULL; } } }
// Setup dbus server static int thd_dbus_server_proc(gboolean no_daemon) { DBusGConnection *bus; DBusGProxy *bus_proxy; GMainLoop *main_loop; GError *error = NULL; guint result; PrefObject *value_obj; thd_engine = NULL; // Initialize the GType/GObject system g_type_init(); // Create a main loop that will dispatch callbacks g_main_loop = main_loop = g_main_loop_new(NULL, FALSE); if (main_loop == NULL) { thd_log_error("Couldn't create GMainLoop:"); return THD_FATAL_ERROR; } if (dbus_enable) { bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (error != NULL) { thd_log_error("Couldn't connect to session bus: %s:", error->message); return THD_FATAL_ERROR; } // Get a bus proxy instance bus_proxy = dbus_g_proxy_new_for_name(bus, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (bus_proxy == NULL) { thd_log_error("Failed to get a proxy for D-Bus:"); return THD_FATAL_ERROR; } thd_log_debug("Registering the well-known name (%s)\n", THD_SERVICE_NAME); // register the well-known name if (!dbus_g_proxy_call(bus_proxy, "RequestName", &error, G_TYPE_STRING, THD_SERVICE_NAME, G_TYPE_UINT, 0, G_TYPE_INVALID, G_TYPE_UINT, &result, G_TYPE_INVALID)) { thd_log_error("D-Bus.RequestName RPC failed: %s\n", error->message); return THD_FATAL_ERROR; } thd_log_debug("RequestName returned %d.\n", result); if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { thd_log_error("Failed to get the primary well-known name:"); return THD_FATAL_ERROR; } value_obj = (PrefObject*) g_object_new(PREF_TYPE_OBJECT, NULL); if (value_obj == NULL) { thd_log_error("Failed to create one Value instance:"); return THD_FATAL_ERROR; } thd_log_debug("Registering it on the D-Bus.\n"); dbus_g_connection_register_g_object(bus, THD_SERVICE_OBJECT_PATH, G_OBJECT(value_obj)); } if (!no_daemon) { printf("Ready to serve requests: Daemonizing.. %d\n", thd_daemonize); thd_log_info( "thermald ver %s: Ready to serve requests: Daemonizing..\n", TD_DIST_VERSION); if (daemon(0, 1) != 0) { thd_log_error("Failed to daemonize.\n"); return THD_FATAL_ERROR; } } thd_engine = new cthd_engine_default(); if (exclusive_control) thd_engine->set_control_mode(EXCLUSIVE); // Initialize thermald objects thd_engine->set_poll_interval(thd_poll_interval); if (thd_engine->thd_engine_start(ignore_cpuid_check) != THD_SUCCESS) { thd_log_error("THD engine start failed: "); closelog(); exit(1); } // Start service requests on the D-Bus thd_log_debug("Start main loop\n"); g_main_loop_run(main_loop); thd_log_warn("Oops g main loop exit..\n"); return THD_SUCCESS; }
static void cpufreq_selector_set_values_dbus (void) { DBusGConnection *connection; DBusGProxy *proxy; gboolean res; GError *error = NULL; connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (!connection) { g_printerr ("Couldn't connect to system bus: %s\n", error->message); g_error_free (error); return; } proxy = dbus_g_proxy_new_for_name (connection, "org.mate.CPUFreqSelector", "/org/mate/cpufreq_selector/selector", "org.mate.CPUFreqSelector"); if (!proxy) { g_printerr ("Could not construct proxy object\n"); return; } if (governor) { res = dbus_g_proxy_call (proxy, "SetGovernor", &error, G_TYPE_UINT, cpu, G_TYPE_STRING, governor, G_TYPE_INVALID, G_TYPE_INVALID); if (!res) { if (error) { g_printerr ("Error calling SetGovernor: %s\n", error->message); g_error_free (error); } else { g_printerr ("Error calling SetGovernor\n"); } g_object_unref (proxy); return; } } if (frequency != 0) { res = dbus_g_proxy_call (proxy, "SetFrequency", &error, G_TYPE_UINT, cpu, G_TYPE_UINT, frequency, G_TYPE_INVALID, G_TYPE_INVALID); if (!res) { if (error) { g_printerr ("Error calling SetFrequency: %s\n", error->message); g_error_free (error); } else { g_printerr ("Error calling SetFrequency\n"); } g_object_unref (proxy); return; } } g_object_unref (proxy); }
/* 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; }
/* adapted from PolicyKit */ static gboolean get_caller_info (GsmDBusClient *client, const char *sender, uid_t *calling_uid, pid_t *calling_pid) { gboolean res; GError *error; DBusGConnection *connection; DBusGProxy *bus_proxy; res = FALSE; bus_proxy = NULL; if (sender == NULL) { goto out; } error = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { if (error != NULL) { g_warning ("error getting session bus: %s", error->message); g_error_free (error); } goto out; } bus_proxy = dbus_g_proxy_new_for_name (connection, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); error = NULL; if (! dbus_g_proxy_call (bus_proxy, "GetConnectionUnixUser", &error, G_TYPE_STRING, sender, G_TYPE_INVALID, G_TYPE_UINT, calling_uid, G_TYPE_INVALID)) { g_debug ("GetConnectionUnixUser() failed: %s", error->message); g_error_free (error); goto out; } error = NULL; if (! dbus_g_proxy_call (bus_proxy, "GetConnectionUnixProcessID", &error, G_TYPE_STRING, sender, G_TYPE_INVALID, G_TYPE_UINT, calling_pid, G_TYPE_INVALID)) { g_debug ("GetConnectionUnixProcessID() failed: %s", error->message); g_error_free (error); goto out; } res = TRUE; g_debug ("uid = %d", *calling_uid); g_debug ("pid = %d", *calling_pid); out: if (bus_proxy != NULL) { g_object_unref (bus_proxy); } return res; }
static void dun_start (PluginInfo *info) { GError *error = NULL; GtkTreeIter iter; g_message ("%s: starting DUN device discovery...", __func__); /* Set up dbus */ info->bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error); if (error || !info->bus) { dun_error (info, __func__, error, _("could not connect to the system bus.")); g_clear_error (&error); goto out; } gtk_label_set_text (GTK_LABEL (info->label), _("Detecting phone configuration...")); /* Start the spinner */ if (!info->spinner) { info->spinner = nma_bling_spinner_new (); gtk_box_pack_start (GTK_BOX (info->hbox), info->spinner, FALSE, FALSE, 6); } nma_bling_spinner_start (BMA_BLING_SPINNER (info->spinner)); gtk_widget_show_all (info->hbox); gtk_widget_set_sensitive (info->dun_button, FALSE); /* ModemManager stuff */ info->mm_proxy = dbus_g_proxy_new_for_name (info->bus, MM_SERVICE, MM_PATH, MM_INTERFACE); g_assert (info->mm_proxy); dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, G_TYPE_BOXED, G_TYPE_INVALID); dbus_g_proxy_add_signal (info->mm_proxy, "DeviceAdded", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (info->mm_proxy, "DeviceAdded", G_CALLBACK (modem_added), info, NULL); dbus_g_proxy_add_signal (info->mm_proxy, "DeviceRemoved", DBUS_TYPE_G_OBJECT_PATH, G_TYPE_INVALID); dbus_g_proxy_connect_signal (info->mm_proxy, "DeviceRemoved", G_CALLBACK (modem_removed), info, NULL); /* Get the device we're looking for */ info->dun_proxy = NULL; if (get_device_iter (info->btmodel, info->bdaddr, &iter)) gtk_tree_model_get (info->btmodel, &iter, BLUETOOTH_COLUMN_PROXY, &info->dun_proxy, -1); if (info->dun_proxy) { info->dun_timeout_id = g_timeout_add_seconds (45, dun_timeout_cb, info); dbus_g_proxy_set_interface (info->dun_proxy, BLUEZ_SERIAL_INTERFACE); g_message ("%s: calling Connect...", __func__); /* Watch for BT device property changes */ dbus_g_object_register_marshaller (nma_marshal_VOID__STRING_BOXED, G_TYPE_NONE, G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_add_signal (info->dun_proxy, "PropertyChanged", G_TYPE_STRING, G_TYPE_VALUE, G_TYPE_INVALID); dbus_g_proxy_connect_signal (info->dun_proxy, "PropertyChanged", G_CALLBACK (dun_property_changed), info, NULL); /* Request a connection to the device and get the port */ dbus_g_proxy_begin_call_with_timeout (info->dun_proxy, "Connect", dun_connect_cb, info, NULL, 20000, G_TYPE_STRING, "dun", G_TYPE_INVALID); } else dun_error (info, __func__, error, _("could not find the Bluetooth device.")); out: g_message ("%s: finished", __func__); }
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; }
int main (int argc, char *argv[]) { DBusGConnection *connection; GError *error; DBusGProxy *proxy; gboolean images = FALSE; gboolean thisvp = FALSE; gboolean mini_only = FALSE; usleep (200000); g_type_init (); GOptionContext *context; GOptionEntry entries[] = { { "images", 'i', 0, G_OPTION_ARG_NONE, &images, "Use IMAGES in the windowlist", NULL }, { "minimized", 'm', 0, G_OPTION_ARG_NONE, &mini_only, "Show only MINIMIZED windows in the windowlist", NULL }, { "current-viewport", 'c', 0, G_OPTION_ARG_NONE, &thisvp, "Show only windows in CURRENT VIEWPORT in the windowlist", NULL }, { NULL, 0, 0, 0, NULL, NULL, NULL } }; context = g_option_context_new (NULL); g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_summary (context, "Calls the daemon to display just a windowlist"); error = NULL; connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error); if (connection == NULL) { g_printerr ("Failed to open connection to bus: %s\n", error->message); g_error_free (error); return 1; } proxy = dbus_g_proxy_new_for_name (connection, DESKMENU_SERVICE_DBUS, DESKMENU_PATH_DBUS, DESKMENU_INTERFACE_DBUS); error = NULL; if (!g_option_context_parse (context, &argc, &argv, &error)) { g_printerr ("option parsing failed: %s", error->message); g_error_free (error); return 1; } if (!dbus_g_proxy_call (proxy, "windowlist", &error, G_TYPE_BOOLEAN, images, G_TYPE_BOOLEAN, thisvp, G_TYPE_BOOLEAN, mini_only, G_TYPE_INVALID, G_TYPE_INVALID)) { g_printerr ("Error: %s\n", error->message); g_error_free (error); return 1; } g_option_context_free (context); g_object_unref (proxy); return 0; }
int main(int argc, char **argv) { GOptionContext *context; GMainLoop *loop; GError *error = NULL; FprintManager *manager; DBusGProxy *driver_proxy; guint32 request_name_ret; int r = 0; bindtextdomain (GETTEXT_PACKAGE, LOCALEDIR); bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8"); textdomain (GETTEXT_PACKAGE); context = g_option_context_new ("Fingerprint handler daemon"); g_option_context_add_main_entries (context, entries, GETTEXT_PACKAGE); g_type_init(); if (g_option_context_parse (context, &argc, &argv, &error) == FALSE) { g_print ("couldn't parse command-line options: %s\n", error->message); g_error_free (error); return 1; } if (g_fatal_warnings) { GLogLevelFlags fatal_mask; fatal_mask = g_log_set_always_fatal (G_LOG_FATAL_MASK); fatal_mask |= G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL; g_log_set_always_fatal (fatal_mask); } /* Load the configuration file, * and the default storage plugin */ if (!load_conf()) set_storage_file (); store.init (); r = fp_init(); if (r < 0) { g_error("fprint init failed with error %d\n", r); return r; } loop = g_main_loop_new(NULL, FALSE); r = setup_pollfds(); if (r < 0) { g_print("pollfd setup failed\n"); goto err; } g_print("Launching FprintObject\n"); /* Obtain a connection to the session bus */ fprintd_dbus_conn = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); if (fprintd_dbus_conn == NULL) g_error("Failed to open connection to bus: %s", error->message); /* create the one instance of the Manager object to be shared between * all fprintd users */ manager = fprint_manager_new(no_timeout); driver_proxy = dbus_g_proxy_new_for_name(fprintd_dbus_conn, DBUS_SERVICE_DBUS, DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS); if (!org_freedesktop_DBus_request_name(driver_proxy, FPRINT_SERVICE_NAME, 0, &request_name_ret, &error)) g_error("Failed to get name: %s", error->message); if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) { g_error ("Got result code %u from requesting name", request_name_ret); exit(1); } g_message("D-Bus service launched with name: %s", FPRINT_SERVICE_NAME); g_message("entering main loop"); g_main_loop_run(loop); g_message("main loop completed"); err: fp_exit(); return 0; }
RygelExternalContainer* rygel_external_container_construct (GType object_type, const char* id, const char* service_name, const char* object_path, const char* host_ip, RygelExternalContainer* parent) { #line 236 "rygel-external-container.c" GError * _inner_error_; RygelExternalContainer * self; char* _tmp0_; char* _tmp1_; char* _tmp2_; GeeArrayList* _tmp3_; #line 42 "rygel-external-container.vala" g_return_val_if_fail (id != NULL, NULL); #line 42 "rygel-external-container.vala" g_return_val_if_fail (service_name != NULL, NULL); #line 42 "rygel-external-container.vala" g_return_val_if_fail (object_path != NULL, NULL); #line 42 "rygel-external-container.vala" g_return_val_if_fail (host_ip != NULL, NULL); #line 251 "rygel-external-container.c" _inner_error_ = NULL; #line 47 "rygel-external-container.vala" self = (RygelExternalContainer*) rygel_media_container_construct (object_type, id, (RygelMediaContainer*) parent, "Uknown", 0); #line 49 "rygel-external-container.vala" self->service_name = (_tmp0_ = g_strdup (service_name), _g_free0 (self->service_name), _tmp0_); #line 50 "rygel-external-container.vala" self->priv->object_path = (_tmp1_ = g_strdup (object_path), _g_free0 (self->priv->object_path), _tmp1_); #line 51 "rygel-external-container.vala" self->host_ip = (_tmp2_ = g_strdup (host_ip), _g_free0 (self->host_ip), _tmp2_); #line 53 "rygel-external-container.vala" self->priv->containers = (_tmp3_ = gee_array_list_new (RYGEL_TYPE_EXTERNAL_CONTAINER, (GBoxedCopyFunc) g_object_ref, g_object_unref, NULL), _g_object_unref0 (self->priv->containers), _tmp3_); #line 263 "rygel-external-container.c" { DBusGConnection* connection; RygelExternalMediaContainer* _tmp4_; char* _tmp5_; #line 56 "rygel-external-container.vala" connection = dbus_g_bus_get (DBUS_BUS_SESSION, &_inner_error_); #line 270 "rygel-external-container.c" if (_inner_error_ != NULL) { goto __catch0_g_error; } #line 59 "rygel-external-container.vala" self->actual_container = (_tmp4_ = rygel_external_media_container_dbus_proxy_new (connection, service_name, object_path), _g_object_unref0 (self->actual_container), _tmp4_); #line 63 "rygel-external-container.vala" rygel_media_object_set_title ((RygelMediaObject*) self, _tmp5_ = rygel_external_media_object_get_display_name ((RygelExternalMediaObject*) self->actual_container)); #line 278 "rygel-external-container.c" _g_free0 (_tmp5_); #line 65 "rygel-external-container.vala" rygel_external_container_update_container (self, &_inner_error_); #line 282 "rygel-external-container.c" if (_inner_error_ != NULL) { _dbus_g_connection_unref0 (connection); goto __catch0_g_error; } #line 67 "rygel-external-container.vala" g_signal_connect_object (self->actual_container, "updated", (GCallback) _rygel_external_container_on_updated_rygel_external_media_container_updated, self, 0); #line 289 "rygel-external-container.c" _dbus_g_connection_unref0 (connection); } goto __finally0; __catch0_g_error: { GError * err; err = _inner_error_; _inner_error_ = NULL; { #line 69 "rygel-external-container.vala" g_critical ("rygel-external-container.vala:69: Failed to fetch information about co" \ "ntainer '%s': %s\n", ((RygelMediaObject*) self)->id, err->message); #line 301 "rygel-external-container.c" _g_error_free0 (err); } } __finally0: if (_inner_error_ != NULL) { g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _inner_error_->message, g_quark_to_string (_inner_error_->domain), _inner_error_->code); g_clear_error (&_inner_error_); return NULL; } return self; }