diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-09-19 01:17:28 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-14 11:00:25 +0100 |
commit | f4fba8a2744991ff8c5cb8af4a67c7d9456f1057 (patch) | |
tree | 352231c9342344599ec2af08ef82495deefb238f /signal-composer-binding/source.cpp | |
parent | 9f61a83961cdbf133fdeb80cb978e6c79f4a9547 (diff) |
Modification about conf definition
- Argument for each signal subscription. (getSignalsArgs)
- differentiation between Signal as raw signal from another API
and virtual signal depending upon other signals
- changing way to specify function with uri that specify everythings
that could be needed to invoke a function.
Change-Id: I8917c5ae3c2c1e3fa48ddfdda41fc75eaba32bb7
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 | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp index 80c59d6..1f5d588 100644 --- a/signal-composer-binding/source.cpp +++ b/signal-composer-binding/source.cpp @@ -20,8 +20,8 @@ SourceAPI::SourceAPI() {} -SourceAPI::SourceAPI(const std::string& api, const std::string& info, CtlActionT* init, CtlActionT* getSignal): - api_(api), info_(info), init_(init), getSignal_(getSignal) +SourceAPI::SourceAPI(const std::string& api, const std::string& info, CtlActionT* init, CtlActionT* getSignals): + api_(api), info_(info), init_(init), getSignals_(getSignals) {} std::string SourceAPI::api() const @@ -29,41 +29,51 @@ std::string SourceAPI::api() const return api_; } -void SourceAPI::addSignal(const std::string& id, std::vector<std::string>& sources, const std::string& sClass, const std::string& unit, double frequency, CtlActionT* onReceived) +void SourceAPI::addSignal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& sClass, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs) { - std::shared_ptr<Signal> sig = std::make_shared<Signal>(id, sources, unit, frequency, onReceived); + std::shared_ptr<Signal> sig = std::make_shared<Signal>(id, event, depends, unit, frequency, onReceived, getSignalsArgs); - signalsList_.push_back(sig); + signalsMap_[sig] = false; } std::vector<std::shared_ptr<Signal>> SourceAPI::getSignals() const { - return signalsList_; + std::vector<std::shared_ptr<Signal>> signals; + for (auto& sig: signalsMap_) + { + signals.push_back(sig.first); + } + return signals; } std::shared_ptr<Signal> SourceAPI::searchSignal(const std::string& name) const { - for (auto& sig: signalsList_) + for (auto& sig: signalsMap_) { - if(*sig == name) {return sig;} + if(*sig.first == name) {return sig.first;} } return nullptr; } -int SourceAPI::makeSubscription() const +int SourceAPI::makeSubscription() { int err = 0; - if(getSignal_) + if(getSignals_) { - for(std::shared_ptr<Signal> sig: signalsList_) + for(auto& sig: signalsMap_) { - json_object* lowSignalNameJ = sig->toJSON(); - if(!lowSignalNameJ) + json_object* signalJ = sig.first->toJSON(); + if(!signalJ) { - AFB_ERROR("Error building JSON query object to subscribe to for signal %s", sig->id().c_str()); - return -1; + AFB_ERROR("Error building JSON query object to subscribe to for signal %s", sig.first->id().c_str()); + err = -1; + break; } - err += ActionExecOne(getSignal_, lowSignalNameJ); + err += sig.second ? 0:ActionExecOne(getSignals_, signalJ); + if(err) + {AFB_WARNING("Fails to subscribe to signal %s", sig.first->id().c_str());} + else + {sig.second = true;} } } |