summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-15 16:29:17 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commit677cde6288a4574b8251a4a532b1d9e1594b09b2 (patch)
treec510a0cdd76e2b8de1cdaf254fd270c8bfebae42 /signal-composer-binding/signal.cpp
parenteabae24ea592420de46e36f0b1af5d39eee5b8a4 (diff)
Subscription by plugin to signals
Change-Id: Icb923f87df2be8eb664106bc9077b3a8221dd3ce Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal.cpp')
-rw-r--r--signal-composer-binding/signal.cpp39
1 files changed, 34 insertions, 5 deletions
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index 0689a99..2dc517c 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -26,7 +26,7 @@ Signal::Signal(const std::string& id,
double frequency,
CtlActionT* onReceived)
:id_(id),
- sourcesSig_(sources),
+ signalSigList_(sources),
frequency_(frequency),
unit_(unit),
onReceived_(onReceived)
@@ -48,17 +48,46 @@ bool Signal::operator ==(const Signal& other) const
bool Signal::operator==(const std::string& aName) const
{
if(id_ == aName) {return true;}
- for( const std::string& src : sourcesSig_)
+ for( const std::string& src : signalSigList_)
{
if(src == aName) {return true;}
}
return false;
}
-std::string Signal::id() const
+const std::string Signal::id() const
{
return id_;
}
+
+json_object* Signal::toJSON() const
+{
+ json_object* queryJ = nullptr;
+ std::vector<std::string> lowSignalName;
+ for (const std::string& src: signalSigList_ )
+ {
+ ssize_t sep = src.find_first_of("/");
+ if(sep != std::string::npos)
+ {
+ lowSignalName.push_back(src.substr(sep+1));
+ }
+ }
+ json_object* nameArray = json_object_new_array();
+ for (const std::string& lowSig: lowSignalName)
+ {
+ json_object_array_add(nameArray, json_object_new_string(lowSig.c_str()));
+ }
+ /*json_object_object_add(queryJ, "signal", nameArray);
+ json_object_object_add(queryJ, "unit", json_object_new_string(unit_.c_str()));
+ json_object_object_add(queryJ, "unit", json_object_new_double(frequency_));*/
+ wrap_json_pack(&queryJ, "{so,ss*,sf*}",
+ "signal", nameArray,
+ "unit", unit_.c_str(),
+ "frequency", frequency_);
+
+ return queryJ;
+}
+
void update(double timestamp, double value)
{
AFB_NOTICE("Got an update from observed signal");
@@ -74,9 +103,9 @@ void Signal::attach(Signal* obs)
Observers_.push_back(obs);
}
-void Signal::attachToSources(bindingApp& bApp)
+void Signal::attachToSourceSignals(bindingApp& bApp)
{
- for (const std::string& srcSig: sourcesSig_)
+ for (const std::string& srcSig: signalSigList_)
{
if(srcSig.find("/") == std::string::npos)
{