X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=include%2Fafb%2Fafb-req-itf.h;h=a3ff9fe0cb81ed464757228ca60090e6c4f0699c;hb=457c879ff89bc7f1a8864304974999dba54af9ae;hp=a8980ffcff8ac88e5483e8bab8f1d780a2e5b13d;hpb=ed4e7e3b0690680d963bc722bc259a424099e7e5;p=src%2Fapp-framework-binder.git diff --git a/include/afb/afb-req-itf.h b/include/afb/afb-req-itf.h index a8980ffc..a3ff9fe0 100644 --- a/include/afb/afb-req-itf.h +++ b/include/afb/afb-req-itf.h @@ -97,6 +97,17 @@ static inline void afb_req_context_set(struct afb_req req, void *value, void (*f return req.itf->context_set(req.closure, value, free_value); } +static inline void *afb_req_context(struct afb_req req, void *(*create_value)(), void (*free_value)(void*)) +{ + void *result = req.itf->context_get(req.closure); + if (result == NULL) { + result = create_value(); + if (result != NULL) + req.itf->context_set(req.closure, result, free_value); + } + return result; +} + static inline void afb_req_context_clear(struct afb_req req) { afb_req_context_set(req, NULL, NULL);