Exemplo n.º 1
0
static struct monitor *register_monitor(struct btd_device *device)
{
	const char *path = device_get_path(device);
	struct monitor *monitor;
	char *level;

	monitor = find_monitor(device);
	if (monitor != NULL)
		return monitor;

	level = read_proximity_config(device, "LinkLossAlertLevel");

	monitor = g_new0(struct monitor, 1);
	monitor->device = btd_device_ref(device);
	monitor->linklosslevel = (level ? : g_strdup("high"));
	monitor->signallevel = g_strdup("unknown");
	monitor->immediatelevel = g_strdup("none");

	monitors = g_slist_append(monitors, monitor);

	if (g_dbus_register_interface(btd_get_dbus_connection(), path,
				PROXIMITY_INTERFACE,
				NULL, NULL, monitor_device_properties,
				monitor, monitor_destroy) == FALSE) {
		error("D-Bus failed to register %s interface",
						PROXIMITY_INTERFACE);
		monitor_destroy(monitor);
		return NULL;
	}

	DBG("Registered interface %s on path %s", PROXIMITY_INTERFACE, path);

	return monitor;
}
Exemplo n.º 2
0
int monitor_register(DBusConnection *conn, struct btd_device *device,
		struct att_primary *linkloss, struct att_primary *txpower,
		struct att_primary *immediate, struct enabled *enabled)
{
	const char *path = device_get_path(device);
	struct monitor *monitor;
	bdaddr_t sba, dba;
	char *level;

	adapter_get_address(device_get_adapter(device), &sba);
	device_get_address(device, &dba);

	level = read_proximity_config(&sba, &dba, "LinkLossAlertLevel");

	monitor = g_new0(struct monitor, 1);
	monitor->device = btd_device_ref(device);
	monitor->conn = dbus_connection_ref(conn);
	monitor->linklosslevel = (level ? : g_strdup("high"));
	monitor->signallevel = g_strdup("unknown");
	monitor->immediatelevel = g_strdup("none");

	if (g_dbus_register_interface(conn, path,
				PROXIMITY_INTERFACE,
				monitor_methods, monitor_signals,
				NULL, monitor, monitor_destroy) == FALSE) {
		error("D-Bus failed to register %s interface",
						PROXIMITY_INTERFACE);
		monitor_destroy(monitor);
		return -1;
	}

	DBG("Registered interface %s on path %s", PROXIMITY_INTERFACE, path);

	if (linkloss && enabled->linkloss) {
		monitor->linkloss = g_new0(struct att_range, 1);
		monitor->linkloss->start = linkloss->start;
		monitor->linkloss->end = linkloss->end;

		monitor->enabled.linkloss = TRUE;
	}