aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-04-30 23:55:04 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-05 16:22:47 +0200
commitc5eeda8be950fa638beb9eec196b6d1e8fec746a (patch)
tree739e1342672e0e845b32ea668b49e84cb61fea4e
parent04e6084fa00fba893f6fd9a6b4ba3f1020e7b655 (diff)
Use a better parameter name, more explicit
Change-Id: I4c2a31f5c395c0d85ec810b25fb88c70cf691375 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
-rw-r--r--signal-composer-binding/signal.cpp33
1 files changed, 17 insertions, 16 deletions
diff --git a/signal-composer-binding/signal.cpp b/signal-composer-binding/signal.cpp
index 20f87e0..3643527 100644
--- a/signal-composer-binding/signal.cpp
+++ b/signal-composer-binding/signal.cpp
@@ -69,7 +69,7 @@ Signal::Signal(const std::string& id,
frequency_(frequency),
unit_(unit),
onReceived_(onReceived),
- getSignalsArgs_(),
+ getSignalsArgs_(nullptr),
signalCtx_({nullptr, nullptr, nullptr, nullptr}),
subscribed_(false)
{}
@@ -127,8 +127,10 @@ const std::string Signal::id() const
/// @return the built JSON object representing the Signal
json_object* Signal::toJSON() const
{
- json_object* queryJ = nullptr;
+ json_object* sigJ = json_object_new_object();
+ json_object *nameArrayJ = json_object_new_array();
std::vector<std::string> dependsSignalName;
+
for (const std::string& src: dependsSigV_ )
{
ssize_t sep = src.find_first_of("/");
@@ -137,36 +139,35 @@ json_object* Signal::toJSON() const
dependsSignalName.push_back(src.substr(sep+1));
}
}
- json_object *nameArrayJ = json_object_new_array();
+
for (const std::string& lowSig: dependsSignalName)
{
json_object_array_add(nameArrayJ, json_object_new_string(lowSig.c_str()));
}
- wrap_json_pack(&queryJ, "{ss,so*}",
- "uid", id_.c_str(),
- "getSignalsArgs", getSignalsArgs_);
- AFB_ApiDebug(nullptr, "========== %s", json_object_get_string(queryJ));
+ 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(queryJ, "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(queryJ, "depends", nameArrayJ);}
+ {json_object_object_add(sigJ, "depends", nameArrayJ);}
else
{json_object_put(nameArrayJ);}
- if (!unit_.empty()) {json_object_object_add(queryJ, "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 (frequency_) {json_object_object_add(queryJ, "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(queryJ, "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(queryJ, "value", json_object_new_boolean(value_.boolVal));}
- else if (value_.hasNum) {json_object_object_add(queryJ, "value", json_object_new_double(value_.numVal));}
- else if (value_.hasStr) {json_object_object_add(queryJ, "value", json_object_new_string(value_.strVal.c_str()));}
+ 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));}
+ else if (value_.hasStr) {json_object_object_add(sigJ, "value", json_object_new_string(value_.strVal.c_str()));}
- return queryJ;
+ return sigJ;
}
/// @brief Initialize signal context if not already done and return it.