char *p;
struct afb_ditf *ditf = closure;
- if (vasprintf(&p, fmt, args) < 0)
+ if (!fmt || vasprintf(&p, fmt, args) < 0)
vverbose(level, file, line, function, fmt, args);
else {
verbose(level, file, line, function, "[API %s] %s", ditf->api, p);
static void old_vverbose_cb(void *closure, int level, const char *file, int line, const char *fmt, va_list args)
{
- vverbose_cb(closure, level, file, line, "?", fmt, args);
+ vverbose_cb(closure, level, file, line, NULL, fmt, args);
}
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);
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);
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);
}
/**********************************************
static void hooked_old_vverbose_cb(void *closure, int level, const char *file, int line, const char *fmt, va_list args)
{
- hooked_vverbose_cb(closure, level, file, line, "?", fmt, args);
+ hooked_vverbose_cb(closure, level, file, line, NULL, fmt, args);
}
static struct afb_event hooked_event_make_cb(void *closure, const char *name)
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);
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;