aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-12-11 18:53:11 +0100
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:49 +0100
commit0524ef772bf0a06fec736d7e1bd0753a7b65bc8c (patch)
tree00d128ca2e05b0779d306dbb48d04936d72947fa /signal-composer-binding
parent4146a3d1b078e2eb183eaf9cfdf97323624622bd (diff)
Use value instead of pointer for a member
no reason to keep it as pointer, and simpler to initiaze it at construction time. Change-Id: I0aee4483c834e66651d80998de81c99799451ff5 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding')
-rw-r--r--signal-composer-binding/signal.cpp23
-rw-r--r--signal-composer-binding/signal.hpp27
2 files changed, 25 insertions, 25 deletions
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index b9663ee..dcbf814 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -34,7 +34,7 @@ Signal::Signal()
unit_(""),
onReceived_(nullptr),
getSignalsArgs_(nullptr),
- signalCtx_(new struct signalCBT),
+ signalCtx_({nullptr, nullptr, nullptr, nullptr}),
subscribed_(false)
{}
@@ -49,7 +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),
+ signalCtx_({nullptr, nullptr, nullptr, nullptr}),
subscribed_(false)
{}
@@ -69,7 +69,7 @@ Signal::Signal(const std::string& id,
unit_(unit),
onReceived_(onReceived),
getSignalsArgs_(),
- signalCtx_(new struct signalCBT),
+ signalCtx_({nullptr, nullptr, nullptr, nullptr}),
subscribed_(false)
{}
@@ -77,7 +77,6 @@ Signal::~Signal()
{
json_object_put(onReceived_->argsJ);
json_object_put(getSignalsArgs_);
- delete(signalCtx_);
delete(onReceived_);
}
@@ -163,21 +162,21 @@ json_object* Signal::toJSON() const
/// @return a pointer to the signalCtx_ member initialized.
struct signalCBT* Signal::get_context()
{
- if(!signalCtx_->aSignal ||
- !signalCtx_->searchNsetSignalValue ||
- !signalCtx_->setSignalValue)
+ if(!signalCtx_.aSignal ||
+ !signalCtx_.searchNsetSignalValue ||
+ !signalCtx_.setSignalValue)
{
- signalCtx_->searchNsetSignalValue = searchNsetSignalValueHandle;
- signalCtx_->setSignalValue = setSignalValueHandle;
+ signalCtx_.searchNsetSignalValue = searchNsetSignalValueHandle;
+ signalCtx_.setSignalValue = setSignalValueHandle;
- signalCtx_->aSignal = (void*)this;
+ signalCtx_.aSignal = (void*)this;
- signalCtx_->pluginCtx = onReceived_ && onReceived_->type == CTL_TYPE_CB ?
+ signalCtx_.pluginCtx = onReceived_ && onReceived_->type == CTL_TYPE_CB ?
onReceived_->exec.cb.plugin->context:
nullptr;
}
- return signalCtx_;
+ return &signalCtx_;
}
/// @brief Set Signal timestamp and value property when an incoming
diff --git a/signal-composer-binding/signal.hpp b/signal-composer-binding/signal.hpp
index 0fbb0a6..63be5c9 100644
--- a/signal-composer-binding/signal.hpp
+++ b/signal-composer-binding/signal.hpp
@@ -53,6 +53,19 @@ struct signalValue {
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);
+
+/// @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* aSignal;
+ void* pluginCtx;
+};
+
+
/// @brief Holds a signal (raw or virtual) definition. Value could be of
/// different types, so an intermediate structure is use to store them.
/// A signal could also be a subject or an observer at the same time, this
@@ -73,7 +86,7 @@ private:
std::string unit_;
CtlActionT* onReceived_;
json_object* getSignalsArgs_;
- struct signalCBT* signalCtx_;
+ struct signalCBT signalCtx_;
public:
bool subscribed_; ///< subscribed_ - boolean value telling if yes or no the signal has been subcribed to the low level binding.
@@ -105,15 +118,3 @@ public:
int initialRecursionCheck();
int recursionCheck(Signal* obs);
};
-
-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);
-
-/// @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* aSignal;
- void* pluginCtx;
-};