X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=include%2Fafb%2Fafb-req-itf.h;h=3efb089df2d2771a0a16fd789fbc05225f79b1c9;hb=da61b6ea09f77ea5a8ff6cb79b440db858980211;hp=8530e05d09597194d03e1f723608a508a5728bb4;hpb=50d35140570377d8ee9f0ace78ea825651034829;p=src%2Fapp-framework-binder.git diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h index 8530e05d..3efb089d 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,6 +67,11 @@ 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); }; /* @@ -130,6 +137,10 @@ static inline struct json_object *afb_req_json(struct afb_req req) * The status of the reply is automatically set to "success". * Its send the object 'obj' (can be NULL) with an * informationnal comment 'info (can also be NULL). + * + * For conveniency, the function calls 'json_object_put' for 'obj'. + * Thus, in the case where 'obj' should remain available after + * the function returns, the function 'json_object_get' shall be used. */ static inline void afb_req_success(struct afb_req req, struct json_object *obj, const char *info) { @@ -139,6 +150,10 @@ static inline void afb_req_success(struct afb_req req, struct json_object *obj, /* * Same as 'afb_req_success' but the 'info' is a formatting * string followed by arguments. + * + * For conveniency, the function calls 'json_object_put' for 'obj'. + * Thus, in the case where 'obj' should remain available after + * the function returns, the function 'json_object_get' shall be used. */ static inline void afb_req_success_f(struct afb_req req, struct json_object *obj, const char *info, ...) { @@ -160,6 +175,10 @@ static inline void afb_req_success_f(struct afb_req req, struct json_object *obj * Note that calling afb_req_fail("success", info) is equivalent * to call afb_req_success(NULL, info). Thus even if possible it * is strongly recommanded to NEVER use "success" for status. + * + * For conveniency, the function calls 'json_object_put' for 'obj'. + * Thus, in the case where 'obj' should remain available after + * the function returns, the function 'json_object_get' shall be used. */ static inline void afb_req_fail(struct afb_req req, const char *status, const char *info) { @@ -169,6 +188,10 @@ static inline void afb_req_fail(struct afb_req req, const char *status, const ch /* * Same as 'afb_req_fail' but the 'info' is a formatting * string followed by arguments. + * + * For conveniency, the function calls 'json_object_put' for 'obj'. + * Thus, in the case where 'obj' should remain available after + * the function returns, the function 'json_object_get' shall be used. */ static inline void afb_req_fail_f(struct afb_req req, const char *status, const char *info, ...) { @@ -259,7 +282,7 @@ static inline void afb_req_session_close(struct afb_req req) } /* - * Sets the level of authorisation of the session of 'req' + * Sets the level of assurance of the session of 'req' * to 'level'. The effect of this function is subject of * security policies. * Returns 1 on success or 0 if failed. @@ -299,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) {