X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=include%2Fafb%2Fafb-req-itf.h;h=34d73dd2a324bdfa3c047213a7040660ab4dd1c5;hb=6f1126ae2c585afc34d0bb06f3763e3a82ee3d37;hp=740b3ac0554a4cc35622e4dfb51aa70d5135dab6;hpb=1d0f869ce3379089b4f4c5285e3d30e971e5b93d;p=src%2Fapp-framework-binder.git diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h index 740b3ac0..34d73dd2 100644 --- a/include/afb/afb-req-itf.h +++ b/include/afb/afb-req-itf.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2016 "IoT.bzh" + * Copyright (C) 2016, 2017 "IoT.bzh" * Author: José Bollo * * Licensed under the Apache License, Version 2.0 (the "License"); @@ -25,7 +25,7 @@ #include #include -#include +#include "afb-event-itf.h" /* avoid inclusion of */ struct json_object; @@ -46,7 +46,7 @@ struct afb_arg { * It records the functions to be called for the request. * Don't use this structure directly. * Use the helper functions documented below. - */ + */ struct afb_req_itf { /* CAUTION: respect the order, add at the end */ @@ -56,8 +56,8 @@ struct afb_req_itf { void (*success)(void *closure, struct json_object *obj, const char *info); void (*fail)(void *closure, const char *status, const char *info); - const char *(*raw)(void *closure, size_t *size); - void (*send)(void *closure, const char *buffer, size_t size); + /*legacy raw */void (*spare1)(void *closure); + /*legacy send*/void (*spare2)(void *closure); void *(*context_get)(void *closure); void (*context_set)(void *closure, void *value, void (*free_value)(void*)); @@ -72,6 +72,7 @@ struct afb_req_itf { 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); + int (*subcallsync)(void *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result); }; /* @@ -82,6 +83,16 @@ struct afb_req { void *closure; /* the closure argument for functions of 'itf' */ }; +/* + * Checks wether the request 'req' is valid or not. + * + * Returns 0 if not valid or 1 if valid. + */ +static inline int afb_req_is_valid(struct afb_req req) +{ + return req.itf != NULL; +} + /* * Gets from the request 'req' the argument of 'name'. * Returns a PLAIN structure of type 'struct afb_arg'. @@ -300,7 +311,7 @@ static inline int afb_req_session_set_LOA(struct afb_req req, unsigned level) */ static inline struct afb_req *afb_req_store(struct afb_req req) { - struct afb_req *result = malloc(sizeof *result); + struct afb_req *result = (struct afb_req*)malloc(sizeof *result); if (result != NULL) { *result = req; afb_req_addref(req); @@ -348,22 +359,32 @@ static inline int afb_req_unsubscribe(struct afb_req req, struct afb_event event * 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. + * 'result' is the json object of the reply, you must not call json_object_put + * on the result. + * + * For convenience, the function calls 'json_object_put' for 'args'. + * Thus, in the case where 'args' should remain available after + * the function returns, the function 'json_object_get' shall be used. */ 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) -{ - return req.itf->raw(req.closure, size); -} - -/* internal use */ -static inline void afb_req_send(struct afb_req req, const char *buffer, size_t size) +/* + * 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'. + * This call is synchronous, it waits untill completion of the request. + * It returns 0 on an error answer and returns 1 when no error was detected. + * The object pointed by 'result' is filled and must be released by the caller + * after its use by calling 'json_object_put'. + * + * For convenience, the function calls 'json_object_put' for 'args'. + * Thus, in the case where 'args' should remain available after + * the function returns, the function 'json_object_get' shall be used. + */ +static inline int afb_req_subcall_sync(struct afb_req req, const char *api, const char *verb, struct json_object *args, struct json_object **result) { - req.itf->send(req.closure, buffer, size); + return req.itf->subcallsync(req.closure, api, verb, args, result); }