summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal.hpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-22 18:15:33 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commita758f4a632adc7fff4769d97379264de6c68685d (patch)
tree01bab4db9d9e8227fc37c17312ea346f46e90fec /signal-composer-binding/signal.hpp
parente4258ef6e45009b5625f85ec7e4f8946805e1c4a (diff)
Migrating to real Observer design pattern usage
Change-Id: I2fa4e1dc81f5dff852e619a425b8caf26b94b55a Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal.hpp')
-rw-r--r--signal-composer-binding/signal.hpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp
index 870843e..8d0d1ab 100644
--- a/signal-composer-binding/signal.hpp
+++ b/signal-composer-binding/signal.hpp
@@ -22,8 +22,15 @@
#include <vector>
#include <ctl-config.h>
+#include "observer-pattern.hpp"
+
class Composer;
+/// @brief Structure holding a possible value of a Signal
+/// as it could be different type of value, we declare all
+/// possibility.
+/// Not very efficient or optimized, maybe use of Variant in
+/// C++17 but this is a bit too new to uses it for now
struct SignalValue {
bool hasBool = false;
bool boolVal;
@@ -33,7 +40,7 @@ struct SignalValue {
std::string strVal;
};
-class Signal
+class Signal: public Observable<Signal>, public Observer<Signal>
{
private:
std::string id_;
@@ -47,12 +54,7 @@ private:
CtlActionT* onReceived_;
json_object* getSignalsArgs_;
- std::vector<Signal*> Observers_;
-
- void notify() const;
- void attach(Signal *obs);
- int recursionCheck(const std::string& origId) const;
-
+ //int recursionCheck(const std::string& origId) const;
public:
Signal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs);
Signal(const std::string& id, std::vector<std::string>& depends, const std::string& unit, double frequency, CtlActionT* onReceived);
@@ -65,7 +67,7 @@ public:
json_object* toJSON() const;
void set(long long int timestamp, struct SignalValue& value);
- void update(long long int timestamp, struct SignalValue value);
+ void update(Signal* sig);
int onReceivedCB(json_object *queryJ);
void attachToSourceSignals(Composer& composer);
@@ -73,5 +75,5 @@ public:
double minimum(int seconds = 0) const;
double maximum(int seconds = 0) const;
struct SignalValue last() const;
- int recursionCheck() const;
+ //int recursionCheck() const;
};