diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-11-29 19:32:01 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-14 11:00:26 +0100 |
commit | 01bf5e6e309c12475e1bf2d58f3b72e64f7a5add (patch) | |
tree | 84467dd9b5b4a7b7cfc71a8e96101514182766b7 /signal-composer-binding/signal-composer.cpp | |
parent | 9a2620f02ce35edd6420f77643c7f64f132d62c1 (diff) |
Update and use latest ctl-utilities.
Controller will now handle loading additional files
from section.
Context retrieving change a bit, now we have source context
and plugin context.
Update json unpacking and packing.
Cleaning, format.
Change-Id: Ie7a4721f6b703796a0dac1a236922427f4755dc5
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal-composer.cpp')
-rw-r--r-- | signal-composer-binding/signal-composer.cpp | 49 |
1 files changed, 10 insertions, 39 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp index e46c57f..b8d5504 100644 --- a/signal-composer-binding/signal-composer.cpp +++ b/signal-composer-binding/signal-composer.cpp @@ -96,7 +96,7 @@ CtlActionT* Composer::convert2Action(const std::string& name, json_object* actio json_object *functionArgsJ = nullptr, *ctlActionJ = nullptr; char *function; const char *plugin; - CtlActionT *ctlAction = nullptr; + CtlActionT *ctlAction = new CtlActionT; if(actionJ && !wrap_json_unpack(actionJ, "{ss,s?s,s?o !}", "function", &function, @@ -173,25 +173,6 @@ CtlActionT* Composer::convert2Action(const std::string& name, json_object* actio return ctlAction; } -void Composer::loadAdditionnalFiles(json_object* filesJ) -{ - std::vector<std::string> files; - if(filesJ) - { - wrap_json_optarray_for_all(filesJ, extractString, (void*)&files); - if(! files.empty()) - { - for(const auto& oneFile: files) - { - std::string filepath = CtlConfigSearch(nullptr, CONTROL_CONFIG_PATH, oneFile.c_str()); - json_object* oneFileJ = json_object_from_file(filepath.c_str()); - if(oneFileJ) - {loadSourcesAPI(nullptr, nullptr, oneFileJ);} - } - } - } -} - /// @brief Add the builtin plugin in the default plugins section definition /// /// @param[in] section - Control Section structure @@ -232,24 +213,22 @@ int Composer::loadOneSourceAPI(json_object* sourceJ) { json_object *initJ = nullptr, *getSignalsJ = nullptr, - *onReceivedJ = nullptr, - *filesJ = nullptr; + *onReceivedJ = nullptr; CtlActionT *initCtl = nullptr, *getSignalsCtl = nullptr, *onReceivedCtl = nullptr; - const char *api, *info; + const char *uid, *api, *info; int retention = 0; int err = wrap_json_unpack(sourceJ, "{ss,s?s,s?o,s?o,s?o,s?i,s?o !}", + "uid", &uid, "api", &api, "info", &info, "init", &initJ, "getSignals", &getSignalsJ, // Signals field to make signals conf by sources "onReceived", &onReceivedJ, - "retention", &retention, - // External files to load where lies others sources obj - "files", &filesJ); + "retention", &retention); if (err) { AFB_ERROR("Missing something api|[info]|[init]|[getSignals] in %s", json_object_get_string(sourceJ)); @@ -277,9 +256,6 @@ int Composer::loadOneSourceAPI(json_object* sourceJ) onReceivedCtl = onReceivedJ ? convert2Action("onReceived", onReceivedJ) : nullptr; sourcesListV_.push_back(std::make_shared<SourceAPI>(api, info, initCtl, getSignalsCtl, onReceivedCtl, retention)); - - loadAdditionnalFiles(filesJ); - return err; } @@ -290,14 +266,14 @@ int Composer::loadSourcesAPI(AFB_ApiT apihandle, CtlSectionT* section, json_obje if(sourcesJ) { - AFB_ApiNotice("Sources JSON: %s", json_object_to_json_string(sourcesJ)); json_object *sigCompJ = nullptr; // add the signal composer itself as source wrap_json_pack(&sigCompJ, "{ss,ss}", "api", afbBindingV2.api, "info", "Api on behalf the virtual signals are sent"); - json_object_array_add(sourcesJ, sigCompJ); + if(json_object_is_type(sourcesJ, json_type_array)) + json_object_array_add(sourcesJ, sigCompJ); if (json_object_get_type(sourcesJ) == json_type_array) { @@ -326,8 +302,7 @@ int Composer::loadOneSignal(json_object* signalJ) { json_object *onReceivedJ = nullptr, *dependsJ = nullptr, - *getSignalsArgs = nullptr, - *filesJ = nullptr; + *getSignalsArgs = nullptr; CtlActionT* onReceivedCtl; const char *id = nullptr, *event = nullptr, @@ -339,16 +314,14 @@ int Composer::loadOneSignal(json_object* signalJ) std::shared_ptr<SourceAPI> src = nullptr; int err = wrap_json_unpack(signalJ, "{ss,s?s,s?o,s?o,s?F,s?s,s?F,s?o !}", - "id", &id, + "uid", &id, "event", &event, "depends", &dependsJ, "getSignalsArgs", &getSignalsArgs, "retention", &retention, "unit", &unit, "frequency", &frequency, - "onReceived", &onReceivedJ, - // External files to load where lies others sources obj - "files", &filesJ); + "onReceived", &onReceivedJ); if (err) { AFB_ERROR("Missing something id|[event|depends]|[getSignalsArgs]|[retention]|[unit]|[frequency]|[onReceived] in %s", json_object_get_string(signalJ)); @@ -436,8 +409,6 @@ int Composer::loadOneSignal(json_object* signalJ) else {err = -1;} - loadAdditionnalFiles(filesJ); - return err; } |