summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-09-12 19:25:29 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:57:27 +0200
commit2828b18b33dee47cebd72c4f7800e99d7ceb2149 (patch)
tree02b29161be5d2706086eeffb17c45a1024aa2de4
parentc5d3dee7873e53c907efdcc232770568d3c635dc (diff)
Handle error send by Bluetooth-Manager
Handle error send by 'Bluetooth-Manager' when no bluetooth devices are detected by discorvery. Change-Id: Iadd2ef7dbd5aff59da62e50f99622a9aaf2627dc Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--plugins/lib/bluetooth/hal-bt.c27
1 files changed, 18 insertions, 9 deletions
diff --git a/plugins/lib/bluetooth/hal-bt.c b/plugins/lib/bluetooth/hal-bt.c
index 04a1f10..a6c51a2 100644
--- a/plugins/lib/bluetooth/hal-bt.c
+++ b/plugins/lib/bluetooth/hal-bt.c
@@ -76,11 +76,11 @@ CTLP_ONLOAD(plugin, callbacks)
// Call at contoller onload time
CTLP_CAPI(init, source, argsJ, queryJ)
{
- unsigned int err;
+ int err;
char *returnedInfo;
- json_object *toSendJ, *returnedJ, *returnedBtList;
+ json_object *toSendJ, *returnedJ, *returnedBtList = NULL;
if(! localHalBtPluginData.halBtPluginEnabled) {
AFB_ApiWarning(source->api, "Controller onload initialization of HAL-BT plugin cannot be done because bluetooth is not reachable");
@@ -169,13 +169,22 @@ CTLP_CAPI(init, source, argsJ, queryJ)
json_object_put(returnedJ);
if(AFB_ServiceSync(source->api, BT_MANAGER_API, BT_MANAGER_GET_DEVICES_VERB, NULL, &returnedJ)) {
- AFB_ApiError(source->api,
- "Error during call to verb '%s' of '%s' api (%s)",
- BT_MANAGER_GET_DEVICES_VERB,
- BT_MANAGER_API,
- json_object_get_string(returnedJ));
+ if((! wrap_json_unpack(returnedJ, "{s:{s:s}}", "request", "info", &returnedInfo)) &&
+ (! strncmp(returnedInfo, "No find devices", strlen(returnedInfo)))) {
+ AFB_ApiInfo(source->api,
+ "No bluetooth devices returned by call to verb '%s' of '%s' api",
+ BT_MANAGER_GET_DEVICES_VERB,
+ BT_MANAGER_API);
+ }
+ else {
+ AFB_ApiError(source->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 -7;
+ return -7;
+ }
}
else if(wrap_json_unpack(returnedJ, "{s:{s:o}}", "response", "list", &returnedBtList)) {
AFB_ApiError(source->api,
@@ -186,7 +195,7 @@ CTLP_CAPI(init, source, argsJ, queryJ)
return -7;
}
- if((err = HalBtDataHandleReceivedMutlipleBtDeviceData(&localHalBtPluginData, returnedBtList)))
+ if((returnedBtList) && (err = HalBtDataHandleReceivedMutlipleBtDeviceData(&localHalBtPluginData, returnedBtList)))
return (10 * err);
json_object_put(returnedJ);