X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-ws-json1.c;h=c796b17cea98d28ed54dc556bba3927f239314df;hb=b596b217c9b82d6be2b1d5486cdced31831aebc3;hp=4e405715d2d4ea1a39a3063cadf2fa973061b0b2;hpb=a138fda9841c46e28de93e32aee62956e26556b1;p=src%2Fapp-framework-binder.git diff --git a/src/afb-ws-json1.c b/src/afb-ws-json1.c index 4e405715..c796b17c 100644 --- a/src/afb-ws-json1.c +++ b/src/afb-ws-json1.c @@ -25,7 +25,7 @@ #include -#include +#include #include "afb-wsj1.h" #include "afb-ws-json1.h" @@ -33,11 +33,10 @@ #include "afb-msg-json.h" #include "afb-session.h" #include "afb-cred.h" -#include "afb-apis.h" +#include "afb-apiset.h" #include "afb-xreq.h" #include "afb-context.h" #include "afb-evt.h" -#include "afb-subcall.h" #include "verbose.h" /* predeclaration of structures */ @@ -63,6 +62,7 @@ struct afb_ws_json1 struct afb_evt_listener *listener; struct afb_wsj1 *wsj1; struct afb_cred *cred; + struct afb_apiset *apiset; int new_session; }; @@ -101,7 +101,7 @@ static const struct afb_evt_itf evt_itf = { **************************************************************** ***************************************************************/ -struct afb_ws_json1 *afb_ws_json1_create(int fd, struct afb_context *context, void (*cleanup)(void*), void *cleanup_closure) +struct afb_ws_json1 *afb_ws_json1_create(int fd, struct afb_apiset *apiset, struct afb_context *context, void (*cleanup)(void*), void *cleanup_closure) { struct afb_ws_json1 *result; @@ -129,6 +129,7 @@ struct afb_ws_json1 *afb_ws_json1_create(int fd, struct afb_context *context, vo goto error4; result->cred = afb_cred_create_for_socket(fd); + result->apiset = afb_apiset_addref(apiset); return result; error4: @@ -144,19 +145,20 @@ error: static struct afb_ws_json1 *aws_addref(struct afb_ws_json1 *ws) { - ws->refcount++; + __atomic_add_fetch(&ws->refcount, 1, __ATOMIC_RELAXED); return ws; } static void aws_unref(struct afb_ws_json1 *ws) { - if (--ws->refcount == 0) { + if (!__atomic_sub_fetch(&ws->refcount, 1, __ATOMIC_RELAXED)) { afb_evt_listener_unref(ws->listener); afb_wsj1_unref(ws->wsj1); if (ws->cleanup != NULL) ws->cleanup(ws->cleanup_closure); afb_session_unref(ws->session); afb_cred_unref(ws->cred); + afb_apiset_unref(ws->apiset); free(ws); } } @@ -200,8 +202,7 @@ static void aws_on_call(struct afb_ws_json1 *ws, const char *api, const char *ve wsreq->xreq.listener = wsreq->aws->listener; /* emits the call */ - afb_apis_call(&wsreq->xreq); - afb_xreq_unref(&wsreq->xreq); + afb_xreq_process(&wsreq->xreq, ws->apiset); } static void aws_on_event(struct afb_ws_json1 *aws, const char *event, int eventid, struct json_object *object)