diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-09-15 16:29:17 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-14 11:00:25 +0100 |
commit | 677cde6288a4574b8251a4a532b1d9e1594b09b2 (patch) | |
tree | c510a0cdd76e2b8de1cdaf254fd270c8bfebae42 /signal-composer-binding/source.cpp | |
parent | eabae24ea592420de46e36f0b1af5d39eee5b8a4 (diff) |
Subscription by plugin to signals
Change-Id: Icb923f87df2be8eb664106bc9077b3a8221dd3ce
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/source.cpp')
-rw-r--r-- | signal-composer-binding/source.cpp | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp index 6e7fec2..80c59d6 100644 --- a/signal-composer-binding/source.cpp +++ b/signal-composer-binding/source.cpp @@ -33,19 +33,39 @@ void SourceAPI::addSignal(const std::string& id, std::vector<std::string>& sourc { std::shared_ptr<Signal> sig = std::make_shared<Signal>(id, sources, unit, frequency, onReceived); - signals_.push_back(sig); + signalsList_.push_back(sig); } std::vector<std::shared_ptr<Signal>> SourceAPI::getSignals() const { - return signals_; + return signalsList_; } std::shared_ptr<Signal> SourceAPI::searchSignal(const std::string& name) const { - for (auto& sig: signals_) + for (auto& sig: signalsList_) { if(*sig == name) {return sig;} } return nullptr; } + +int SourceAPI::makeSubscription() const +{ + int err = 0; + if(getSignal_) + { + for(std::shared_ptr<Signal> sig: signalsList_) + { + json_object* lowSignalNameJ = sig->toJSON(); + if(!lowSignalNameJ) + { + AFB_ERROR("Error building JSON query object to subscribe to for signal %s", sig->id().c_str()); + return -1; + } + err += ActionExecOne(getSignal_, lowSignalNameJ); + } + } + + return err; +} |