diff options
author | Romain Forlot <romain.forlot@iot.bzh> | 2017-09-21 18:18:21 +0200 |
---|---|---|
committer | Romain Forlot <romain.forlot@iot.bzh> | 2017-12-14 11:00:25 +0100 |
commit | d3061debd7d654dad1d1e96029ff5ca2aee15177 (patch) | |
tree | 94688b3b0beeef03dd20718d1d03e6fbea768187 /signal-composer-binding | |
parent | 58f2d68238464f8fb3451b3c8245e62914b4bb14 (diff) |
Beginning client App context handling work
Change-Id: Ifb21916bfb4c9c1be0fe68c1a88ada342d18ffe4
Signed-off-by: Romain Forlot <romain.forlot@iot.bzh>
Diffstat (limited to 'signal-composer-binding')
-rw-r--r-- | signal-composer-binding/signal-composer-binding.cpp | 71 | ||||
-rw-r--r-- | signal-composer-binding/signal-composer.hpp | 7 |
2 files changed, 54 insertions, 24 deletions
diff --git a/signal-composer-binding/signal-composer-binding.cpp b/signal-composer-binding/signal-composer-binding.cpp index 95bfc36..6c793a5 100644 --- a/signal-composer-binding/signal-composer-binding.cpp +++ b/signal-composer-binding/signal-composer-binding.cpp @@ -47,54 +47,77 @@ void onEvent(const char *event, json_object *object) static int one_subscribe_unsubscribe(struct afb_req request, bool subscribe, - const std::string& tag, + const std::string& event, json_object* args) { - return 1; + return 0; } -/// @brief entry point for client subscription request. -void subscribe(afb_req request) +static int subscribe_unsubscribe(struct afb_req request, + bool subscribe, + json_object* args) { - 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)) + int rc = 0; + json_object *event = nullptr; + if (args == NULL || !json_object_object_get_ex(args, "event", &event)) { rc = one_subscribe_unsubscribe(request, subscribe, "*", args); } - else if (json_object_get_type(event) != json_type_array) + else if (json_object_get_type(event) == json_type_string) { rc = one_subscribe_unsubscribe(request, subscribe, json_object_get_string(event), args); } - else + else if (json_object_get_type(event) == json_type_array) { - rc = 0; - n = json_object_array_length(event); - for (int i = 0 ; i < n ; i++) + for (int i = 0 ; i < json_object_array_length(event) ; 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; + rc += one_subscribe_unsubscribe(request, subscribe, json_object_get_string(x), args); + } + } + else {rc = -1;} + + return rc; +} + +/// @brief entry point for client subscription request. +static void do_subscribe_unsubscribe(afb_req request, bool subscribe) +{ + int rc = 0; + json_object *oneArg = nullptr, *args = afb_req_json(request); + if (json_object_get_type(args) == json_type_array) + { + for (int i = 0 ; i < json_object_array_length(args); i++) + { + oneArg = json_object_array_get_idx(args, i); + rc += subscribe_unsubscribe(request, subscribe, oneArg); } } - if(true) + else + { + rc = subscribe_unsubscribe(request, subscribe, args); + } + + if(rc >= 0) afb_req_success(request, NULL, NULL); else afb_req_fail(request, "error", NULL); } /// @brief entry point for client un-subscription request. +void subscribe(afb_req request) +{ + clientAppCtxT *clientAppCtx = (clientAppCtxT*)afb_req_context_make(request, 0, Composer::createContext, Composer::destroyContext, nullptr); + + //do_subscribe_unsubscribe(request, true); +} + +/// @brief entry point for client un-subscription request. void unsubscribe(afb_req request) { - if(true) - afb_req_success(request, NULL, NULL); - else - afb_req_fail(request, "error when unsubscribe", NULL); + clientAppCtxT *clientAppCtx = (clientAppCtxT*)afb_req_context_make(request, 0, Composer::createContext, Composer::destroyContext, nullptr); + + //do_subscribe_unsubscribe(request, false); } /// @brief verb that loads JSON configuration (old SigComp.json file now) diff --git a/signal-composer-binding/signal-composer.hpp b/signal-composer-binding/signal-composer.hpp index bbc9a36..afd987b 100644 --- a/signal-composer-binding/signal-composer.hpp +++ b/signal-composer-binding/signal-composer.hpp @@ -23,6 +23,13 @@ #include "source.hpp" +typedef struct clientAppCtxS +{ + uuid_t uid; + std::vector<std::shared_ptr<Signal>> subscribedSignals; + struct afb_event event; +} clientAppCtxT; + class Composer { private: |