summaryrefslogtreecommitdiffstats
path: root/plugins/lib
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-09-19 12:08:34 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:57:27 +0200
commit07ac2284bdceae1d7ee75fe799da3285aedc3229 (patch)
treef6a1c372271bbd511c1db90df8849b29d47f32cb /plugins/lib
parent2026507973e610be8dac306f4a0adbda449e465f (diff)
hal-bt: Check presence of a bluetooth receiver
Disable hal-bt plugin if no bluetooth receiver is connected at plugin initialization. To be bale to check if there is no connected bluetooth receiver, use call to 'power' verb of 'Bluetooth-Manager' api. Change-Id: Idd301d2106e8b2e79e25969cc2c1a2a4e4194711 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'plugins/lib')
-rw-r--r--plugins/lib/bluetooth/hal-bt.c31
-rw-r--r--plugins/lib/bluetooth/hal-bt.h1
2 files changed, 27 insertions, 5 deletions
diff --git a/plugins/lib/bluetooth/hal-bt.c b/plugins/lib/bluetooth/hal-bt.c
index 8ad2d86..ecb0f03 100644
--- a/plugins/lib/bluetooth/hal-bt.c
+++ b/plugins/lib/bluetooth/hal-bt.c
@@ -53,9 +53,11 @@ CTLP_INIT(plugin, callbacks)
{
unsigned int idx;
+ char *returnedInfo;
+
CtlConfigT *ctrlConfig;
- json_object *actionsToAdd;
+ json_object *actionsToAdd, *returnedJ;
AFB_ApiInfo(plugin->api, "Plugin initialization of HAL-BT plugin");
@@ -74,6 +76,25 @@ CTLP_INIT(plugin, callbacks)
return -2;
}
+ if(AFB_ServiceSync(plugin->api, BT_MANAGER_API, BT_MANAGER_GET_POWER_INFO, NULL, &returnedJ)) {
+ if((! wrap_json_unpack(returnedJ, "{s:{s:s}}", "request", "info", &returnedInfo)) &&
+ (! strncmp(returnedInfo, "Unable to get power status", strlen(returnedInfo)))) {
+ AFB_ApiWarning(plugin->api,
+ "No bluetooth receiver detected when calling verb '%s' of '%s' api, bluetooth is disable because not reachable",
+ BT_MANAGER_GET_POWER_INFO,
+ BT_MANAGER_API);
+ return 0;
+ }
+ else {
+ AFB_ApiError(plugin->api,
+ "Error during call to verb '%s' of '%s' api (%s)",
+ BT_MANAGER_GET_POWER_INFO,
+ BT_MANAGER_API,
+ json_object_get_string(returnedJ));
+ return -3;
+ }
+ }
+
wrap_json_pack(&actionsToAdd, "{s:s s:s}",
"uid", "Bluetooth-Manager/device_updated",
"action", "plugin://hal-bt#events");
@@ -85,13 +106,13 @@ CTLP_INIT(plugin, callbacks)
if(! ctrlConfig->sections[idx].key) {
AFB_ApiError(plugin->api, "Wasn't able to add '%s' as a new event, 'events' section not found", json_object_get_string(actionsToAdd));
json_object_put(actionsToAdd);
- return -3;
+ return -4;
}
if(AddActionsToSectionFromPlugin(plugin->api, *ctrlConfig->ctlPlugins, &ctrlConfig->sections[idx], actionsToAdd, 0)) {
AFB_ApiError(plugin->api, "Wasn't able to add '%s' as a new event to %s", json_object_get_string(actionsToAdd), ctrlConfig->sections[idx].key);
json_object_put(actionsToAdd);
- return -4;
+ return -5;
}
wrap_json_pack(&actionsToAdd, "{s:s s:s s:s}",
@@ -106,13 +127,13 @@ CTLP_INIT(plugin, callbacks)
if(! ctrlConfig->sections[idx].key) {
AFB_ApiError(plugin->api, "Wasn't able to add '%s' as a new onload, 'onload' section not found", json_object_get_string(actionsToAdd));
json_object_put(actionsToAdd);
- return -5;
+ return -6;
}
if(AddActionsToSectionFromPlugin(plugin->api, *ctrlConfig->ctlPlugins, &ctrlConfig->sections[idx], actionsToAdd, 0)) {
AFB_ApiError(plugin->api, "Wasn't able to add '%s' as a new onload to %s", json_object_get_string(actionsToAdd), ctrlConfig->sections[idx].uid);
json_object_put(actionsToAdd);
- return -6;
+ return -7;
}
localHalBtPluginData.halBtPluginEnabled = 1;
diff --git a/plugins/lib/bluetooth/hal-bt.h b/plugins/lib/bluetooth/hal-bt.h
index ad94a7e..af5f6c3 100644
--- a/plugins/lib/bluetooth/hal-bt.h
+++ b/plugins/lib/bluetooth/hal-bt.h
@@ -25,6 +25,7 @@
#define HAL_BT_PLUGIN_NAME "hal-bt"
#define BT_MANAGER_API "Bluetooth-Manager"
+#define BT_MANAGER_GET_POWER_INFO "power"
#define BT_MANAGER_SUBSCRIBE_VERB "subscribe"
#define BT_MANAGER_GET_DEVICES_VERB "discovery_result"