static void
default_adapter_cb (GObject *proxy, GAsyncResult *result, gpointer user_data)
{
	NMBluez4Manager *self = NM_BLUEZ4_MANAGER (user_data);
	NMBluez4ManagerPrivate *priv = NM_BLUEZ4_MANAGER_GET_PRIVATE (self);
	GVariant *ret;
	GError *err = NULL;

	ret = _nm_dbus_proxy_call_finish (G_DBUS_PROXY (proxy), result,
	                                  G_VARIANT_TYPE ("(o)"), &err);
	if (ret) {
		const char *default_adapter;

		g_variant_get (ret, "(&o)", &default_adapter);
		default_adapter_changed (priv->proxy, default_adapter, self);
		g_variant_unref (ret);
	} else {
		/* Ignore "No such adapter" errors; just means bluetooth isn't active */
		if (   !_nm_dbus_error_has_name (err, "org.bluez.Error.NoSuchAdapter")
		    && !_nm_dbus_error_has_name (err, "org.freedesktop.systemd1.LoadFailed")
		    && !g_error_matches (err, G_DBUS_ERROR, G_DBUS_ERROR_SERVICE_UNKNOWN)) {
			g_dbus_error_strip_remote_error (err);
			nm_log_warn (LOGD_BT, "bluez error getting default adapter: %s",
			             err->message);
		}
		g_error_free (err);
	}
}
Beispiel #2
0
int setup_agents(void)
{
	dbus_g_error_domain_register(AGENT_ERROR, "org.bluez.Error",
							AGENT_ERROR_TYPE);

	client = bluetooth_client_new();
	g_signal_connect (G_OBJECT (client), "notify::default-adapter",
			  G_CALLBACK (default_adapter_changed), NULL);
	default_adapter_changed (G_OBJECT (client), NULL, NULL);

	return 0;
}
static void
default_adapter_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
{
    NMBluezManager *self = NM_BLUEZ_MANAGER (user_data);
    NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE (self);
    const char *default_adapter = NULL;
    GError *err = NULL;

    if (!dbus_g_proxy_end_call (proxy, call, &err,
                                DBUS_TYPE_G_OBJECT_PATH, &default_adapter,
                                G_TYPE_INVALID)) {
        nm_log_warn (LOGD_BT, "bluez error getting default adapter: %s",
                     err && err->message ? err->message : "(unknown)");
        g_error_free (err);
        return;
    }

    default_adapter_changed (priv->proxy, default_adapter, self);
}
static void
bluetooth_chooser_button_init (BluetoothChooserButton *button)
{
	gtk_button_set_label (GTK_BUTTON (button), _("Click to select device..."));

	button->image = gtk_image_new ();
	gtk_button_set_image (GTK_BUTTON (button), button->image);

	button->bdaddr = NULL;
	button->dialog = NULL;

	button->client = bluetooth_client_new ();
	g_signal_connect (G_OBJECT (button->client), "notify::default-adapter",
			  G_CALLBACK (default_adapter_changed), button);
	g_signal_connect (G_OBJECT (button->client), "notify::default-adapter-powered",
			  G_CALLBACK (default_adapter_changed), button);

	/* And set the default value already */
	default_adapter_changed (NULL, NULL, button);

	set_btdevname (button, NULL, NULL, NULL);
}