summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal.hpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-22 01:13:17 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-25 10:08:07 +0200
commit7f15ef65f420179b606f136ed805fae9d320b321 (patch)
treec4ef2dde841415ce4dedcaaa5f0edf7e258bc356 /signal-composer-binding/signal.hpp
parent3b08cec1ad06f313374bc1fd9cc64e1b28ce798d (diff)
Improved performance
Before value was translated to a C type variable two times, at the reception then at the emission. Now it just receives and sends the signal value without translation nor interpretation except if you ask for an average, minimum or maximum value. Then in those cases it interprets the json to return you a value or an error if there is no numeric values to compute. Remove unneeded log message at event reception. Improved signal search engine, will search in source's signals map by the signal ID not the event name which lead to a more direct map match. Bugs-AGL: SPEC-1612 Depends-On: I43e79ed73a507ac2ca7ed4cdc3f16ec009392194 Change-Id: Ie253c3fe1e8cde42dabe8832da74e9f9bf442c14 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal.hpp')
-rw-r--r--signal-composer-binding/signal.hpp45
1 files changed, 9 insertions, 36 deletions
diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp
index 0a12b16..6c7f43f 100644
--- a/signal-composer-binding/signal.hpp
+++ b/signal-composer-binding/signal.hpp
@@ -28,40 +28,14 @@
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 undefined;
- bool hasBool;
- bool boolVal;
- bool hasNum;
- double numVal;
- bool hasStr;
- std::string strVal;
-
- signalValue():
- undefined(true), hasBool(false), boolVal(false), hasNum(false), numVal(0), hasStr(false), strVal("") {};
- signalValue(bool b):
- undefined(false), hasBool(true), boolVal(b), hasNum(false), numVal(0), hasStr(false), strVal("") {};
- signalValue(int i):
- undefined(false), hasBool(false), boolVal(false), hasNum(true), numVal(i), hasStr(false), strVal("") {};
- signalValue(double d):
- undefined(false), hasBool(false), boolVal(false), hasNum(true), numVal(d), hasStr(false), strVal("") {};
- signalValue(const std::string& s):
- undefined(false), hasBool(false), boolVal(false), hasNum(false), numVal(0), hasStr(true), strVal(s) {};
-};
-
-extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestamp, struct signalValue value);
-extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, struct signalValue value);
+extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestamp, json_object* value);
+extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, json_object* value);
/// @brief Holds composer callbacks and obj to manipulate
struct signalCBT
{
- void (*searchNsetSignalValue)(const char* aName, uint64_t timestamp, struct signalValue value);
- void (*setSignalValue)(void* aSignal, uint64_t timestamp, struct signalValue value);
+ void (*searchNsetSignalValue)(const char* aName, uint64_t timestamp, json_object* value);
+ void (*setSignalValue)(void* aSignal, uint64_t timestamp, json_object* value);
void* aSignal;
void* pluginCtx;
};
@@ -80,8 +54,8 @@ private:
std::string event_;
std::vector<std::string> dependsSigV_;
uint64_t timestamp_;
- struct signalValue value_;
- std::map<uint64_t, struct signalValue> history_; ///< history_ - Hold signal value history in map with <timestamp, value>
+ json_object* value_;
+ std::map<uint64_t, json_object*> history_; ///< history_ - Hold signal value history in map with <timestamp, value>
int retention_;
double frequency_;
std::string unit_;
@@ -107,17 +81,16 @@ public:
struct signalCBT* get_context();
json_object *getSignalsArgs();
- void set(uint64_t timestamp, struct signalValue& value);
+ void set(uint64_t timestamp, json_object*& value);
void update(Signal* sig);
- static int defaultOnReceivedCB(CtlSourceT* source, json_object* argsJ, json_object *queryJ);
- void defaultReceivedCB(json_object *eventJ);
+ static void defaultReceivedCB(Signal *signal, json_object *eventJ);
void onReceivedCB(json_object *eventJ);
void attachToSourceSignals(Composer& composer);
double average(int seconds = 0) const;
double minimum(int seconds = 0) const;
double maximum(int seconds = 0) const;
- struct signalValue last_value() const;
+ json_object* last_value() const;
uint64_t last_timestamp() const;
int initialRecursionCheck();