aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-09-26 20:27:00 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:57:27 +0200
commit19e4a3cd29f3e4d49ce8c484ab471eaee4d22753 (patch)
tree606bf5af21cc694fe584c1ad57871f543cfc13a7
parent40b5fca57111f5dba5487b8e7d5160c68afdb830 (diff)
hl-bt: Check that hal is available in init
In hal-bluetooth plugin, check that hal is available in plugin initialization. Move every data initialization after that everything is checked. Change-Id: I8055dd17e75099a8009f21a1070d1de293682d4b Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--plugins/lib/bluetooth/hal-bt.c25
1 files changed, 16 insertions, 9 deletions
diff --git a/plugins/lib/bluetooth/hal-bt.c b/plugins/lib/bluetooth/hal-bt.c
index 1fb4180..a4791e1 100644
--- a/plugins/lib/bluetooth/hal-bt.c
+++ b/plugins/lib/bluetooth/hal-bt.c
@@ -38,12 +38,6 @@ CTLP_CAPI_REGISTER(HAL_BT_PLUGIN_NAME)
// Call at initialisation time
CTLP_ONLOAD(plugin, callbacks)
{
- AFB_ApiInfo(plugin->api, "%s Plugin Registering: uid='%s' 'info='%s'", HAL_BT_PLUGIN_NAME, plugin->uid, plugin->info);
-
- memset(&localHalBtPluginData, '\0', sizeof(localHalBtPluginData));
-
- localHalBtPluginData.currentHalApiHandle = plugin->api;
-
AFB_ApiNotice(plugin->api, "%s Plugin Registered correctly: uid='%s' 'info='%s'", HAL_BT_PLUGIN_NAME, plugin->uid, plugin->info);
return 0;
@@ -59,6 +53,8 @@ CTLP_INIT(plugin, callbacks)
CtlConfigT *ctrlConfig;
+ struct SpecificHalData *currentHalData;
+
json_object *actionsToAdd, *returnedJ, *halMixerJ, *halOrigCaptureJ, *halNewCaptureJ, *halOrigStreamJ, *halNewStreamJ, *btCaptureJ, *btCaptureParamsJ, *btStreamJ;
AFB_ApiInfo(plugin->api, "Plugin initialization of %s plugin", HAL_BT_PLUGIN_NAME);
@@ -73,13 +69,13 @@ CTLP_INIT(plugin, callbacks)
return -1;
}
- if(! (localHalBtPluginData.currentHalData = (struct SpecificHalData *) ctrlConfig->external)) {
+ if(! (currentHalData = (struct SpecificHalData *) ctrlConfig->external)) {
AFB_ApiError(plugin->api, "Can't get current hal controller data");
return -2;
}
- if((! localHalBtPluginData.currentHalData->ctlHalSpecificData) ||
- (! (halMixerJ = localHalBtPluginData.currentHalData->ctlHalSpecificData->halMixerJ))) {
+ if((! currentHalData->ctlHalSpecificData) ||
+ (! (halMixerJ = currentHalData->ctlHalSpecificData->halMixerJ))) {
AFB_ApiError(plugin->api, "Can't get current hal mixer json section");
return -3;
}
@@ -113,6 +109,17 @@ CTLP_INIT(plugin, callbacks)
"uid", "Bluetooth-Manager/device_updated",
"action", "plugin://hal-bt#events");
+ if(currentHalData->status != HAL_STATUS_AVAILABLE) {
+ AFB_ApiWarning(plugin->api, "Controller initialization of %s plugin cannot be done because hal is not ready to be used", HAL_BT_PLUGIN_NAME);
+ return 0;
+ }
+
+ memset(&localHalBtPluginData, '\0', sizeof(localHalBtPluginData));
+
+ localHalBtPluginData.currentHalApiHandle = plugin->api;
+
+ localHalBtPluginData.currentHalData = currentHalData;
+
idx = 0;
while(ctrlConfig->sections[idx].key && strcasecmp(ctrlConfig->sections[idx].key, "events"))
idx++;