diff options
-rw-r--r-- | bindings/tutorial/tuto-3.cpp | 9 | ||||
-rw-r--r-- | include/afb/c++/binding-wrap.hpp | 34 |
2 files changed, 37 insertions, 6 deletions
diff --git a/bindings/tutorial/tuto-3.cpp b/bindings/tutorial/tuto-3.cpp index 66f8e83a..8ad69ef3 100644 --- a/bindings/tutorial/tuto-3.cpp +++ b/bindings/tutorial/tuto-3.cpp @@ -6,11 +6,10 @@ afb::event event_login, event_logout; -void login(afb_req_t r) +void login(afb::req req) { json_object *args, *user, *passwd; char *usr; - afb::req req(r); args = req.json(); if (!json_object_object_get_ex(args, "user", &user) @@ -33,11 +32,10 @@ void login(afb_req_t r) } } -void action(afb_req_t r) +void action(afb::req req) { json_object *args, *val; char *usr; - afb::req req(r); args = req.json(); // usr = (char*)req.context_get(); @@ -57,10 +55,9 @@ usr = nullptr; req.success(json_object_get(args)); } -void logout(afb_req_t r) +void logout(afb::req req) { char *usr; - afb::req req(r); // usr = (char*)req.context_get(); usr = nullptr; diff --git a/include/afb/c++/binding-wrap.hpp b/include/afb/c++/binding-wrap.hpp index 0a5a5e25..8eddc58b 100644 --- a/include/afb/c++/binding-wrap.hpp +++ b/include/afb/c++/binding-wrap.hpp @@ -571,6 +571,40 @@ constexpr afb_verb_t verb( return r; } +#if AFB_BINDING_VERSION >= 3 +void __afb__verb__cb__for__global__(afb_req_t r) +{ + void *vcbdata; + void (*callback)(req); + + vcbdata = afb_req_get_vcbdata(r); + callback = reinterpret_cast<void(*)(req)>(vcbdata); + callback(req(r)); +} + +constexpr afb_verb_t verb( + const char *name, + void (&callback)(req), + const char *info = nullptr, + uint16_t session = 0, + const afb_auth *auth = nullptr + , + bool glob = false, + void *vcbdata = nullptr +) +{ + return verb( + name, + __afb__verb__cb__for__global__, + info, + session, + auth, + glob, + reinterpret_cast<void*>(&callback) + ); +} +#endif + constexpr afb_verb_t verbend() { afb_verb_t r = verb(nullptr, nullptr); |