diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2018-07-22 12:45:13 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2018-07-23 09:52:41 +0200 |
commit | 3b08cec1ad06f313374bc1fd9cc64e1b28ce798d (patch) | |
tree | 474eeb22cda79134562cdd66dea01ceaf7280cdd /signal-composer-binding/signal.cpp | |
parent | 1eb97bc1126943b2d2a3ef631ed019231ba06da5 (diff) |
Adds a signal's metadata attributeflounder_5.99.2flounder/5.99.25.99.2
This adds a signal's metadata attribute which lets you store
any kind and number of metadata attributes to your signal. These
metadata are just reissued at the event emission without alteration.
Special case of "unit" attribute which is kept as a signal attribute
and not as a metadata because it is an intrinsic signal attribute that
all signals should have.
Bug-AGL: SPEC-1419
Change-Id: I531b4012ac9b22f312a4ccebc1a07a8d93129403
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal.cpp')
-rw-r--r-- | signal-composer-binding/signal.cpp | 47 |
1 files changed, 16 insertions, 31 deletions
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp index f248eae..2f1aa57 100644 --- a/signal-composer-binding/signal.cpp +++ b/signal-composer-binding/signal.cpp @@ -33,13 +33,14 @@ Signal::Signal() retention_(0), frequency_(0), unit_(""), + metadata_(nullptr), onReceived_(nullptr), getSignalsArgs_(nullptr), signalCtx_({nullptr, nullptr, nullptr, nullptr}), subscribed_(false) {} -Signal::Signal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& unit, int retention, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs) +Signal::Signal(const std::string& id, const std::string& event, std::vector<std::string>& depends, const std::string& unit, json_object *metadata, int retention, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs) :id_(id), event_(event), dependsSigV_(depends), @@ -48,34 +49,16 @@ Signal::Signal(const std::string& id, const std::string& event, std::vector<std: retention_(retention), frequency_(frequency), unit_(unit), + metadata_(metadata), onReceived_(onReceived), getSignalsArgs_(getSignalsArgs), signalCtx_({nullptr, nullptr, nullptr, nullptr}), subscribed_(false) {} -Signal::Signal(const std::string& id, - std::vector<std::string>& depends, - const std::string& unit, - int retention, - double frequency, - CtlActionT* onReceived) -:id_(id), - event_(), - dependsSigV_(depends), - timestamp_(0.0), - value_(), - retention_(retention), - frequency_(frequency), - unit_(unit), - onReceived_(onReceived), - getSignalsArgs_(nullptr), - signalCtx_({nullptr, nullptr, nullptr, nullptr}), - subscribed_(false) -{} - Signal::~Signal() { + if(metadata_) json_object_put(metadata_); if(getSignalsArgs_) json_object_put(getSignalsArgs_); if(onReceived_) delete(onReceived_); } @@ -135,33 +118,35 @@ json_object* Signal::toJSON() const { ssize_t sep = src.find_first_of("/"); if(sep != std::string::npos) - { dependsSignalName.push_back(src.substr(sep+1)); - } } for (const std::string& lowSig: dependsSignalName) - { json_object_array_add(nameArrayJ, json_object_new_string(lowSig.c_str())); - } json_object_object_add(sigJ, "uid", json_object_new_string(id_.c_str())); json_object_object_add(sigJ, "getSignalsArgs", json_object_get(getSignalsArgs_)); if (!event_.empty()) - {json_object_object_add(sigJ, "event", json_object_new_string(event_.c_str()));} + json_object_object_add(sigJ, "event", json_object_new_string(event_.c_str())); if (json_object_array_length(nameArrayJ)) - {json_object_object_add(sigJ, "depends", nameArrayJ);} + json_object_object_add(sigJ, "depends", nameArrayJ); else - {json_object_put(nameArrayJ);} + json_object_put(nameArrayJ); + + if (!unit_.empty()) + json_object_object_add(sigJ, "unit", json_object_new_string(unit_.c_str())); - if (!unit_.empty()) {json_object_object_add(sigJ, "unit", json_object_new_string(unit_.c_str()));} + if (!metadata_) + json_object_object_add(sigJ, "metadata", json_object_get(metadata_)); - if (frequency_) {json_object_object_add(sigJ, "frequency", json_object_new_double(frequency_));} + if (frequency_) + json_object_object_add(sigJ, "frequency", json_object_new_double(frequency_)); - if(timestamp_) {json_object_object_add(sigJ, "timestamp", json_object_new_int64(timestamp_));} + if(timestamp_) + json_object_object_add(sigJ, "timestamp", json_object_new_int64(timestamp_)); if (value_.hasBool) {json_object_object_add(sigJ, "value", json_object_new_boolean(value_.boolVal));} else if (value_.hasNum) {json_object_object_add(sigJ, "value", json_object_new_double(value_.numVal));} |