コード例 #1
0
ファイル: scan.c プロジェクト: AlanApter/steamlink-sdk
static int scan_register(struct btd_service *service, struct gatt_primary *prim)
{
	struct btd_device *device = btd_service_get_device(service);
	struct scan *scan;

	scan = g_new0(struct scan, 1);
	scan->device = btd_device_ref(device);
	scan->range = prim->range;
	scan->attioid = btd_device_add_attio_callback(device,
							attio_connected_cb,
							attio_disconnected_cb,
							scan);

	btd_service_set_user_data(service, scan);

	return 0;
}
コード例 #2
0
static int csc_device_probe(struct btd_service *service)
{
	struct btd_device *device = btd_service_get_device(service);
	struct btd_adapter *adapter;
	struct csc_adapter *cadapter;
	struct csc *csc;
	struct gatt_primary *prim;

	prim = btd_device_get_primary(device, CYCLING_SC_UUID);
	if (prim == NULL)
		return -EINVAL;

	adapter = device_get_adapter(device);

	cadapter = find_csc_adapter(adapter);
	if (cadapter == NULL)
		return -1;

	csc = g_new0(struct csc, 1);
	csc->dev = btd_device_ref(device);
	csc->cadapter = cadapter;

	if (!g_dbus_register_interface(btd_get_dbus_connection(),
						device_get_path(device),
						CYCLINGSPEED_INTERFACE,
						cyclingspeed_device_methods,
						NULL,
						cyclingspeed_device_properties,
						csc, destroy_csc)) {
		error("D-Bus failed to register %s interface",
						CYCLINGSPEED_INTERFACE);
		destroy_csc(csc);
		return -EIO;
	}

	csc->svc_range = g_new0(struct att_range, 1);
	csc->svc_range->start = prim->range.start;
	csc->svc_range->end = prim->range.end;

	cadapter->devices = g_slist_prepend(cadapter->devices, csc);

	csc->attioid = btd_device_add_attio_callback(device, attio_connected_cb,
						attio_disconnected_cb, csc);

	return 0;
}
コード例 #3
0
ファイル: deviceinfo.c プロジェクト: AlanApter/steamlink-sdk
static int deviceinfo_register(struct btd_service *service,
						struct gatt_primary *prim)
{
	struct btd_device *device = btd_service_get_device(service);
	struct deviceinfo *d;

	d = g_new0(struct deviceinfo, 1);
	d->dev = btd_device_ref(device);
	d->svc_range = g_new0(struct att_range, 1);
	d->svc_range->start = prim->range.start;
	d->svc_range->end = prim->range.end;

	btd_service_set_user_data(service, d);

	d->attioid = btd_device_add_attio_callback(device, attio_connected_cb,
						attio_disconnected_cb, d);
	return 0;
}
コード例 #4
0
ファイル: server.c プロジェクト: intgr/bluez
static void filter_devices_notify(char *key, char *value, void *user_data)
{
	struct notify_data *notify_data = user_data;
	struct alert_adapter *al_adapter = notify_data->al_adapter;
	enum notify_type type = notify_data->type;
	struct btd_device *device;
	struct notify_callback *cb;

	device = get_notifiable_device(al_adapter->adapter, key, value,
						al_adapter->hnd_ccc[type]);
	if (device == NULL)
		return;

	cb = g_new0(struct notify_callback, 1);
	cb->notify_data = notify_data;
	cb->device = device;
	cb->id = btd_device_add_attio_callback(device,
						attio_connected_cb, NULL, cb);
}
コード例 #5
0
static int heartrate_device_register(struct btd_device *device,
						struct gatt_primary *prim)
{
	struct btd_adapter *adapter;
	struct heartrate_adapter *hradapter;
	struct heartrate *hr;

	adapter = device_get_adapter(device);

	hradapter = find_heartrate_adapter(adapter);

	if (hradapter == NULL)
		return -1;

	hr = g_new0(struct heartrate, 1);
	hr->dev = btd_device_ref(device);
	hr->hradapter = hradapter;

	if (!g_dbus_register_interface(btd_get_dbus_connection(),
						device_get_path(device),
						HEART_RATE_INTERFACE,
						heartrate_device_methods,
						NULL,
						heartrate_device_properties,
						hr, destroy_heartrate)) {
		error("D-Bus failed to register %s interface",
						HEART_RATE_INTERFACE);
		destroy_heartrate(hr);
		return -EIO;
	}

	hr->svc_range = g_new0(struct att_range, 1);
	hr->svc_range->start = prim->range.start;
	hr->svc_range->end = prim->range.end;

	hradapter->devices = g_slist_prepend(hradapter->devices, hr);

	hr->attioid = btd_device_add_attio_callback(device, attio_connected_cb,
						attio_disconnected_cb, hr);

