static GtkWidget *
get_config_widgets (const char *bdaddr, const char **uuids)
{
	WidgetInfo *info;
	NmaBtDevice *device;
	GtkWidget *vbox, *hbox;
	gboolean pan = FALSE, dun = FALSE, busy;
	GtkTreeIter iter;
	BluetoothClient *btclient;
	GtkTreeModel *btmodel;
	guint id;

	/* Don't allow configuration if NM isn't running; it just confuses people
	 * if they see the checkboxes but the configuration doesn't seem to have
	 * any visible effect since they aren't running NM/nm-applet.
	 */
	if (!nm_is_running ())
		return NULL;

	get_capabilities (bdaddr, uuids, &pan, &dun);
	if (!pan && !dun)
		return NULL;

	/* BluetoothClient setup */
	btclient = bluetooth_client_new ();
	btmodel = bluetooth_client_get_model (btclient);
	g_assert (btmodel);

	device = get_device (bdaddr);
	if (!device) {
		const char *op = NULL;
		gpointer proxy;
		char *alias;

		if (!get_device_iter (btmodel, bdaddr, &iter)) {
			g_warning ("%s: failed to retrieve device %s from gnome-bluetooth!", __func__, bdaddr);
			g_object_unref (btmodel);
			g_object_unref (btclient);
			return NULL;
		}

		gtk_tree_model_get (btmodel, &iter,
		                    BLUETOOTH_COLUMN_ALIAS, &alias,
		                    BLUETOOTH_COLUMN_PROXY, &proxy,
		                    -1);
		g_assert (proxy);

		/* At some point gnome-bluetooth switched to gdbus, so we don't know
		* if the proxy will be a DBusGProxy (dbus-glib) or a GDBusProxy (gdbus).
		*/
		if (G_IS_DBUS_PROXY (proxy))
			op = g_dbus_proxy_get_object_path (G_DBUS_PROXY (proxy));
		else if (DBUS_IS_G_PROXY (proxy))
			op = dbus_g_proxy_get_path (DBUS_G_PROXY (proxy));
		else
			g_assert_not_reached ();

		device = nma_bt_device_new (bdaddr, alias, op, pan, dun);
		g_free (alias);
		g_object_unref (proxy);

		if (!device) {
			g_warning ("%s: failed to create Bluetooth proxy object!", bdaddr);
			g_object_unref (btmodel);
			g_object_unref (btclient);
			return NULL;
		}

		add_device (device);
	}

	info = g_malloc0 (sizeof (WidgetInfo));
	info->device = g_object_ref (device);
	info->btclient = btclient;

	g_signal_connect (G_OBJECT (btclient), "notify::default-adapter",
	                  G_CALLBACK (default_adapter_changed), info);
	g_signal_connect (G_OBJECT (btclient), "notify::default-adapter-powered",
	                  G_CALLBACK (default_adapter_powered_changed), info);

	id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_PAN_ENABLED,
	                       G_CALLBACK (device_pan_enabled_cb), info);
	info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id));

	id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_DUN_ENABLED,
	                       G_CALLBACK (device_dun_enabled_cb), info);
	info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id));

	id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_BUSY,
	                       G_CALLBACK (device_busy_cb), info);
	info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id));

	id = g_signal_connect (device, "notify::" NMA_BT_DEVICE_STATUS,
	                       G_CALLBACK (device_status_cb), info);
	info->sigids = g_slist_prepend (info->sigids, GUINT_TO_POINTER (id));

	/* UI setup */
#if GTK_CHECK_VERSION (3,1,6)
	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
#else
	vbox = gtk_vbox_new (FALSE, 6);
