X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?p=src%2Fapp-framework-binder.git;a=blobdiff_plain;f=src%2Fafb-stub-ws.c;h=9bd8ed6355ccd95b25d57199453318ca620e71af;hp=2a48745bb013579a552cd44c0c9bb42387402fa5;hb=b55f3cd48507105e85894be89557787eccfbe22f;hpb=eaf5670e9d10b5d7c066043e7563706cf1e01bd5 diff --git a/src/afb-stub-ws.c b/src/afb-stub-ws.c index 2a48745b..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,38 +270,17 @@ 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 **********************************/ @@ -546,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); } /*****************************************************/