aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal-composer.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-28 20:07:54 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commit784d48b8f432119de570a119a760e05e9068d12d (patch)
tree945486d89e10b67febde3522b723443e70b9e6e6 /signal-composer-binding/signal-composer.cpp
parent7b5a679d0ae117eb6b5bbcf516bf9e5051afd7dd (diff)
Enhance list/get verb
Handle options in a vector. Change-Id: Iafad2d93ea027db054750816750f4d07bd13c5d4 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.cpp28
1 files changed, 14 insertions, 14 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index a340aa6..ab5c63c 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -355,33 +355,33 @@ int Composer::loadSignals(CtlSectionT* section, json_object *signalsJ)
return err;
}
-void Composer::processOptions(const char** opts, std::shared_ptr<Signal> sig, json_object* response) const
+void Composer::processOptions(const std::map<std::string, int>& opts, std::shared_ptr<Signal> sig, json_object* response) const
{
- for(int idx=0; idx < sizeof(opts); idx++)
+ for(const auto& o: opts)
{
bool avg = false, min = false, max = false, last = false;
- if (strcasestr(opts[idx], "average") && !avg)
+ if (o.first.compare("average") && !avg)
{
avg = true;
- double value = sig->average();
+ double value = sig->average(o.second);
json_object_object_add(response, "value",
json_object_new_double(value));
}
- else if (strcasestr(opts[idx], "min") && !min)
+ else if (o.first.compare("minimum") && !min)
{
min = true;
double value = sig->minimum();
json_object_object_add(response, "value",
json_object_new_double(value));
}
- else if (strcasestr(opts[idx], "max") && !max)
+ else if (o.first.compare("maximum") && !max)
{
max = true;
double value = sig->maximum();
json_object_object_add(response, "value",
json_object_new_double(value));
}
- else if (strcasestr(opts[idx], "last") && !last)
+ else if (o.first.compare("last") && !last)
{
last = true;
struct signalValue value = sig->last();
@@ -535,14 +535,14 @@ std::vector<std::shared_ptr<Signal>> Composer::searchSignals(const std::string&
json_object* Composer::getsignalValue(const std::string& sig, json_object* options)
{
- const char **opts = nullptr;
+ std::map<std::string, int> opts;
json_object *response = nullptr, *finalResponse = json_object_new_array();
- wrap_json_unpack(options, "{s?s?s?s?!}",
- &opts[0],
- &opts[1],
- &opts[2],
- &opts[3]);
+ wrap_json_unpack(options, "{s?i, s?i, s?i, s?i !}",
+ "average", &opts["average"],
+ "minimum", &opts["minimum"],
+ "maximum", &opts["maximum"],
+ "last", &opts["last"]);
std::vector<std::shared_ptr<Signal>> sigP = searchSignals(sig);
if(!sigP.empty())
@@ -551,7 +551,7 @@ json_object* Composer::getsignalValue(const std::string& sig, json_object* optio
{
wrap_json_pack(&response, "{ss}",
"signal", sig->id().c_str());
- if (!opts)
+ if (opts.empty())
{
struct signalValue value = sig->last();
if(value.hasBool)