#endif
	g_object_set_data_full (G_OBJECT (vbox), "info", info, widget_info_destroy);

	busy = nma_bt_device_get_busy (device);

	if (pan) {
		info->pan_button = gtk_check_button_new_with_label (_("Use your mobile phone as a network device (PAN/NAP)"));
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->pan_button),
		                              nma_bt_device_get_pan_enabled (device));
		info->pan_toggled_id = g_signal_connect (G_OBJECT (info->pan_button), "toggled", G_CALLBACK (pan_button_toggled), info);
		gtk_box_pack_start (GTK_BOX (vbox), info->pan_button, FALSE, TRUE, 6);
		gtk_widget_set_sensitive (info->pan_button, !busy);
	}

	if (dun) {
		info->dun_button = gtk_check_button_new_with_label (_("Access the Internet using your mobile phone (DUN)"));
		gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (info->dun_button),
		                              nma_bt_device_get_dun_enabled (device));
		info->dun_toggled_id = g_signal_connect (G_OBJECT (info->dun_button), "toggled", G_CALLBACK (dun_button_toggled), info);
		gtk_box_pack_start (GTK_BOX (vbox), info->dun_button, FALSE, TRUE, 6);
		set_dun_button_sensitive (info, !busy);
	}

#if GTK_CHECK_VERSION (3,1,6)
	hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
#else
	hbox = gtk_hbox_new (FALSE, 6);
#endif
	gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, TRUE, 6);

	/* Spinner's hbox */
#if GTK_CHECK_VERSION (3,1,6)
	info->hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
#else
	info->hbox = gtk_hbox_new (FALSE, 6);
