summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-04-30 23:53:58 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-05 16:21:22 +0200
commit04e6084fa00fba893f6fd9a6b4ba3f1020e7b655 (patch)
treee1ae36a4f520f0497569ad9cc22efd5fdc0ef1b5
parent1782a5b692038e67f26290a799ebc2d3b1dc242c (diff)
Implement the signal's update default method
Adding != operator to Signal class This operator is needed to exclude signal inclusion in notify function and make possible to add a signal at last position Change-Id: I95f3434019383e52928c37f396aae938f2cfae05 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--signal-composer-binding/signal.cpp50
-rw-r--r--signal-composer-binding/signal.hpp2
2 files changed, 47 insertions, 5 deletions
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index 66c8b54..20f87e0 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -93,11 +93,25 @@ bool Signal::operator ==(const Signal& other) const
return false;
}
+bool Signal::operator !=(const Signal& other) const
+{
+ if(id_ != other.id_) {return true;}
+ return false;
+}
+
bool Signal::operator ==(const std::string& aName) const
{
- if(! ::fnmatch(aName.c_str(), id_.c_str(), FNM_CASEFOLD))
+ if(! ::fnmatch(aName.c_str(), id_.c_str(), FNM_CASEFOLD) ||
+ ! ::fnmatch(aName.c_str(), event_.c_str(), FNM_CASEFOLD))
{return true;}
- if(! ::fnmatch(aName.c_str(), event_.c_str(), FNM_CASEFOLD))
+
+ return false;
+}
+
+bool Signal::operator !=(const std::string& aName) const
+{
+ if(::fnmatch(aName.c_str(), id_.c_str(), FNM_CASEFOLD) &&
+ ::fnmatch(aName.c_str(), event_.c_str(), FNM_CASEFOLD))
{return true;}
return false;
@@ -207,18 +221,44 @@ void Signal::set(uint64_t timestamp, struct signalValue& value)
while(diff > retention_)
{
uint64_t first = history_.begin()->first;
- diff = (timestamp_ - first)/MICRO;
+ diff = (timestamp_ - first)/NANO;
if(diff > retention_)
{history_.erase(history_.cbegin());}
}
+
+ notify();
}
-/// @brief Observer method called when a Observable Signal has changes.
+/// @brief Observer method called when an Observable Signal has changed.
+/// this will call the onReceived callback with a JSONinifed object of observed
+/// signals.
+///
+/// The signal which triggered the update action will be provided as the last
+/// element.
///
/// @param[in] Observable - object from which update come from
void Signal::update(Signal* sig)
{
- AFB_NOTICE("Got an update from observed signal %s", sig->id().c_str());
+ json_object *depSigJ = json_object_new_array();
+ CtlSourceT src = {
+ .uid = sig->id().c_str(),
+ .api = nullptr,
+ .request = {nullptr, nullptr},
+ .context = (void*)get_context(),
+ .status = CTL_STATUS_EVT};
+ Composer& composer = Composer::instance();
+
+ for(const std::string& depSignal : dependsSigV_)
+ {
+ if(*sig != depSignal) {
+ std::vector<std::shared_ptr<Signal>> vs = composer.searchSignals(depSignal);
+ for(const auto& s : vs)
+ json_object_array_add(depSigJ, s->toJSON());
+ }
+ }
+ json_object_array_add(depSigJ, sig->toJSON());
+
+ ActionExecOne(&src, onReceived_, depSigJ);
}
/// @brief
diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp
index 2b4a461..815c7d9 100644
--- a/signal-composer-binding/signal.hpp
+++ b/signal-composer-binding/signal.hpp
@@ -98,7 +98,9 @@ public:
explicit operator bool() const;
bool operator==(const Signal& other) const;
+ bool operator!=(const Signal& other) const;
bool operator==(const std::string& aName) const;
+ bool operator!=(const std::string& aName) const;
const std::string id() const;
json_object* toJSON() const;