summaryrefslogtreecommitdiffstats
path: root/plugins/lib/bluetooth/hal-bt.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-09-11 18:44:48 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:57:27 +0200
commit8326170cafb0e3493c7df6acb799e0ecb70ef803 (patch)
treebf0d65314a7c3d5aee4f1bf36918a00b03e63fbd /plugins/lib/bluetooth/hal-bt.c
parentbce96da92113890e2634e837a98c3565aa143102 (diff)
Add ctl actions needed by Hal-Bt in plugin init
Add controller events/onloads actions needed by Hal-Bt plugin in plugin initialization ('CTLP_INIT'). Therefore, these actions can be reomved from json files. Change-Id: I67391abfc7d3fd0f8b9d4fbd0fe8698497da1393 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'plugins/lib/bluetooth/hal-bt.c')
-rw-r--r--plugins/lib/bluetooth/hal-bt.c69
1 files changed, 65 insertions, 4 deletions
diff --git a/plugins/lib/bluetooth/hal-bt.c b/plugins/lib/bluetooth/hal-bt.c
index a6c51a2..0e84b3d 100644
--- a/plugins/lib/bluetooth/hal-bt.c
+++ b/plugins/lib/bluetooth/hal-bt.c
@@ -65,10 +65,71 @@ CTLP_ONLOAD(plugin, callbacks)
AFB_ApiNotice(plugin->api, "Hal-Bt Plugin Registered correctly: uid='%s' 'info='%s'", plugin->uid, plugin->info);
- /* TDB JAI :
- - Register 'init' plugin function (HAL_BT_PLUGIN_NAME#init) as onload action here (to avoid adding it in json)
- - Register 'event' plugin function (HAL_BT_PLUGIN_NAME#event) as action for BT_MANAGER_API#BT_MANAGER_DEVICE_UPDATE_EVENT event here (to avoid adding it in json)
- */
+ return 0;
+}
+
+CTLP_INIT(plugin, callbacks)
+{
+ unsigned int idx;
+
+ CtlConfigT *ctrlConfig;
+
+ json_object *actionsToAdd;
+
+ if(! localHalBtPluginData.halBtPluginEnabled) {
+ AFB_ApiWarning(plugin->api, "Plugin initialization of HAL-BT plugin cannot be done because bluetooth is not reachable");
+ return 0;
+ }
+
+ AFB_ApiInfo(plugin->api, "Plugin initialization of HAL-BT plugin");
+
+ if(! (ctrlConfig = (CtlConfigT *) afb_dynapi_get_userdata(plugin->api))) {
+ AFB_ApiError(plugin->api, "Can't get current hal controller config");
+ return -1;
+ }
+
+ wrap_json_pack(&actionsToAdd, "{s:s s:s}",
+ "uid", "Bluetooth-Manager/device_updated",
+ "action", "plugin://hal-bt#events");
+
+ idx = 0;
+ while(ctrlConfig->sections[idx].key && strcasecmp(ctrlConfig->sections[idx].key, "events"))
+ idx++;
+
+ 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 -2;
+ }
+
+ 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 -3;
+ }
+
+ wrap_json_pack(&actionsToAdd, "{s:s s:s s:s}",
+ "uid", "init-bt-plugin",
+ "info", "Init Bluetooth hal plugin",
+ "action", "plugin://hal-bt#init");
+
+ idx = 0;
+ while(ctrlConfig->sections[idx].key && strcasecmp(ctrlConfig->sections[idx].key, "onload"))
+ idx++;
+
+ 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 -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 onload to %s", json_object_get_string(actionsToAdd), ctrlConfig->sections[idx].uid);
+ json_object_put(actionsToAdd);
+ return -5;
+ }
+
+ AFB_ApiNotice(plugin->api, "Plugin initialization of HAL-BT plugin correctly done");
return 0;
}