summaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal-composer.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-25 18:22:49 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commitdb45a68715c07e6b8fe35e322ddcbbc6c473cb2b (patch)
tree43c1be13ddf78810ef8264b0816aad7d1565d92f /signal-composer-binding/signal-composer.cpp
parentfb1d083aa2702b96ff33ab7f3249ef9b1ed5a715 (diff)
No errors on get if no values has been recorded
Change-Id: Ib1d5da084b3a39fbfc9816070aba008e3486cfae Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal-composer.cpp')
-rw-r--r--signal-composer-binding/signal-composer.cpp55
1 files changed, 35 insertions, 20 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index db35e76..b0c7d6a 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -337,42 +337,52 @@ void Composer::processOptions(const char** opts, Signal* sig, json_object* respo
{
avg = true;
double value = sig->average();
- json_object_object_add(response, "average",
+ json_object_object_add(response, "value",
json_object_new_double(value));
}
- if (strcasestr(opts[idx], "min") && !min)
+ else if (strcasestr(opts[idx], "min") && !min)
{
min = true;
double value = sig->minimum();
- json_object_object_add(response, "min",
+ json_object_object_add(response, "value",
json_object_new_double(value));
}
- if (strcasestr(opts[idx], "max") && !max)
+ else if (strcasestr(opts[idx], "max") && !max)
{
max = true;
double value = sig->maximum();
- json_object_object_add(response, "max",
+ json_object_object_add(response, "value",
json_object_new_double(value));
}
- if (strcasestr(opts[idx], "last") && !last)
+ else if (strcasestr(opts[idx], "last") && !last)
{
last = true;
- struct SignalValue value = sig->last();
+ struct signalValue value = sig->last();
if(value.hasBool)
{
- json_object_object_add(response, "last",
+ json_object_object_add(response, "value",
json_object_new_boolean(value.boolVal));
}
- if(value.hasNum)
+ else if(value.hasNum)
{
- json_object_object_add(response, "last",
+ json_object_object_add(response, "value",
json_object_new_double(value.numVal));
}
- if(value.hasStr)
+ else if(value.hasStr)
{
- json_object_object_add(response, "last",
+ json_object_object_add(response, "value",
json_object_new_string(value.strVal.c_str()));
}
+ else
+ {
+ json_object_object_add(response, "value",
+ json_object_new_string("No recorded value so far."));
+ }
+ }
+ else
+ {
+ json_object_object_add(response, "value",
+ json_object_new_string("No recorded value so far."));
}
}
}
@@ -496,7 +506,7 @@ std::vector<Signal*> Composer::searchSignals(const std::string& aName)
return signals;
}
-json_object* Composer::getSignalValue(const std::string& sig, json_object* options)
+json_object* Composer::getsignalValue(const std::string& sig, json_object* options)
{
const char **opts = nullptr;
json_object *response = nullptr, *finalResponse = json_object_new_array();
@@ -516,22 +526,27 @@ json_object* Composer::getSignalValue(const std::string& sig, json_object* optio
"signal", sig->id().c_str());
if (!opts)
{
- struct SignalValue value = sig->last();
+ struct signalValue value = sig->last();
if(value.hasBool)
{
- json_object_object_add(response, "last",
+ json_object_object_add(response, "value",
json_object_new_boolean(value.boolVal));
}
- if(value.hasNum)
+ else if(value.hasNum)
{
- json_object_object_add(response, "last",
+ json_object_object_add(response, "value",
json_object_new_double(value.numVal));
}
- if(value.hasStr)
+ else if(value.hasStr)
{
- json_object_object_add(response, "last",
+ json_object_object_add(response, "value",
json_object_new_string(value.strVal.c_str()));
}
+ else
+ {
+ json_object_object_add(response, "value",
+ json_object_new_string("No recorded value so far."));
+ }
}
else
{processOptions(opts, sig, response);}
@@ -539,7 +554,7 @@ json_object* Composer::getSignalValue(const std::string& sig, json_object* optio
}
}
- return response;
+ return finalResponse;
}
int Composer::execSignalsSubscription()