コード例 #1
0
static void
bluez_connect_cb (GDBusConnection *dbus_connection,
                  GAsyncResult *res,
                  gpointer user_data)
{
	GSimpleAsyncResult *result = G_SIMPLE_ASYNC_RESULT (user_data);
	GObject *result_object = g_async_result_get_source_object (G_ASYNC_RESULT (result));
	NMBluezDevice *self = NM_BLUEZ_DEVICE (result_object);
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
	GError *error = NULL;
	char *device;
	GVariant *variant;

	variant = g_dbus_connection_call_finish (dbus_connection, res, &error);

	if (!variant) {
		g_simple_async_result_take_error (result, error);
	} else {
		g_variant_get (variant, "(s)", &device);

		g_simple_async_result_set_op_res_gpointer (result,
		                                           g_strdup (device),
		                                           g_free);
		priv->bt_iface = device;
		g_variant_unref (variant);
	}

	g_simple_async_result_complete (result);
	g_object_unref (result);
	g_object_unref (result_object);
}
コード例 #2
0
static void
properties_changed (GDBusProxy *proxy,
                    GVariant *changed_properties,
                    GStrv invalidated_properties,
                    gpointer user_data)
{
	NMBluezDevice *self = NM_BLUEZ_DEVICE (user_data);

	_set_properties (self, changed_properties);
	check_emit_usable (self);
}
コード例 #3
0
void
nm_bluez4_manager_query_devices (NMBluez4Manager *self)
{
	NMBluez4ManagerPrivate *priv = NM_BLUEZ4_MANAGER_GET_PRIVATE (self);
	GSList *devices, *iter;

	if (!priv->adapter)
		return;

	devices = nm_bluez4_adapter_get_devices (priv->adapter);
	for (iter = devices; iter; iter = g_slist_next (iter))
		emit_bdaddr_added (self, NM_BLUEZ_DEVICE (iter->data));
	g_slist_free (devices);
}
コード例 #4
0
static void
bluez4_property_changed (GDBusProxy *proxy,
                         const char *sender,
                         const char *signal_name,
                         GVariant   *parameters,
                         gpointer user_data)
{
	NMBluezDevice *self = NM_BLUEZ_DEVICE (user_data);

	if (g_strcmp0 (signal_name, "PropertyChanged") == 0) {
		const char *property = NULL;
		GVariant *v = NULL;

		g_variant_get (parameters, "(&sv)", &property, &v);
		_take_one_variant_property (self, property, v);
		check_emit_usable (self);
	}
}
コード例 #5
0
static void
adapter_removed (GDBusProxy *proxy, const char *path, NMBluez4Manager *self)
{
	NMBluez4ManagerPrivate *priv = NM_BLUEZ4_MANAGER_GET_PRIVATE (self);

	if (priv->adapter && !strcmp (path, nm_bluez4_adapter_get_path (priv->adapter))) {
		if (nm_bluez4_adapter_get_initialized (priv->adapter)) {
			GSList *devices, *iter;

			devices = nm_bluez4_adapter_get_devices (priv->adapter);
			for (iter = devices; iter; iter = g_slist_next (iter))
				g_signal_emit_by_name (NM_BLUEZ_DEVICE (iter->data), NM_BLUEZ_DEVICE_REMOVED);
			g_slist_free (devices);
		}

		g_object_unref (priv->adapter);
		priv->adapter = NULL;
	}
}
コード例 #6
0
static void
get_properties_cb (DBusGProxy *proxy, DBusGProxyCall *call, gpointer user_data)
{
	NMBluezDevice *self = NM_BLUEZ_DEVICE (user_data);
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
	GHashTable *properties = NULL;
	GError *err = NULL;
	GValue *value;
	const char **uuids;

	if (!dbus_g_proxy_end_call (proxy, call, &err,
	                            DBUS_TYPE_G_MAP_OF_VARIANT, &properties,
	                            G_TYPE_INVALID)) {
		nm_log_warn (LOGD_BT, "bluez error getting device properties: %s",
		             err && err->message ? err->message : "(unknown)");
		g_error_free (err);
		g_signal_emit (self, signals[INITIALIZED], 0, FALSE);
		return;
	}

	value = g_hash_table_lookup (properties, "Address");
	priv->address = value ? g_value_dup_string (value) : NULL;

	value = g_hash_table_lookup (properties, "Name");
	priv->name = value ? g_value_dup_string (value) : NULL;

	value = g_hash_table_lookup (properties, "RSSI");
	priv->rssi = value ? g_value_get_int (value) : 0;

	value = g_hash_table_lookup (properties, "UUIDs");
	if (value) {
		uuids = (const char **) g_value_get_boxed (value);
		priv->capabilities = convert_uuids_to_capabilities (uuids);
	} else
		priv->capabilities = NM_BT_CAPABILITY_NONE;

	g_hash_table_unref (properties);

	priv->initialized = TRUE;
	g_signal_emit (self, signals[INITIALIZED], 0, TRUE);

	check_emit_usable (self);
}
コード例 #7
0
static void
bluez_disconnect_cb (GDBusConnection *dbus_connection,
                     GAsyncResult *res,
                     gpointer user_data)
{
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (user_data);
	GError *error = NULL;
	GVariant *variant;

	variant = g_dbus_connection_call_finish (dbus_connection, res, &error);
	if (!variant) {
		if (!strstr (error->message, "org.bluez.Error.NotConnected"))
			nm_log_warn (LOGD_BT, "bluez[%s]: failed to disconnect: %s", priv->path, error->message);
		g_error_free (error);
	} else
		g_variant_unref (variant);

	g_object_unref (NM_BLUEZ_DEVICE (user_data));
}
コード例 #8
0
static void
get_properties_cb_4 (GObject *source_object, GAsyncResult *res, gpointer user_data)
{
	NMBluezDevice *self = NM_BLUEZ_DEVICE (user_data);
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
	GError *err = NULL;
	GVariant *v_properties, *v_dict;
	GVariantType *v_type;

	v_properties = g_dbus_proxy_call_finish (priv->proxy, res, &err);
	if (!v_properties) {
		nm_log_warn (LOGD_BT, "bluez[%s] error getting device properties: %s",
		             priv->path, err && err->message ? err->message : "(unknown)");
		g_error_free (err);
		g_signal_emit (self, signals[INITIALIZED], 0, FALSE);
		goto END;
	}

	v_type = g_variant_type_new ("(a{sv})");
	if (g_variant_is_of_type (v_properties, v_type)) {
		v_dict = g_variant_get_child_value (v_properties, 0);
		_set_properties (self, v_dict);
		g_variant_unref (v_dict);
	} else {
		nm_log_warn (LOGD_BT, "bluez[%s] GetProperties returns unexpected result of type %s", priv->path, g_variant_get_type_string (v_properties));
	}
	g_variant_type_free (v_type);

	g_variant_unref (v_properties);

	/* Check if any connections match this device */
	load_connections (self);

	priv->initialized = TRUE;
	g_signal_emit (self, signals[INITIALIZED], 0, TRUE);


	check_emit_usable (self);

END:
	g_object_unref (self);
}
コード例 #9
0
static void
adapter_initialized (NMBluez4Adapter *adapter, gboolean success, gpointer user_data)
{
	NMBluez4Manager *self = NM_BLUEZ4_MANAGER (user_data);
	NMBluez4ManagerPrivate *priv = NM_BLUEZ4_MANAGER_GET_PRIVATE (self);

	if (success) {
		GSList *devices, *iter;

		devices = nm_bluez4_adapter_get_devices (adapter);
		for (iter = devices; iter; iter = g_slist_next (iter))
			emit_bdaddr_added (self, NM_BLUEZ_DEVICE (iter->data));
		g_slist_free (devices);

		g_signal_connect (adapter, "device-added", G_CALLBACK (device_added), self);
		g_signal_connect (adapter, "device-removed", G_CALLBACK (device_removed), self);
	} else {
		g_object_unref (priv->adapter);
		priv->adapter = NULL;
	}
}
コード例 #10
0
static void
property_changed (DBusGProxy *proxy,
                  const char *property,
                  GValue *value,
                  gpointer user_data)
{
	NMBluezDevice *self = NM_BLUEZ_DEVICE (user_data);
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
	const char *str;
	guint32 uint_val;
	gint int_val;

	if (!strcmp (property, "Name")) {
		str = g_value_get_string (value);
		if (   (!priv->name && str)
		    || (priv->name && !str)
		    || (priv->name && str && strcmp (priv->name, str))) {
			g_free (priv->name);
			priv->name = g_strdup (str);
			g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_NAME);
		}
	} else if (!strcmp (property, "RSSI")) {
		int_val = g_value_get_int (value);
		if (priv->rssi != int_val) {
			priv->rssi = int_val;
			g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_RSSI);
		}
	} else if (!strcmp (property, "UUIDs")) {
		uint_val = convert_uuids_to_capabilities ((const char **) g_value_get_boxed (value));
		if (priv->capabilities != uint_val) {
			priv->capabilities = uint_val;
			g_object_notify (G_OBJECT (self), NM_BLUEZ_DEVICE_CAPABILITIES);
		}
	}

	check_emit_usable (self);
}
コード例 #11
0
static void
dispose (GObject *object)
{
	NMBluezDevice *self = NM_BLUEZ_DEVICE (object);
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
	NMConnection *to_delete = NULL;

	if (priv->pan_connection) {
		/* Check whether we want to remove the created connection. If so, we take a reference
		 * and delete it at the end of dispose(). */
		if (   nm_settings_connection_get_unsaved (NM_SETTINGS_CONNECTION (priv->pan_connection))
		    && nm_connection_compare (priv->pan_connection, priv->pan_connection_original, NM_SETTING_COMPARE_FLAG_EXACT))
			to_delete = g_object_ref (priv->pan_connection);

		priv->pan_connection = NULL;
		g_clear_object (&priv->pan_connection_original);
	}

	g_signal_handlers_disconnect_by_func (priv->provider, cp_connection_added, self);
	g_signal_handlers_disconnect_by_func (priv->provider, cp_connection_removed, self);
	g_signal_handlers_disconnect_by_func (priv->provider, cp_connection_updated, self);

	g_slist_free_full (priv->connections, g_object_unref);
	priv->connections = NULL;

	g_clear_object (&priv->adapter5);
	g_clear_object (&priv->dbus_connection);

	G_OBJECT_CLASS (nm_bluez_device_parent_class)->dispose (object);

	if (to_delete) {
		nm_log_dbg (LOGD_BT, "bluez[%s] removing Bluetooth connection for NAP device: '%s' (%s)", priv->path,
		            nm_connection_get_id (to_delete), nm_connection_get_uuid (to_delete));
		nm_settings_connection_delete (NM_SETTINGS_CONNECTION (to_delete), NULL, NULL);
		g_object_unref (to_delete);
	}
}
コード例 #12
0
static void
adapter_removed (DBusGProxy *proxy, const char *path, NMBluezManager *self)
{
    NMBluezManagerPrivate *priv = NM_BLUEZ_MANAGER_GET_PRIVATE (self);

    if (priv->adapter && !strcmp (path, nm_bluez_adapter_get_path (priv->adapter))) {
        if (nm_bluez_adapter_get_initialized (priv->adapter)) {
            GSList *devices, *iter;

            devices = nm_bluez_adapter_get_devices (priv->adapter);
            for (iter = devices; iter; iter = g_slist_next (iter)) {
                NMBluezDevice *device = NM_BLUEZ_DEVICE (iter->data);

                g_signal_emit (self, signals[BDADDR_REMOVED], 0,
                               nm_bluez_device_get_address (device),
                               nm_bluez_device_get_path (device));
            }
            g_slist_free (devices);
        }

        g_object_unref (priv->adapter);
        priv->adapter = NULL;
    }
}
コード例 #13
0
static void
adapter5_on_properties_changed (GDBusProxy *proxy,
                                GVariant *changed_properties,
                                GStrv invalidated_properties,
                                gpointer user_data)
{
	NMBluezDevice *self = NM_BLUEZ_DEVICE (user_data);
	NMBluezDevicePrivate *priv = NM_BLUEZ_DEVICE_GET_PRIVATE (self);
	GVariantIter i;
	const char *property;
	GVariant *v;

	g_variant_iter_init (&i, changed_properties);
	while (g_variant_iter_next (&i, "{&sv}", &property, &v)) {
		if (!strcmp (property, "Powered") && VARIANT_IS_OF_TYPE_BOOLEAN (v)) {
			gboolean powered = g_variant_get_boolean (v);
			if (priv->adapter_powered != powered)
				priv->adapter_powered = powered;
		}
		g_variant_unref (v);
	}

	check_emit_usable (self);
}