#endif
	gtk_box_pack_start (GTK_BOX (hbox), info->hbox, FALSE, FALSE, 0);

	device_busy_cb (device, NULL, info);

	/* Status label */
	info->status = gtk_label_new (nma_bt_device_get_status (device));
	gtk_label_set_max_width_chars (GTK_LABEL (info->status), 80);
	gtk_label_set_line_wrap (GTK_LABEL (info->status), TRUE);
	gtk_box_pack_start (GTK_BOX (hbox), info->status, FALSE, TRUE, 6);

	default_adapter_powered_changed (G_OBJECT (info->btclient), NULL, info);

	return vbox;
}
Example #2
0
gint
main (gint    argc,
      gchar **argv)
{
    g_type_init ();
    g_test_init (&argc, &argv, NULL);
#if 0
    g_test_add_func ("/ibus/list-engines", test_list_engines);
    g_test_add_func ("/ibus/list-active-engines", test_list_active_engines);
#endif
    return g_test_run ();
#if 0
    IBusBus *bus;
    GList *engines;
    gchar *active_engine_name;

    bus = ibus_bus_new ();

    if (ibus_bus_get_use_global_engine (bus)) {
        g_debug ("use_global_engine is true.");
        if (ibus_bus_is_global_engine_enabled (bus)) {
        g_debug ("Global engine is enabled.");
        IBusEngineDesc *global_engine = ibus_bus_get_global_engine (bus);
        g_assert (global_engine);
        g_debug ("%s (id:%s, icon:%s)", global_engine->longname,
             global_engine->name, global_engine->icon);
        g_object_unref (global_engine);
        }
    }

    g_debug ("===== Use system layout:%s", ibus_bus_get_use_sys_layout (bus) ? "true" : "false");

    g_debug ("Test ibusbus.c: passed.");

    /* Test ibusinputcontext.c */
#if 1
    {
        IBusInputContext *context;
        IBusEngineDesc *engine_desc;
        gchar *current_ic;
        context = ibus_bus_create_input_context (bus, "test");
        ibus_input_context_set_capabilities (context, IBUS_CAP_FOCUS);
        ibus_input_context_disable (context);
        g_assert (ibus_input_context_is_enabled (context) == FALSE);
        ibus_input_context_enable (context);
        g_assert (ibus_input_context_is_enabled (context) == TRUE);
        ibus_input_context_focus_in (context);
        ibus_input_context_set_engine (context, active_engine_name);
        current_ic = ibus_bus_current_input_context (bus);
        g_assert (!strcmp (current_ic, g_dbus_proxy_get_object_path ((GDBusProxy *)context)));
        engine_desc = ibus_input_context_get_engine (context);
        g_assert (engine_desc);
        g_assert (!strcmp (active_engine_name, engine_desc->name));
        g_debug ("Test ibusinputcontext.c: passed.");

        g_free (active_engine_name);
        g_free (current_ic);
        g_object_unref (engine_desc);
        g_object_unref (context);
    }
#endif
    g_object_unref (bus);
#endif
    return 0;
}
/* Get DBus object path */
const gchar *heart_rate_manager_get_dbus_object_path(HeartRateManager *self)
{
    g_assert(HEART_RATE_MANAGER_IS(self));
    g_assert(self->priv->proxy != NULL);
    return g_dbus_proxy_get_object_path(self->priv->proxy);
}
Example #4
0
static gboolean
cockpit_object_proxy_update (CockpitObjectProxy *self,
                             GList *interfaces_to_add,
                             GList *interfaces_to_remove)
{
  const gchar *iface_name;
  GList *removed = NULL;
  GList *added = NULL;
  GList *l;

  g_return_val_if_fail (COCKPIT_IS_OBJECT_PROXY (self), FALSE);

  /*
   * First we update the object, then we emit the signals. In the
   * the future we'll need to eliminate races with use of generations.
   */

  for (l = interfaces_to_add; l != NULL; l = g_list_next (l))
    {
      iface_name = g_dbus_proxy_get_interface_name (l->data);
      if (!g_hash_table_lookup (self->interfaces, iface_name))
        {
          g_debug ("fakemanager: interface-added: %s: %s",
                   g_dbus_proxy_get_object_path (l->data), iface_name);
          g_hash_table_insert (self->interfaces, (gpointer)iface_name,
                               g_object_ref (l->data));
          added = g_list_prepend (added, l->data);
          g_signal_connect (l->data, "g-signal", G_CALLBACK (on_proxy_signal), self);
          g_signal_connect (l->data, "g-properties-changed", G_CALLBACK (on_properties_changed), self);
        }
    }

  for (l = interfaces_to_remove; l != NULL; l = g_list_next (l))
    {
      iface_name = g_dbus_proxy_get_interface_name (l->data);

      /*
       * TODO: If we start allowing concurrent pokes for the same object path
       * then we'll need to double check here that we're removing the right
       * interface from the hash table.
       */

      /* Caller holds a reference so this is safe */
      if (g_hash_table_remove (self->interfaces, iface_name))
        {
          g_debug ("fakemanager: interface-removed: %s: %s",
                   g_dbus_proxy_get_object_path (l->data), iface_name);
          removed = g_list_prepend (removed, l->data);
          g_signal_handlers_disconnect_by_func (l->data, on_proxy_signal, self);
          g_signal_handlers_disconnect_by_func (l->data, on_properties_changed, self);
        }
    }

  for (l = added; l != NULL; l = g_list_next (l))
    {
      g_signal_emit (self, sig_object__interface_added, 0, l->data);
      if (self->manager)
        g_signal_emit (self->manager, sig_manager__interface_added, 0, self, l->data);
    }
  g_list_free (added);

  for (l = removed; l != NULL; l = g_list_next (l))
    {
      g_signal_emit (self, sig_object__interface_removed, 0, l->data);
      if (self->manager)
        g_signal_emit (self->manager, sig_manager__interface_removed, 0, self, l->data);
    }
  g_list_free (removed);

  return g_hash_table_size (self->interfaces) > 0;
}
Example #5
0
static GList * CAPeripheralInitializeGattServices(CALEContext * context)
{
    GList * result = NULL;

    /*
      Create a proxies to the org.bluez.GattManager1 D-Bus objects that
      will later be used to register the OIC GATT service.
    */
    GList * gatt_managers = NULL;
    if (!CAGetBlueZManagedObjectProxies(&gatt_managers,
                                        BLUEZ_GATT_MANAGER_INTERFACE,
                                        context,
                                        NULL))
        return result;

    GList * gatt_services = NULL;

    for (GList * l = gatt_managers; l != NULL; )
    {
        CAGattService * const service = OICCalloc(1, sizeof(*service));

        if (service == NULL)
        {
            g_list_free_full(gatt_services,
                             CAPeripheralDestroyGattServices);
            g_list_free_full(gatt_managers, g_object_unref);
            return result;
        }

        /*
          Use the HCI device name (e.g. hci0) in GattManager1 object
          path (e.g. /org/bluez/hci0) as a means to differentiate the
          GATT service hierarchy for each GattManager1 object.
        */
        GDBusProxy * const manager = G_DBUS_PROXY(l->data);
        char const * const path = g_dbus_proxy_get_object_path(manager);

        /*
          The return value will actually be a pointer to a substring
          starting with the '/' before the HCI name.  We add 1 later
          on to skip that character.
        */
        char const * const hci_name = strrchr(path, '/');

        if (hci_name == NULL
            || !CAGattServiceInitialize(service, hci_name + 1, context))
        {
            g_list_free_full(gatt_services,
                             CAPeripheralDestroyGattServices);
            g_list_free_full(gatt_managers, g_object_unref);
            return result;
        }

        service->gatt_manager = manager;

        /*
          The GattManager1 proxy is now owned by the CAGattService
          object.
        */

        GList * const tmp = l;
        l = l->next;
        gatt_managers = g_list_delete_link(gatt_managers, tmp);

        // Prepend for efficiency.
        gatt_services = g_list_prepend(gatt_services, service);
    }

    result = gatt_services;

    return result;
}
Example #6
0
static bool CAPeripheralRegisterAdvertisements(
    CAPeripheralContext * context)
{
    bool success = false;

    /*
      Register the OIC LE advertisement service with each BlueZ
      LE Advertisement Manager.
    */

    ca_mutex_lock(context->lock);

    char const * const advertisement_path =
        g_dbus_interface_skeleton_get_object_path(
            G_DBUS_INTERFACE_SKELETON(
                context->advertisement.advertisement));

    GList * managers = context->advertisement.managers;

    for (GList * l = managers; l != NULL; )
    {
        GDBusProxy * const manager = G_DBUS_PROXY(l->data);

        /**
         * @c org.bluez.LEAdvertisingManager1.RegisterService()
         * accepts two parameters: the advertisement object path, and
         * an options dictionary.  No options are used so pass a NULL
         * pointer to reflect an empty dictionary.
         *
         *  @todo The parameters don't change between loop iterations.
         *        Ideally we should initialize this variable before
         *        the loop is executed, but g_dbus_proxy_call_sync()
         *        takes ownership of the variant.  Is there anyway to
         *        create a non-floating GVariant and pass it to that
         *        function?
         */
        GVariant * const parameters =
            g_variant_new("(oa{sv})", advertisement_path, NULL);

        GError * error = NULL;

        GVariant * const ret =
            g_dbus_proxy_call_sync(
                manager,
                "RegisterAdvertisement",
                parameters,
                G_DBUS_CALL_FLAGS_NONE,
                -1,    // timeout (default == -1),
                NULL,  // cancellable
                &error);

        if (ret == NULL)
        {
            OIC_LOG_V(WARNING,
                      TAG,
                      "LE advertisement registration on %s failed: %s",
                      g_dbus_proxy_get_object_path(manager),
                      error->message);

            g_error_free(error);

            // We can't use the LE advertising manager.  Drop it.
            g_object_unref(manager);

            GList * const tmp = l;
            l = l->next;
            managers = g_list_delete_link(managers, tmp);

            continue;
        }

        g_variant_unref(ret);

        /*
          Note that we can do this in the for-statement because of
          the similar code in the error case above.
        */
        l = l->next;
    }

    // Use the updated list of managers.
    context->advertisement.managers = managers;

    if (managers == NULL)   // Empty
    {
        OIC_LOG(ERROR,
                TAG,
                "LE advertisment registration failed for all "
                "Bluetooth adapters.");
    }
    else
    {

        success = true;
    }

    ca_mutex_unlock(context->lock);

    return success;
}
Example #7
0
/* Get DBus object path */
const gchar *network_get_dbus_object_path(Network *self)
{
	g_assert(NETWORK_IS(self));
	g_assert(self->priv->proxy != NULL);
	return g_dbus_proxy_get_object_path(self->priv->proxy);
}
Example #8
0
/* Get DBus object path */
const gchar *health_device_get_dbus_object_path(HealthDevice *self)
{
	g_assert(HEALTH_DEVICE_IS(self));
	g_assert(self->priv->proxy != NULL);
	return g_dbus_proxy_get_object_path(self->priv->proxy);
}