summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-22 12:45:13 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-23 09:52:41 +0200
commit3b08cec1ad06f313374bc1fd9cc64e1b28ce798d (patch)
tree474eeb22cda79134562cdd66dea01ceaf7280cdd /signal-composer-binding
parent1eb97bc1126943b2d2a3ef631ed019231ba06da5 (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')
-rw-r--r--signal-composer-binding/signal-composer.cpp10
-rw-r--r--signal-composer-binding/signal.cpp47
-rw-r--r--signal-composer-binding/signal.hpp4
-rw-r--r--signal-composer-binding/source.cpp4
-rw-r--r--signal-composer-binding/source.hpp2
5 files changed, 27 insertions, 40 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index 535e85b..99129b4 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -220,8 +220,9 @@ int Composer::loadSourcesAPI(AFB_ApiT apihandle, CtlSectionT* section, json_obje
int Composer::loadOneSignal(json_object* signalJ)
{
json_object *onReceivedJ = nullptr,
- *dependsJ = nullptr,
- *getSignalsArgs = nullptr;
+ *dependsJ = nullptr,
+ *metadataJ = nullptr,
+ *getSignalsArgs = nullptr;
CtlActionT* onReceivedCtl;
const char *id = nullptr,
*event = nullptr,
@@ -232,13 +233,14 @@ int Composer::loadOneSignal(json_object* signalJ)
ssize_t sep;
std::shared_ptr<SourceAPI> src = nullptr;
- int err = wrap_json_unpack(signalJ, "{ss,s?s,s?o,s?o,s?i,s?s,s?F,s?o !}",
+ int err = wrap_json_unpack(signalJ, "{ss,s?s,s?o,s?o,s?i,s?s,s?o,s?F,s?o !}",
"uid", &id,
"event", &event,
"depends", &dependsJ,
"getSignalsArgs", &getSignalsArgs,
"retention", &retention,
"unit", &unit,
+ "metadata", &metadataJ,
"frequency", &frequency,
"onReceived", &onReceivedJ);
if (err)
@@ -335,7 +337,7 @@ int Composer::loadOneSignal(json_object* signalJ)
else {onReceivedCtl = convert2Action(uid, onReceivedJ);}
if(src != nullptr)
- {src->addSignal(id, event, dependsV, retention, unit, frequency, onReceivedCtl, getSignalsArgs);}
+ {src->addSignal(id, event, dependsV, retention, unit, metadataJ, frequency, onReceivedCtl, getSignalsArgs);}
else
{err = -1;}
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));}
diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp
index 091d060..0a12b16 100644
--- a/signal-composer-binding/signal.hpp
+++ b/signal-composer-binding/signal.hpp
@@ -85,6 +85,7 @@ private:
int retention_;
double frequency_;
std::string unit_;
+ json_object* metadata_;
CtlActionT* onReceived_;
json_object* getSignalsArgs_;
struct signalCBT signalCtx_;
@@ -92,8 +93,7 @@ private:
public:
bool subscribed_; ///< subscribed_ - boolean value telling if yes or no the signal has been subcribed to the low level binding.
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(const std::string& id, std::vector<std::string>& depends, const std::string& unit, int retention, double frequency, CtlActionT* onReceived);
+ 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);
~Signal();
explicit operator bool() const;
diff --git a/signal-composer-binding/source.cpp b/signal-composer-binding/source.cpp
index d7a5915..a46e766 100644
--- a/signal-composer-binding/source.cpp
+++ b/signal-composer-binding/source.cpp
@@ -67,9 +67,9 @@ const struct signalsDefault& SourceAPI::signalsDefault() const
return signalsDefault_;
}
-void SourceAPI::addSignal(const std::string& id, const std::string& event, std::vector<std::string>& depends, int retention, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs)
+void SourceAPI::addSignal(const std::string& id, const std::string& event, std::vector<std::string>& depends, int retention, const std::string& unit, json_object *metadata, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs)
{
- std::shared_ptr<Signal> sig = std::make_shared<Signal>(id, event, depends, unit, retention, frequency, onReceived, getSignalsArgs);
+ std::shared_ptr<Signal> sig = std::make_shared<Signal>(id, event, depends, unit, metadata, retention, frequency, onReceived, getSignalsArgs);
newSignalsM_[id] = sig;
}
diff --git a/signal-composer-binding/source.hpp b/signal-composer-binding/source.hpp
index 8dd18e5..6585d0c 100644
--- a/signal-composer-binding/source.hpp
+++ b/signal-composer-binding/source.hpp
@@ -47,7 +47,7 @@ public:
void init();
std::string api() const;
const struct signalsDefault& signalsDefault() const;
- void addSignal(const std::string& id, const std::string& event, std::vector<std::string>& sources, int retention, const std::string& unit, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs);
+ void addSignal(const std::string& id, const std::string& event, std::vector<std::string>& sources, int retention, const std::string& unit, json_object *metadata, double frequency, CtlActionT* onReceived, json_object* getSignalsArgs);
void initSignals();
std::vector<std::shared_ptr<Signal>> getSignals() const;