diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-11 18:52:14 +0100 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-14 11:00:49 +0100 |
commit | 4146a3d1b078e2eb183eaf9cfdf97323624622bd (patch) | |
tree | 667bcf93cf11214d44b7500d6c48f334f317d9e0 /signal-composer-binding/signal-composer-binding.cpp | |
parent | b77a6a7841b203bf8e86179e67b9141cbc3cd83f (diff) |
Improve subscription process
Unsubscription remove asked signals from client session
then when no more signals are requested by the client
unsubscribe from event handle.
Correctly initialize members to by correctly evaluated after
Change-Id: Icabcb5a2446c62cab4eea9bf807613b719324ea0
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 | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp index a155062..d9f1f01 100644 --- a/signal-composer-binding/signal-composer-binding.cpp +++ b/signal-composer-binding/signal-composer-binding.cpp @@ -85,11 +85,16 @@ static int one_subscribe_unsubscribe(struct afb_req request, int err = 0; std::vector<std::shared_ptr<Signal>> signals = Composer::instance().searchSignals(event); - cContext->appendSignals(signals); if(subscribe) - {err = cContext->makeSubscription(request);} + { + cContext->appendSignals(signals); + err = cContext->makeSubscription(request); + } else - {err = cContext->makeUnsubscription(request);} + { + cContext->subtractSignals(signals); + err = cContext->makeUnsubscription(request); + } return err; } @@ -100,20 +105,20 @@ static int subscribe_unsubscribe(struct afb_req request, clientAppCtx* cContext) { int rc = 0; - json_object *event = nullptr; - if (args == NULL || !json_object_object_get_ex(args, "event", &event)) + json_object *eventJ = nullptr; + if (args == NULL || !json_object_object_get_ex(args, "signal", &eventJ)) { rc = one_subscribe_unsubscribe(request, subscribe, "*", args, cContext); } - else if (json_object_get_type(event) == json_type_string) + else if (json_object_get_type(eventJ) == json_type_string) { - rc = one_subscribe_unsubscribe(request, subscribe, json_object_get_string(event), args, cContext); + rc = one_subscribe_unsubscribe(request, subscribe, json_object_get_string(eventJ), args, cContext); } - else if (json_object_get_type(event) == json_type_array) + else if (json_object_get_type(eventJ) == json_type_array) { - for (int i = 0 ; i < json_object_array_length(event) ; i++) + for (int i = 0 ; i < json_object_array_length(eventJ) ; i++) { - json_object *x = json_object_array_get_idx(event, i); + json_object *x = json_object_array_get_idx(eventJ, i); rc += one_subscribe_unsubscribe(request, subscribe, json_object_get_string(x), args, cContext); } } |