	return 0;
}
コード例 #6
0
static struct hog_device *hog_device_new(struct btd_device *device,
        struct gatt_primary *prim)
{
    struct hog_device *dev;
    char name[248];
    uint16_t vendor, product, version;

    if (device_name_known(device))
        device_get_name(device, name, sizeof(name));
    else
        strcpy(name, "bluez-hog-device");

    vendor = btd_device_get_vendor(device);
    product = btd_device_get_product(device);
    version = btd_device_get_version(device);

    DBG("name=%s vendor=0x%X, product=0x%X, version=0x%X", name, vendor,
        product, version);

    dev = new0(struct hog_device, 1);
    dev->device = btd_device_ref(device);
    dev->hog = bt_hog_new_default(name, vendor, product, version, prim);

    /*
     * TODO: Remove attio callback and use .accept once using
     * bt_gatt_client.
     */
    dev->attioid = btd_device_add_attio_callback(device,
                   attio_connected_cb,
                   attio_disconnected_cb,
                   dev);

    if (!devices)
        devices = queue_new();

    queue_push_tail(devices, dev);

    return dev;
}
コード例 #7
0
ファイル: monitor.c プロジェクト: hakssung/p920ics_package
static DBusMessage *set_immediate_alert(DBusConnection *conn, DBusMessage *msg,
						const char *level, void *data)
{
	struct monitor *monitor = data;

	if (!level_is_valid(level))
		return btd_error_invalid_args(msg);

	if (g_strcmp0(monitor->immediatelevel, level) == 0)
		return dbus_message_new_method_return(msg);

	if (monitor->immediateto) {
		g_source_remove(monitor->immediateto);
		monitor->immediateto = 0;
	}

	/* Previous Immediate Alert level if connection/write fails */
	g_free(monitor->fallbacklevel);
	monitor->fallbacklevel = monitor->immediatelevel;

	monitor->immediatelevel = g_strdup(level);

	/*
	 * Means that Link/Path Loss are disabled or there is a pending
	 * writting for Find Me(Immediate Alert characteristic value).
	 * If enabled, Path Loss always registers a connection callback
	 * when the Proximity Monitor starts.
	 */
	if (monitor->attioid == 0)
		monitor->attioid = btd_device_add_attio_callback(monitor->device,
							attio_connected_cb,
							attio_disconnected_cb,
							monitor);
	else if (monitor->attrib)
		write_immediate_alert(monitor);

	return dbus_message_new_method_return(msg);
}
コード例 #8
0
ファイル: monitor.c プロジェクト: alvarofagner/bluez
static void update_monitor(struct monitor *monitor)
{
	if (monitor->txpower != NULL && monitor->immediate != NULL)
		monitor->enabled.pathloss = TRUE;
	else
		monitor->enabled.pathloss = FALSE;

	DBG("Link Loss: %s, Path Loss: %s, FindMe: %s",
				monitor->enabled.linkloss ? "TRUE" : "FALSE",
				monitor->enabled.pathloss ? "TRUE" : "FALSE",
				monitor->enabled.findme ? "TRUE" : "FALSE");

	if (!monitor->enabled.linkloss && !monitor->enabled.pathloss)
		return;

	if (monitor->attioid != 0)
		return;

	monitor->attioid = btd_device_add_attio_callback(monitor->device,
							attio_connected_cb,
							attio_disconnected_cb,
							monitor);
}
コード例 #9
0
ファイル: linkloss.c プロジェクト: richardxu/panda-a4
static uint8_t link_loss_alert_lvl_write(struct attribute *a,
		gpointer user_data, struct btd_device *device)
{
	uint8_t value;
	struct link_loss_adapter *adapter = user_data;
	GSList *l = NULL;
	struct connected_device *condev = NULL;

	if (device) {
		l = g_slist_find_custom(adapter->connected_devices, device,
					lldevice_cmp);
		if (l)
			condev = l->data;
	}

	if (a->len == 0) {
		DBG("Illegal alert level len");
		goto set_error;
	}

	value = a->data[0];
	if (value != NO_ALERT && value != MILD_ALERT && value != HIGH_ALERT) {
		DBG("Illegal alert value");
		goto set_error;
	}

	/* Register a disconnect cb if the alert level is non-zero */
	if (value != NO_ALERT && device && !condev) {
		condev = g_new0(struct connected_device, 1);
		condev->device = btd_device_ref(device);
		condev->adapter = adapter;
		condev->callback_id = btd_device_add_attio_callback(device,
					NULL, link_loss_disc_cb, condev);
		adapter->connected_devices = g_slist_append(
					adapter->connected_devices, condev);
	} else if (value == NO_ALERT && condev) {