X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fafb-stub-ws.c;h=ce68b441cc736fc40b980f891e6a544a827ae4b3;hb=a63851bb4726c89d9a3c5755d78d1c4bbc3f3b2e;hp=fa7e4894cc6cbb58d3cb54e4b1a751edbe605f09;hpb=052c3aee6362b2e33c060e0fbddd68439bb73dcb;p=src%2Fapp-framework-binder.git diff --git a/src/afb-stub-ws.c b/src/afb-stub-ws.c index fa7e4894..ce68b441 100644 --- a/src/afb-stub-ws.c +++ b/src/afb-stub-ws.c @@ -144,7 +144,7 @@ struct server_describe uint32_t descid; }; -/******************* client description part for server *****************************/ +/******************* stub description for client or servers ******************/ struct afb_stub_ws { @@ -181,6 +181,9 @@ struct afb_stub_ws /* apiset */ struct afb_apiset *apiset; + /* on hangup callback */ + void (*on_hangup)(struct afb_stub_ws *); + /* the api name */ char apiname[1]; }; @@ -1083,17 +1086,11 @@ static void server_send_description(struct afb_stub_ws *stubws, uint32_t descid, static void server_describe_job(int signum, void *closure) { - struct afb_api api; struct json_object *obj; struct server_describe *desc = closure; /* get the description if possible */ - obj = NULL; - if (!signum - && !afb_apiset_get(desc->stubws->apiset, desc->stubws->apiname, &api) - && api.itf->describe) { - obj = api.itf->describe(api.closure); - } + obj = !signum ? afb_apiset_describe(desc->stubws->apiset, desc->stubws->apiname) : NULL; /* send it */ server_send_description(desc->stubws, desc->descid, obj); @@ -1211,6 +1208,8 @@ static void server_on_hangup(void *closure) if (stubws->fd >= 0) { close(stubws->fd); stubws->fd = -1; + if (stubws->on_hangup) + stubws->on_hangup(stubws); } /* release the client */ @@ -1278,19 +1277,7 @@ static struct afb_stub_ws *afb_stub_ws_create(int fd, const char *apiname, struc struct afb_stub_ws *afb_stub_ws_create_client(int fd, const char *apiname, struct afb_apiset *apiset) { - struct afb_api afb_api; - struct afb_stub_ws *stubws; - - stubws = afb_stub_ws_create(fd, apiname, apiset, &stub_ws_client_ws_itf); - if (stubws) { - afb_api.closure = stubws; - afb_api.itf = &ws_api_itf; - if (afb_apiset_add(apiset, stubws->apiname, afb_api) >= 0) - return stubws; - afb_stub_ws_unref(stubws); - } - return NULL; - + return afb_stub_ws_create(fd, apiname, apiset, &stub_ws_client_ws_itf); } struct afb_stub_ws *afb_stub_ws_create_server(int fd, const char *apiname, struct afb_apiset *apiset) @@ -1333,3 +1320,28 @@ void afb_stub_ws_addref(struct afb_stub_ws *stubws) __atomic_add_fetch(&stubws->refcount, 1, __ATOMIC_RELAXED); } +void afb_stub_ws_on_hangup(struct afb_stub_ws *stubws, void (*on_hangup)(struct afb_stub_ws*)) +{ + stubws->on_hangup = on_hangup; +} + +const char *afb_stub_ws_name(struct afb_stub_ws *stubws) +{ + return stubws->apiname; +} + +struct afb_api afb_stub_ws_client_api(struct afb_stub_ws *stubws) +{ + struct afb_api api; + + assert(!stubws->listener); /* check client */ + api.closure = stubws; + api.itf = &ws_api_itf; + return api; +} + +int afb_stub_ws_client_add(struct afb_stub_ws *stubws, struct afb_apiset *apiset) +{ + return afb_apiset_add(apiset, stubws->apiname, afb_stub_ws_client_api(stubws)); +} +