aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding/signal-composer.cpp
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-22 01:13:17 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-07-25 10:08:07 +0200
commit7f15ef65f420179b606f136ed805fae9d320b321 (patch)
treec4ef2dde841415ce4dedcaaa5f0edf7e258bc356 /signal-composer-binding/signal-composer.cpp
parent3b08cec1ad06f313374bc1fd9cc64e1b28ce798d (diff)
Improved performance
Before value was translated to a C type variable two times, at the reception then at the emission. Now it just receives and sends the signal value without translation nor interpretation except if you ask for an average, minimum or maximum value. Then in those cases it interprets the json to return you a value or an error if there is no numeric values to compute. Remove unneeded log message at event reception. Improved signal search engine, will search in source's signals map by the signal ID not the event name which lead to a more direct map match. Bugs-AGL: SPEC-1612 Depends-On: I43e79ed73a507ac2ca7ed4cdc3f16ec009392194 Change-Id: Ie253c3fe1e8cde42dabe8832da74e9f9bf442c14 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.cpp62
1 files changed, 11 insertions, 51 deletions
diff --git a/signal-composer-binding/signal-composer.cpp b/signal-composer-binding/signal-composer.cpp
index 99129b4..f7c1971 100644
--- a/signal-composer-binding/signal-composer.cpp
+++ b/signal-composer-binding/signal-composer.cpp
@@ -21,7 +21,7 @@
#include "clientApp.hpp"
-extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestamp, struct signalValue value)
+extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestamp, json_object* value)
{
std::vector<std::shared_ptr<Signal>> signals = Composer::instance().searchSignals(aName);
if(!signals.empty())
@@ -31,7 +31,7 @@ extern "C" void searchNsetSignalValueHandle(const char* aName, uint64_t timestam
}
}
-extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, struct signalValue value)
+extern "C" void setSignalValueHandle(void* aSignal, uint64_t timestamp, json_object* value)
{
Signal* sig = static_cast<Signal*>(aSignal);
sig->set(timestamp, value);
@@ -380,47 +380,25 @@ void Composer::processOptions(const std::map<std::string, int>& opts, std::share
{
avg = true;
double value = sig->average(o.second);
- json_object_object_add(response, "value",
- json_object_new_double(value));
+ json_object_object_add(response, "value", json_object_new_double(value));
}
else if (o.first.compare("minimum") && !min)
{
min = true;
double value = sig->minimum();
- json_object_object_add(response, "value",
- json_object_new_double(value));
+ json_object_object_add(response, "value", json_object_new_double(value));
}
else if (o.first.compare("maximum") && !max)
{
max = true;
double value = sig->maximum();
- json_object_object_add(response, "value",
- json_object_new_double(value));
+ json_object_object_add(response, "value", json_object_new_double(value));
}
else if (o.first.compare("last") && !last)
{
last = true;
- struct signalValue value = sig->last_value();
- if(value.hasBool)
- {
- json_object_object_add(response, "value",
- json_object_new_boolean(value.boolVal));
- }
- else if(value.hasNum)
- {
- json_object_object_add(response, "value",
- json_object_new_double(value.numVal));
- }
- else if(value.hasStr)
- {
- 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."));
- }
+ json_object* value = sig->last_value();
+ json_object_object_add(response, "value", value);
}
else
{
@@ -568,8 +546,9 @@ std::vector<std::shared_ptr<Signal>> Composer::searchSignals(const std::string&
if(sep != std::string::npos)
{
api = aName.substr(0, sep);
+ std::string signal_id = aName.substr(sep + 1, std::string::npos);
std::shared_ptr<SourceAPI> source = getSourceAPI(api);
- return source->searchSignals(aName);
+ return source->searchSignals(signal_id);
}
else
{
@@ -603,27 +582,8 @@ json_object* Composer::getsignalValue(const std::string& sig, json_object* optio
"signal", sig->id().c_str());
if (opts.empty())
{
- struct signalValue value = sig->last_value();
- if(value.hasBool)
- {
- json_object_object_add(response, "value",
- json_object_new_boolean(value.boolVal));
- }
- else if(value.hasNum)
- {
- json_object_object_add(response, "value",
- json_object_new_double(value.numVal));
- }
- else if(value.hasStr)
- {
- 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."));
- }
+ json_object* value = sig->last_value();
+ json_object_object_add(response, "value", value);
}
else
{processOptions(opts, sig, response);}