diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-09-21 08:50:38 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-14 11:00:25 +0100 |
commit | e93cb3415e883bbd73528ca6a08e53e854f7bee0 (patch) | |
tree | 20d2f75be8486dd05e8f64434838069145fe601e /signal-composer-binding/signal-composer-binding.cpp | |
parent | 78202d5bd8a8d09a55bb71b9df6d3f54b18184b8 (diff) |
Find all signals that matches the searched pattern
Change-Id: Ia562fbd90aaeaa57c1c731d0f66dd31865db7e71
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding/signal-composer-binding.cpp')
-rw-r--r-- | signal-composer-binding/signal-composer-binding.cpp | 43 |
1 files changed, 40 insertions, 3 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp index 269eaba..5dcb53f 100644 --- a/signal-composer-binding/signal-composer-binding.cpp +++ b/signal-composer-binding/signal-composer-binding.cpp @@ -35,16 +35,53 @@ void onEvent(const char *event, json_object *object) AFB_DEBUG("Received event json: %s", json_object_to_json_string(object)); bindingApp& bApp = bindingApp::instance(); - std::shared_ptr<Signal> sig = bApp.searchSignal(event); - if(sig != nullptr) + std::vector<std::shared_ptr<Signal>> signals = bApp.searchSignals(event); + if(!signals.empty()) { - sig->onReceivedCB(object); + for(auto& sig: signals) + { + sig->onReceivedCB(object); + } } } +static int one_subscribe_unsubscribe(struct afb_req request, + bool subscribe, + const std::string& tag, + json_object* args) +{ + return 1; +} + /// @brief entry point for client subscription request. void subscribe(afb_req request) { + int rc,rc2,n; + json_object *event, *args = afb_req_json(request); + if (args == NULL || + !json_object_object_get_ex(args, "event", &event) || + !json_object_object_get_ex(args, "events", &event) || + !json_object_object_get_ex(args, "signal", &event) || + !json_object_object_get_ex(args, "signals", &event)) + { + rc = one_subscribe_unsubscribe(request, subscribe, "*", args); + } + else if (json_object_get_type(event) != json_type_array) + { + rc = one_subscribe_unsubscribe(request, subscribe, json_object_get_string(event), args); + } + else + { + rc = 0; + n = json_object_array_length(event); + for (int i = 0 ; i < n ; i++) + { + json_object *x = json_object_array_get_idx(event, i); + rc2 = one_subscribe_unsubscribe(request, subscribe, json_object_get_string(x), args); + if (rc >= 0) + rc = rc2 >= 0 ? rc + rc2 : rc2; + } + } if(true) afb_req_success(request, NULL, NULL); else |