X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-stub-ws.c;h=9bd8ed6355ccd95b25d57199453318ca620e71af;hb=b55f3cd48507105e85894be89557787eccfbe22f;hp=b362c127a6cbfaa06cd9e1c8b9c18e7286093468;hpb=5425e054fbf87fe6d024103f46e53f2a28e074f2;p=src%2Fapp-framework-binder.git diff --git a/src/afb-stub-ws.c b/src/afb-stub-ws.c index b362c127..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 */ @@ -145,7 +135,7 @@ struct afb_stub_ws uint8_t is_client; /* the api name */ - char apiname[1]; + char apiname[]; }; static struct afb_proto_ws *afb_stub_ws_create_proto(struct afb_stub_ws *stubws, struct fdev *fdev, uint8_t server); @@ -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; @@ -341,12 +310,12 @@ static void server_event_push_cb(void *closure, const char *event, int eventid, json_object_put(object); } -static void server_event_broadcast_cb(void *closure, const char *event, int eventid, struct json_object *object) +static void server_event_broadcast_cb(void *closure, const char *event, struct json_object *object, const uuid_binary_t uuid, uint8_t hop) { struct afb_stub_ws *stubws = closure; if (stubws->proto != NULL) - afb_proto_ws_server_event_broadcast(stubws->proto, event, object); + afb_proto_ws_server_event_broadcast(stubws->proto, event, object, uuid, hop); json_object_put(object); } @@ -457,9 +426,9 @@ static void client_on_event_push_cb(void *closure, const char *event_name, int e ERROR("unreadable push event"); } -static void client_on_event_broadcast_cb(void *closure, const char *event_name, struct json_object *data) +static void client_on_event_broadcast_cb(void *closure, const char *event_name, struct json_object *data, const uuid_binary_t uuid, uint8_t hop) { - afb_evt_broadcast(event_name, data); + afb_evt_rebroadcast(event_name, data, uuid, hop); } /*****************************************************/ @@ -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); } /*****************************************************/ @@ -649,7 +594,7 @@ static void on_hangup(void *closure) static int enqueue_processing(struct afb_proto_ws *proto, void (*callback)(int signum, void* arg), void *arg) { - return jobs_queue(NULL /* proto */, 0, callback, arg); + return jobs_queue(proto, 0, callback, arg); } /*****************************************************/ @@ -673,7 +618,7 @@ static struct afb_stub_ws *afb_stub_ws_create(struct fdev *fdev, const char *api { struct afb_stub_ws *stubws; - stubws = calloc(1, sizeof *stubws + strlen(apiname)); + stubws = calloc(1, sizeof *stubws + 1 + strlen(apiname)); if (stubws == NULL) errno = ENOMEM; else {