X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-stub-ws.c;h=9bd8ed6355ccd95b25d57199453318ca620e71af;hb=b55f3cd48507105e85894be89557787eccfbe22f;hp=6a52f6fc5e69f9098057c1aabbb67c9dcd043bd9;hpb=6dfeafe7e4fa582b3db3f950136bc97f8611fc6d;p=src%2Fapp-framework-binder.git diff --git a/src/afb-stub-ws.c b/src/afb-stub-ws.c index 6a52f6fc..9bd8ed63 100644 --- a/src/afb-stub-ws.c +++ b/src/afb-stub-ws.c @@ -70,16 +70,6 @@ struct client_event int refcount; /**< a reference count */ }; -/** - * structure for recording describe requests on the client side - */ -struct client_describe -{ - struct afb_stub_ws *stubws; /**< the stub */ - struct jobloop *jobloop; /**< the jobloop to leave */ - struct json_object *result; /**< result */ -}; - /** * structure for jobs of describing */ @@ -280,43 +270,22 @@ static void client_api_call_cb(void * closure, struct afb_xreq *xreq) } } -static void client_on_description_cb(void *closure, struct json_object *data) -{ - struct client_describe *desc = closure; - - desc->result = data; - jobs_leave(desc->jobloop); -} - -static void client_send_describe_cb(int signum, void *closure, struct jobloop *jobloop) -{ - struct client_describe *desc = closure; - struct afb_proto_ws *proto; - - proto = client_get_proto(desc->stubws); - if (signum || proto == NULL) - jobs_leave(jobloop); - else { - desc->jobloop = jobloop; - afb_proto_ws_client_describe(proto, client_on_description_cb, desc); - } -} - /* get the description */ -static struct json_object *client_api_describe_cb(void * closure) +static void client_api_describe_cb(void * closure, void (*describecb)(void *, struct json_object *), void *clocb) { - struct client_describe desc; + struct afb_stub_ws *stubws = closure; + struct afb_proto_ws *proto; - /* synchronous job: send the request and wait its result */ - desc.stubws = closure; - desc.result = NULL; - jobs_enter(NULL, 0, client_send_describe_cb, &desc); - return desc.result; + proto = client_get_proto(stubws); + if (proto) + afb_proto_ws_client_describe(proto, describecb, clocb); + else + describecb(clocb, NULL); } /******************* server part: manage events **********************************/ -static void server_event_add_cb(void *closure, const char *event, int eventid) +static void server_event_add_cb(void *closure, const char *event, uint16_t eventid) { struct afb_stub_ws *stubws = closure; @@ -324,7 +293,7 @@ static void server_event_add_cb(void *closure, const char *event, int eventid) afb_proto_ws_server_event_create(stubws->proto, event, eventid); } -static void server_event_remove_cb(void *closure, const char *event, int eventid) +static void server_event_remove_cb(void *closure, const char *event, uint16_t eventid) { struct afb_stub_ws *stubws = closure; @@ -332,7 +301,7 @@ static void server_event_remove_cb(void *closure, const char *event, int eventid afb_proto_ws_server_event_remove(stubws->proto, event, eventid); } -static void server_event_push_cb(void *closure, const char *event, int eventid, struct json_object *object) +static void server_event_push_cb(void *closure, const char *event, uint16_t eventid, struct json_object *object) { struct afb_stub_ws *stubws = closure; @@ -523,15 +492,14 @@ static void server_on_call_cb(void *closure, struct afb_proto_ws_call *call, con wreq->call = call; /* init the context */ - if (afb_context_connect(&wreq->xreq.context, sessionid, NULL) < 0) + if (afb_context_connect_validated(&wreq->xreq.context, sessionid) < 0) goto unconnected; - wreq->xreq.context.validated = 1; server_record_session(stubws, wreq->xreq.context.session); if (wreq->xreq.context.created) afb_session_set_autoclose(wreq->xreq.context.session, 1); /* makes the call */ - wreq->xreq.cred = afb_cred_mixed_on_behalf_import(stubws->cred, sessionid, user_creds); + wreq->xreq.cred = afb_cred_mixed_on_behalf_import(stubws->cred, &wreq->xreq.context, user_creds); wreq->xreq.request.called_api = stubws->apiname; wreq->xreq.request.called_verb = verb; wreq->xreq.json = args; @@ -547,42 +515,19 @@ out_of_memory: afb_proto_ws_call_unref(call); } -static void server_describe_cb(int signum, void *closure) +static void server_on_description_cb(void *closure, struct json_object *description) { - struct json_object *obj; - struct server_describe *desc = closure; - - /* get the description if possible */ - obj = !signum ? afb_apiset_describe(desc->stubws->apiset, desc->stubws->apiname) : NULL; - - /* send it */ - afb_proto_ws_describe_put(desc->describe, obj); - json_object_put(obj); - afb_stub_ws_unref(desc->stubws); + struct afb_proto_ws_describe *describe = closure; + afb_proto_ws_describe_put(describe, description); + json_object_put(description); } -static void server_describe_job(int signum, void *closure) -{ - server_describe_cb(signum, closure); - free(closure); -} static void server_on_describe_cb(void *closure, struct afb_proto_ws_describe *describe) { - struct server_describe *desc, sdesc; struct afb_stub_ws *stubws = closure; - /* allocate (if possible) and init */ - desc = malloc(sizeof *desc); - if (desc == NULL) - desc = &sdesc; - desc->stubws = stubws; - desc->describe = describe; - afb_stub_ws_addref(stubws); - - /* process */ - if (desc == &sdesc || jobs_queue(NULL, 0, server_describe_job, desc) < 0) - jobs_call(NULL, 0, server_describe_cb, desc); + afb_apiset_describe(stubws->apiset, stubws->apiname, server_on_description_cb, describe); } /*****************************************************/