From 7229918a064a862c51217f1294a320c7260da937 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Tue, 24 Apr 2018 15:11:44 +0200 Subject: Initialize sources at binding start. This has changed and is now explicitly launched because last step of Controller configuration doesn't execute it. Change-Id: I104011b912172da62114b62eeab90c76e41459dd Signed-off-by: Romain Forlot --- signal-composer-binding/signal-composer-binding.cpp | 1 + signal-composer-binding/signal-composer.cpp | 17 ++++++++++++++--- signal-composer-binding/signal-composer.hpp | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp index fb99c89..7cdda91 100644 --- a/signal-composer-binding/signal-composer-binding.cpp +++ b/signal-composer-binding/signal-composer-binding.cpp @@ -279,6 +279,7 @@ int execConf() int err = 0; CtlConfigExec(nullptr, composer.ctlConfig()); + composer.initSourcesAPI(); composer.initSignals(); AFB_DEBUG("Signal Composer Control configuration Done."); diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp index c83aee6..0ee210b 100644 --- a/signal-composer-binding/signal-composer.cpp +++ b/signal-composer-binding/signal-composer.cpp @@ -295,7 +295,7 @@ int Composer::loadOneSourceAPI(json_object* sourceJ) onReceivedCtl = onReceivedJ ? convert2Action("onReceived", onReceivedJ) : nullptr; - sourcesListV_.push_back(std::make_shared(uid, api, info, initCtl, getSignalsCtl, onReceivedCtl, retention)); + newSourcesListV_.push_back(std::make_shared(uid, api, info, initCtl, getSignalsCtl, onReceivedCtl, retention)); return err; } @@ -421,7 +421,17 @@ int Composer::loadOneSignal(json_object* signalJ) } dependsV.push_back(sourceStr); } - if(!src) {src=*sourcesListV_.rbegin();} + if(!src) { + if (!sourcesListV_.empty()) + src = *sourcesListV_.rbegin(); + else if (!newSourcesListV_.empty()) + src = *newSourcesListV_.rbegin(); + else + { + AFB_WARNING("Signal '%s' not correctly attached to its source. Abort this one", json_object_to_json_string(signalJ)); + return -1; + } + } } // Set default retention if not specified @@ -644,7 +654,8 @@ CtlConfigT* Composer::ctlConfig() void Composer::initSourcesAPI() { - for(int i=0; i < newSourcesListV_.size(); i++) + size_t toInitialize = newSourcesListV_.size(); + for(int i=0; i < toInitialize; i++) { std::shared_ptr src = newSourcesListV_.back(); newSourcesListV_.pop_back(); diff --git a/signal-composer-binding/signal-composer.hpp b/signal-composer-binding/signal-composer.hpp index b3e1fed..90bd354 100644 --- a/signal-composer-binding/signal-composer.hpp +++ b/signal-composer-binding/signal-composer.hpp @@ -46,7 +46,6 @@ private: int loadOneSignal(json_object* signalsJ); static int loadSignals(AFB_ApiT apihandle, CtlSectionT* section, json_object *signalsJ); - void initSourcesAPI(); void execSignalsSubscription(); std::shared_ptr getSourceAPI(const std::string& api); void processOptions(const std::map& opts, std::shared_ptr sig, json_object* response) const; @@ -59,6 +58,7 @@ public: int loadSources(json_object* sourcesJ); int loadSignals(json_object* signalsJ); void initSignals(); + void initSourcesAPI(); CtlConfigT* ctlConfig(); std::vector> getAllSignals(); -- cgit 1.2.3-korg