summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-12-05 16:51:25 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:49 +0100
commitfb487caec38c0da7a43bab850af6aa79b07befde (patch)
treeda3c46e3e8dcd4627fee54f784b391b284d373b5 /signal-composer-binding/signal.cpp
parent2c3a3ca76a57efa1cd825d140fb26fdec3482ee8 (diff)
Hold all contexts (plugin & source) in signalCtx_
Keeping persistence between call data are kept in that member also subscription Action now use getSignals_ context and no more the signal one, this is more accurate and simples Change-Id: Idd7c56ba30f1daa9eaf9b99a7261d58189ef0bb2 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal.cpp')
-rw-r--r--signal-composer-binding/signal.cpp41
1 files changed, 34 insertions, 7 deletions
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index e7156dc..c09e059 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -34,6 +34,7 @@ Signal::Signal()
unit_(""),
onReceived_(nullptr),
getSignalsArgs_(nullptr),
+ signalCtx_(new struct signalCBT),
subscribed_(false)
{}
@@ -48,6 +49,7 @@ Signal::Signal(const std::string& id, const std::string& event, std::vector<std:
unit_(unit),
onReceived_(onReceived),
getSignalsArgs_(getSignalsArgs),
+ signalCtx_(new struct signalCBT),
subscribed_(false)
{}
@@ -67,11 +69,13 @@ Signal::Signal(const std::string& id,
unit_(unit),
onReceived_(onReceived),
getSignalsArgs_(),
+ signalCtx_(new struct signalCBT),
subscribed_(false)
{}
Signal::~Signal()
{
+ delete(signalCtx_);
delete(onReceived_);
}
@@ -126,9 +130,16 @@ json_object* Signal::toJSON() const
"uid", id_.c_str(),
"getSignalsArgs", getSignalsArgs_);
- if (!event_.empty()) {json_object_object_add(queryJ, "event", json_object_new_string(event_.c_str()));}
- if (json_object_array_length(nameArrayJ)) {json_object_object_add(queryJ, "depends", nameArrayJ);}
+ if (!event_.empty())
+ {json_object_object_add(queryJ, "event", json_object_new_string(event_.c_str()));}
+
+ if (json_object_array_length(nameArrayJ))
+ {json_object_object_add(queryJ, "depends", nameArrayJ);}
+ else
+ {json_object_put(nameArrayJ);}
+
if (!unit_.empty()) {json_object_object_add(queryJ, "unit", json_object_new_string(unit_.c_str()));}
+
if (frequency_) {json_object_object_add(queryJ, "frequency", json_object_new_double(frequency_));}
if(timestamp_) {json_object_object_add(queryJ, "timestamp", json_object_new_int64(timestamp_));}
@@ -140,15 +151,31 @@ json_object* Signal::toJSON() const
return queryJ;
}
+/// @brief Initialize signal context if not already done and return it.
+/// Signal context is a handle to be use by plugins then they can call
+/// some signal object method setting signal values.
+/// Also if plugin set a context it retrieve it and initiaze the pluginCtx
+/// member then plugin can find a persistent memory area where to hold its
+/// value.
+///
+/// @return a pointer to the signalCtx_ member initialized.
struct signalCBT* Signal::get_context()
{
- struct signalCBT* ctx = new struct signalCBT;
+ if(!signalCtx_->aSignal ||
+ !signalCtx_->searchNsetSignalValue ||
+ !signalCtx_->setSignalValue)
+ {
+ signalCtx_->searchNsetSignalValue = searchNsetSignalValueHandle;
+ signalCtx_->setSignalValue = setSignalValueHandle;
+
+ signalCtx_->aSignal = (void*)this;
- ctx->searchNsetSignalValue = searchNsetSignalValueHandle;
- ctx->setSignalValue = setSignalValueHandle;
+ signalCtx_->pluginCtx = onReceived_ && onReceived_->type == CTL_TYPE_CB ?
+ onReceived_->exec.cb.plugin->context:
+ nullptr;
+ }
- ctx->aSignal = (void*)this;
- return ctx;
+ return signalCtx_;
}
/// @brief Set Signal timestamp and value property when an incoming