From 2828b18b33dee47cebd72c4f7800e99d7ceb2149 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Wed, 12 Sep 2018 19:25:29 +0200 Subject: 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 --- plugins/lib/bluetooth/hal-bt.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) (limited to 'plugins/lib/bluetooth/hal-bt.c') 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); -- cgit 1.2.3-korg