aboutsummaryrefslogtreecommitdiffstats
path: root/signal-composer-binding
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2017-09-28 20:09:00 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2017-12-14 11:00:25 +0100
commit19bc0fd64d5f5035e53abfcda1559782ff3c54b4 (patch)
treeadbe66b48cc50319ee34cd1e9558cc19bbf4ad92 /signal-composer-binding
parent784d48b8f432119de570a119a760e05e9068d12d (diff)
Better deeper signal search on received event.
Search in received JSON data if we could find a better signal name if the preceding one is too fuzzy Change-Id: I83ba376890155c44d5f29dfe2401627c72539f34 Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding')
-rw-r--r--signal-composer-binding/signal-composer-binding.cpp36
1 files changed, 34 insertions, 2 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp
index a1e4543..92bd0cc 100644
--- a/signal-composer-binding/signal-composer-binding.cpp
+++ b/signal-composer-binding/signal-composer-binding.cpp
@@ -33,14 +33,46 @@
void onEvent(const char *event, json_object *object)
{
Composer& composer = Composer::instance();
+ AFB_NOTICE("event: %s", json_object_to_json_string(object));
std::vector<std::shared_ptr<Signal>> signals = composer.searchSignals(event);
if(!signals.empty())
{
- for(auto& sig: signals)
+ // If there is more than 1 element then maybe we can find a more
+ // detailled event name in JSON object as 1 event may carry several
+ // signals. Try to find that one.
+ if(signals.size() > 1)
{
- sig->onReceivedCB(object);
+ bool found = false;
+ json_object_iterator iter = json_object_iter_begin(object);
+ json_object_iterator iterEnd = json_object_iter_end(object);
+ while(!json_object_iter_equal(&iter, &iterEnd))
+ {
+ json_object *value = json_object_iter_peek_value(&iter);
+ if(json_object_is_type(value, json_type_string))
+ {
+ std::string name = json_object_get_string(value);
+ for(auto& sig: signals)
+ {
+ if(*sig == name)
+ {
+ found = true;
+ sig->onReceivedCB(object);
+ }
+ }
+ }
+ json_object_iter_next(&iter);
+ }
+ // If nothing found in JSON data then apply onReceived callback
+ // for all signals found
+ if(! found)
+ {
+ for(auto& sig: signals)
+ {sig->onReceivedCB(object);}
+ }
}
+ else
+ {signals[0]->onReceivedCB(object);}
}
}