From e21e7421988fde2023a1dc53cb151ba4f2adfe20 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Tue, 11 Dec 2018 14:41:04 +0100 Subject: hal-bt: Use another verb to get adapter number. Use 'managed_objects' verb of 'Bluetooth-Manager' api to get adapter number. Before this change, some errors were not detected correctly. Bug-AGL: SPEC-1986 Change-Id: I0f2e697c9b4aef58aa50c3ea85359670961f7d6b Signed-off-by: Jonathan Aillet --- plugins/lib/bluetooth/hal-bt.c | 34 +++++++++++++++++----------------- plugins/lib/bluetooth/hal-bt.h | 1 - 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/plugins/lib/bluetooth/hal-bt.c b/plugins/lib/bluetooth/hal-bt.c index 1a53c0d..96ca080 100644 --- a/plugins/lib/bluetooth/hal-bt.c +++ b/plugins/lib/bluetooth/hal-bt.c @@ -50,7 +50,7 @@ CTLP_INIT(plugin, callbacks) unsigned int idx; char *btStreamZone; - struct json_object *returnedState; + struct json_object *returnedAdapters; CtlConfigT *ctrlConfig; @@ -81,22 +81,22 @@ CTLP_INIT(plugin, callbacks) return -3; } - if(AFB_ServiceSync(plugin->api, BT_MANAGER_API, BT_MANAGER_GET_ADAPTER_INFO, NULL, &returnedJ)) { - if(wrap_json_unpack(returnedJ, "{s:{s:b}}", "response", "powered", &returnedState)) { - AFB_ApiWarning(plugin->api, - "No bluetooth receiver detected when calling verb '%s' of '%s' api, bluetooth is disabled because not reachable", - BT_MANAGER_GET_ADAPTER_INFO, - BT_MANAGER_API); - return 0; - } - else { - AFB_ApiError(plugin->api, - "Error during call to verb '%s' of '%s' api (%s)", - BT_MANAGER_GET_ADAPTER_INFO, - BT_MANAGER_API, - json_object_get_string(returnedJ)); - return -4; - } + if(AFB_ServiceSync(plugin->api, BT_MANAGER_API, BT_MANAGER_GET_DEVICES_VERB, NULL, &returnedJ) || + wrap_json_unpack(returnedJ, "{s:{s:o}}", "response", "adapters", &returnedAdapters) || + (! json_object_is_type(returnedAdapters, json_type_array))) { + AFB_ApiError(plugin->api, + "Error during call to verb '%s' of '%s' api (%s)", + BT_MANAGER_GET_DEVICES_VERB, + BT_MANAGER_API, + json_object_get_string(returnedJ)); + return -4; + } + else if(! json_object_array_length(returnedAdapters)) { + AFB_ApiWarning(plugin->api, + "No bluetooth receiver detected when calling verb '%s' of '%s' api, bluetooth is disabled because not reachable", + BT_MANAGER_GET_DEVICES_VERB, + BT_MANAGER_API); + return 0; } if((! json_object_is_type(plugin->paramsJ, json_type_object)) || diff --git a/plugins/lib/bluetooth/hal-bt.h b/plugins/lib/bluetooth/hal-bt.h index 120c166..f4e2a48 100644 --- a/plugins/lib/bluetooth/hal-bt.h +++ b/plugins/lib/bluetooth/hal-bt.h @@ -25,7 +25,6 @@ #define HAL_BT_PLUGIN_NAME "hal-bt" #define BT_MANAGER_API "Bluetooth-Manager" -#define BT_MANAGER_GET_ADAPTER_INFO "adapter_state" #define BT_MANAGER_SUBSCRIBE_VERB "subscribe" #define BT_MANAGER_GET_DEVICES_VERB "managed_objects" -- cgit 1.2.3-korg