X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fafb-ditf.c;h=28cd46a73ffb5f4d453d688e35a1e63a79ed0e4e;hb=b355a2a65511c32aaaddf289d70395f872bd4b26;hp=66bdb9df146ec0fab4876a29049535437c506011;hpb=8a30491d5e60239a338e485311a29c43398726e9;p=src%2Fapp-framework-binder.git diff --git a/src/afb-ditf.c b/src/afb-ditf.c index 66bdb9df..28cd46a7 100644 --- a/src/afb-ditf.c +++ b/src/afb-ditf.c @@ -65,6 +65,14 @@ static struct afb_event event_make_cb(void *closure, const char *name) char *event; struct afb_ditf *ditf = closure; + /* check daemon state */ + if (ditf->state == Daemon_Pre_Init) { + + ERROR("[API %s] Bad call to 'afb_daemon_event_make(%s)', must not be in PreInit", ditf->api, name); + errno = EINVAL; + return (struct afb_event){ .itf = NULL, .closure = NULL }; + } + /* makes the event name */ plen = strlen(ditf->api); nlen = strlen(name); @@ -83,6 +91,14 @@ static int event_broadcast_cb(void *closure, const char *name, struct json_objec char *event; struct afb_ditf *ditf = closure; + /* check daemon state */ + if (ditf->state == Daemon_Pre_Init) { + + ERROR("[API %s] Bad call to 'afb_daemon_event_broadcast(%s, %s)', must not be in PreInit", ditf->api, name, json_object_to_json_string(object)); + errno = EINVAL; + return 0; + } + /* makes the event name */ plen = strlen(ditf->api); nlen = strlen(name); @@ -112,8 +128,13 @@ static struct afb_req unstore_req_cb(void *closure, struct afb_stored_req *sreq) static int require_api_cb(void *closure, const char *name, int initialized) { - struct afb_api a; - return (initialized ? afb_apiset_get_started : afb_apiset_get)(main_apiset, name, &a); + struct afb_ditf *ditf = closure; + if (ditf->state != Daemon_Init) { + ERROR("[API %s] Bad call to 'afb_daemon_require(%s, %d)', must be in Init", ditf->api, name, initialized); + errno = EINVAL; + return -1; + } + return -!(initialized ? afb_apiset_lookup_started : afb_apiset_lookup)(main_apiset, name, 1); } /********************************************** @@ -247,6 +268,7 @@ static const struct afb_daemon_itf hooked_daemon_itf = { void afb_ditf_init_v2(struct afb_ditf *ditf, const char *api, struct afb_binding_data_v2 *data) { ditf->version = 2; + ditf->state = Daemon_Pre_Init; ditf->v2 = data; data->daemon.closure = ditf; afb_ditf_rename(ditf, api); @@ -255,6 +277,7 @@ void afb_ditf_init_v2(struct afb_ditf *ditf, const char *api, struct afb_binding void afb_ditf_init_v1(struct afb_ditf *ditf, const char *api, struct afb_binding_interface_v1 *itf) { ditf->version = 1; + ditf->state = Daemon_Pre_Init; ditf->v1 = itf; itf->verbosity = verbosity; itf->mode = AFB_MODE_LOCAL;