aboutsummaryrefslogtreecommitdiffstats
path: root/binding/bluetooth-api.c
diff options
context:
space:
mode:
authorMatt Ranostay <matt.ranostay@konsulko.com>2018-11-23 14:24:18 -0800
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2018-12-07 12:14:43 +0000
commitdc504cf7676cdca0a2816750d1d287dc2350fbd0 (patch)
treedf081e01f190109a3137f85a63d366df5e7aac95 /binding/bluetooth-api.c
parent1fb7a01eb655bbe1c72a3502c2aa59f27dd3d8dc (diff)
binding: bluetooth: add default_adapter verb
Allow setting of default adapter for use by other verbs within the binding. This allows to select an adapter on boards with more than one. Bug-AGL: SPEC-1630 Change-Id: Iec77b0abaa9f4c092dc5c827522efb1744953fce Signed-off-by: Matt Ranostay <matt.ranostay@konsulko.com>
Diffstat (limited to 'binding/bluetooth-api.c')
-rw-r--r--binding/bluetooth-api.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/binding/bluetooth-api.c b/binding/bluetooth-api.c
index bc2a4a4..23ce55d 100644
--- a/binding/bluetooth-api.c
+++ b/binding/bluetooth-api.c
@@ -43,7 +43,7 @@
*/
static GThread *global_thread;
-static struct bluetooth_state *bluetooth_get_userdata(afb_req_t request) {
+struct bluetooth_state *bluetooth_get_userdata(afb_req_t request) {
afb_api_t api = afb_req_get_api(request);
return afb_api_get_userdata(api);
}
@@ -575,6 +575,7 @@ static int init(afb_api_t api)
{
struct init_data init_data, *id = &init_data;
gint64 end_time;
+ int ret;
memset(id, 0, sizeof(*id));
id->init_done = FALSE;
@@ -583,6 +584,12 @@ static int init(afb_api_t api)
g_cond_init(&id->cond);
g_mutex_init(&id->mutex);
+ ret = afb_daemon_require_api("persistence", 1);
+ if (ret < 0) {
+ AFB_ERROR("Cannot request data persistence service");
+ return ret;
+ }
+
global_thread = g_thread_new("agl-service-bluetooth",
bluetooth_func,
id);
@@ -609,6 +616,8 @@ static int init(afb_api_t api)
else
AFB_INFO("bluetooth-binding operational");
+ id->ns->default_adapter = get_default_adapter(id->api);
+
return id->rc;
}
@@ -702,7 +711,7 @@ static void bluetooth_state(afb_req_t request)
json_object *jresp;
const char *adapter = afb_req_value(request, "adapter");
- adapter = BLUEZ_ROOT_PATH(adapter ? adapter : BLUEZ_DEFAULT_ADAPTER);
+ adapter = BLUEZ_ROOT_PATH(adapter ? adapter : ns->default_adapter);
jresp = adapter_properties(ns, &error, adapter);
if (!jresp) {
@@ -721,7 +730,7 @@ static void bluetooth_adapter(afb_req_t request)
const char *adapter = afb_req_value(request, "adapter");
const char *scan, *discoverable, *powered, *filter;
- adapter = BLUEZ_ROOT_PATH(adapter ? adapter : BLUEZ_DEFAULT_ADAPTER);
+ adapter = BLUEZ_ROOT_PATH(adapter ? adapter : ns->default_adapter);
scan = afb_req_value(request, "discovery");
if (scan) {
@@ -815,6 +824,27 @@ static void bluetooth_adapter(afb_req_t request)
bluetooth_state(request);
}
+static void bluetooth_default_adapter(afb_req_t request)
+{
+ struct bluetooth_state *ns = bluetooth_get_userdata(request);
+ const char *adapter = afb_req_value(request, "adapter");
+ json_object *jresp = json_object_new_object();
+
+ call_work_lock(ns);
+ if (adapter) {
+ set_default_adapter(afb_req_get_api(request), adapter);
+
+ if (ns->default_adapter)
+ g_free(ns->default_adapter);
+ ns->default_adapter = g_strdup(adapter);
+ }
+
+ json_object_object_add(jresp, "adapter", json_object_new_string(ns->default_adapter));
+ call_work_unlock(ns);
+
+ afb_req_success(request, jresp, "Bluetooth - default adapter");
+}
+
static void connect_service_callback(void *user_data,
GVariant *result, GError **error)
{
@@ -1207,6 +1237,11 @@ static const struct afb_verb_v3 bluetooth_verbs[] = {
.callback = bluetooth_adapter,
.info = "Set adapter mode and retrieve properties"
}, {
+ .verb = "default_adapter",
+ .session = AFB_SESSION_NONE,
+ .callback = bluetooth_default_adapter,
+ .info = "Set default adapter for commands"
+ }, {
.verb = "connect",
.session = AFB_SESSION_NONE,
.callback = bluetooth_connect_device,