diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-09-25 18:29:48 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-14 11:00:25 +0100 |
commit | b7dd0a6e19d5387bc8d499bd1b3a99d457fa58d9 (patch) | |
tree | 0d1a26964435e8f91b96713e2b5beb3c1e94d0b2 /signal-composer-binding/signal-composer.cpp | |
parent | db45a68715c07e6b8fe35e322ddcbbc6c473cb2b (diff) |
Enhance pointer manage and container browsing
- SourceAPI now holds share_ptr of Signal
- Signal are stored in a map<string,signal> that change
way to browse the signals
- subscribed property included in SourceAPI.
- Clean old code
- renaming struct SignalValue->signalValue
Change-Id: Ic5c28296ddd7197c6562e12fbc91c504c1cc0b4d
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 | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp index b0c7d6a..71cac7b 100644 --- a/signal-composer-binding/signal-composer.cpp +++ b/signal-composer-binding/signal-composer.cpp @@ -21,9 +21,9 @@ #include "clientApp.hpp" -extern "C" void setSignalValueHandle(const char* aName, long long int timestamp, struct SignalValue value) +extern "C" void setsignalValueHandle(const char* aName, long long int timestamp, struct signalValue value) { - std::vector<Signal*> signals = Composer::instance().searchSignals(aName); + std::vector<std::shared_ptr<Signal>> signals = Composer::instance().searchSignals(aName); if(!signals.empty()) { for(auto& sig: signals) @@ -42,7 +42,7 @@ bool startsWith(const std::string& str, const std::string& pattern) } static struct pluginCBT pluginHandle = { - .setSignalValue = setSignalValueHandle, + .setsignalValue = setsignalValueHandle, }; CtlSectionT Composer::ctlSections_[] = { @@ -328,7 +328,7 @@ int Composer::loadSignals(CtlSectionT* section, json_object *signalsJ) return err; } -void Composer::processOptions(const char** opts, Signal* sig, json_object* response) const +void Composer::processOptions(const char** opts, std::shared_ptr<Signal> sig, json_object* response) const { for(int idx=0; idx < sizeof(opts); idx++) { @@ -461,18 +461,6 @@ int Composer::initSourcesAPI() return err; } -std::vector<Signal*> Composer::getAllSignals() -{ - std::vector<Signal*> allSignals; - for( auto& source : sourcesListV_) - { - std::vector<Signal*> srcSignals = source.getSignals(); - allSignals.insert(allSignals.end(), srcSignals.begin(), srcSignals.end()); - } - - return allSignals; -} - SourceAPI* Composer::getSourceAPI(const std::string& api) { for(auto& source: sourcesListV_) @@ -483,10 +471,22 @@ SourceAPI* Composer::getSourceAPI(const std::string& api) return nullptr; } -std::vector<Signal*> Composer::searchSignals(const std::string& aName) +std::vector<std::shared_ptr<Signal>> Composer::getAllSignals() +{ + std::vector<std::shared_ptr<Signal>> allSignals; + for( auto& source : sourcesListV_) + { + std::vector<std::shared_ptr<Signal>> srcSignals = source.getSignals(); + allSignals.insert(allSignals.end(), srcSignals.begin(), srcSignals.end()); + } + + return allSignals; +} + +std::vector<std::shared_ptr<Signal>> Composer::searchSignals(const std::string& aName) { std::string api; - std::vector<Signal*> signals; + std::vector<std::shared_ptr<Signal>> signals; size_t sep = aName.find_first_of("/"); if(sep != std::string::npos) { @@ -496,8 +496,8 @@ std::vector<Signal*> Composer::searchSignals(const std::string& aName) } else { - std::vector<Signal*> allSignals = getAllSignals(); - for (Signal*& sig : allSignals) + std::vector<std::shared_ptr<Signal>> allSignals = getAllSignals(); + for (std::shared_ptr<Signal>& sig : allSignals) { if(*sig == aName) {signals.emplace_back(sig);} @@ -517,7 +517,7 @@ json_object* Composer::getsignalValue(const std::string& sig, json_object* optio &opts[2], &opts[3]); - std::vector<Signal*> sigP = searchSignals(sig); + std::vector<std::shared_ptr<Signal>> sigP = searchSignals(sig); if(!sigP.empty()) { for(auto& sig: sigP) |