summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-04-24 15:11:44 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-05 15:43:09 +0200
commit7229918a064a862c51217f1294a320c7260da937 (patch)
treeb482145bdee1c68ac59d3eeebdb2ab671c87ec48 /signal-composer-binding
parent27776f5a89ba71cb102e5c2e08b813025c55c663 (diff)
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 <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding')
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp1
-rw-r--r--signal-composer-binding/signal-composer.cpp17
-rw-r--r--signal-composer-binding/signal-composer.hpp2
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<SourceAPI>(uid, api, info, initCtl, getSignalsCtl, onReceivedCtl, retention));
+ newSourcesListV_.push_back(std::make_shared<SourceAPI>(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<SourceAPI> 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<SourceAPI> getSourceAPI(const std::string& api);
void processOptions(const std::map<std::string, int>& opts, std::shared_ptr<Signal> 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<std::shared_ptr<Signal>> getAllSignals();