X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=include%2Fafb%2Fafb-req-itf.h;h=af452faf0fb0d03ccd7d1eefa1fc5b1c46a5e021;hb=bca90021828565bddb8624e8f6370bf4959cbfbf;hp=f4fab5512b559dcc51e2f792e335d94b66309931;hpb=1a66f6a8c0b213e14bc0b1896bfaa68a5c2a5002;p=src%2Fapp-framework-binder.git diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h index f4fab551..af452faf 100644 --- a/include/afb/afb-req-itf.h +++ b/include/afb/afb-req-itf.h @@ -25,6 +25,8 @@ #include #include +#include + /* avoid inclusion of */ struct json_object; @@ -65,10 +67,15 @@ struct afb_req_itf { void (*session_close)(void *closure); int (*session_set_LOA)(void *closure, unsigned level); + + int (*subscribe)(void *closure, struct afb_event event); + int (*unsubscribe)(void *closure, struct afb_event event); + + void (*subcall)(void *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure); }; /* - * Describes the request by plugins from afb-daemon + * Describes the request by bindings from afb-daemon */ struct afb_req { const struct afb_req_itf *itf; /* the interface to use */ @@ -199,8 +206,8 @@ static inline void afb_req_fail_f(struct afb_req req, const char *status, const } /* - * Gets the pointer stored by the plugin for the session of 'req'. - * When the plugin has not yet recorded a pointer, NULL is returned. + * Gets the pointer stored by the binding for the session of 'req'. + * When the binding has not yet recorded a pointer, NULL is returned. */ static inline void *afb_req_context_get(struct afb_req req) { @@ -208,9 +215,9 @@ static inline void *afb_req_context_get(struct afb_req req) } /* - * Stores for the plugin the pointer 'context' to the session of 'req'. + * Stores for the binding the pointer 'context' to the session of 'req'. * The function 'free_context' will be called when the session is closed - * or if plugin stores an other pointer. + * or if binding stores an other pointer. */ static inline void afb_req_context_set(struct afb_req req, void *context, void (*free_context)(void*)) { @@ -218,7 +225,7 @@ static inline void afb_req_context_set(struct afb_req req, void *context, void ( } /* - * Gets the pointer stored by the plugin for the session of 'req'. + * Gets the pointer stored by the binding for the session of 'req'. * If the stored pointer is NULL, indicating that no pointer was * already stored, afb_req_context creates a new context by calling * the function 'create_context' and stores it with the freeing function @@ -235,7 +242,7 @@ static inline void *afb_req_context(struct afb_req req, void *(*create_context)( } /* - * Frees the pointer stored by the plugin for the session of 'req' + * Frees the pointer stored by the binding for the session of 'req' * and sets it to NULL. * * Shortcut for: afb_req_context_set(req, NULL, NULL) @@ -315,6 +322,39 @@ static inline struct afb_req afb_req_unstore(struct afb_req *req) return result; } +/* + * Establishes for the client link identified by 'req' a subscription + * to the 'event'. + * Returns 0 in case of successful subscription or -1 in case of error. + */ +static inline int afb_req_subscribe(struct afb_req req, struct afb_event event) +{ + return req.itf->subscribe(req.closure, event); +} + +/* + * Revokes the subscription established to the 'event' for the client + * link identified by 'req'. + * Returns 0 in case of successful subscription or -1 in case of error. + */ +static inline int afb_req_unsubscribe(struct afb_req req, struct afb_event event) +{ + return req.itf->unsubscribe(req.closure, event); +} + +/* + * Makes a call to the method of name 'api' / 'verb' with the object 'args'. + * This call is made in the context of the request 'req'. + * On completion, the function 'callback' is invoked with the + * 'closure' given at call and two other parameters: 'iserror' and 'result'. + * 'iserror' is a boolean that indicates if the reply is an error reply. + * 'result' is the json object of the reply. + */ +static inline void afb_req_subcall(struct afb_req req, const char *api, const char *verb, struct json_object *args, void (*callback)(void *closure, int iserror, struct json_object *result), void *closure) +{ + req.itf->subcall(req.closure, api, verb, args, callback, closure); +} + /* internal use */ static inline const char *afb_req_raw(struct afb_req req, size_t *size) {