summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-12-11 14:41:04 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-12-11 18:30:14 +0100
commite21e7421988fde2023a1dc53cb151ba4f2adfe20 (patch)
tree40c91ae802ea4fd6bb557c3bf7f5a3fab8be474f
parente815fdaec657810c9ee8f33dc943dd5e9b7dab5f (diff)
hal-bt: Use another verb to get adapter number.flounder_6.0.3flounder/6.0.36.0.3
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 <jonathan.aillet@iot.bzh>
-rw-r--r--plugins/lib/bluetooth/hal-bt.c34
-rw-r--r--plugins/lib/bluetooth/hal-bt.h1
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"