aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-06-02 09:13:06 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-06-02 17:05:37 +0200
commit8a30491d5e60239a338e485311a29c43398726e9 (patch)
tree890cc1512ca1804f6857d6b1519a35ca308a1f11 /src
parentc6380108964e71f533d8c672bb9c217020a95e8d (diff)
Add 'afb_daemon_require_api'
This solution is at this time the best one to allow asynchronous calls within initialisation of bindings. Change-Id: I21ba3a74b4e93eec238a11dd51bc6b58c483308d Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/afb-ditf.c25
-rw-r--r--src/afb-hook.c25
-rw-r--r--src/afb-hook.h10
3 files changed, 56 insertions, 4 deletions
diff --git a/src/afb-ditf.c b/src/afb-ditf.c
index 66136760..66bdb9df 100644
--- a/src/afb-ditf.c
+++ b/src/afb-ditf.c
@@ -30,10 +30,14 @@
#include "afb-evt.h"
#include "afb-common.h"
#include "afb-xreq.h"
+#include "afb-api.h"
+#include "afb-apiset.h"
#include "afb-hook.h"
#include "jobs.h"
#include "verbose.h"
+extern struct afb_apiset *main_apiset;
+
/**********************************************
* normal flow
**********************************************/
@@ -106,6 +110,12 @@ static struct afb_req unstore_req_cb(void *closure, struct afb_stored_req *sreq)
return afb_xreq_unstore(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);
+}
+
/**********************************************
* hooked flow
**********************************************/
@@ -192,6 +202,15 @@ static struct afb_req hooked_unstore_req_cb(void *closure, struct afb_stored_req
return unstore_req_cb(closure, sreq);
}
+static int hooked_require_api_cb(void *closure, const char *name, int initialized)
+{
+ int result;
+ struct afb_ditf *ditf = closure;
+ afb_hook_ditf_require_api(ditf, name, initialized);
+ result = require_api_cb(closure, name, initialized);
+ return afb_hook_ditf_require_api_result(ditf, name, initialized, result);
+}
+
/**********************************************
* vectors
**********************************************/
@@ -206,7 +225,8 @@ static const struct afb_daemon_itf daemon_itf = {
.rootdir_get_fd = afb_common_rootdir_get_fd,
.rootdir_open_locale = rootdir_open_locale_cb,
.queue_job = queue_job_cb,
- .unstore_req = unstore_req_cb
+ .unstore_req = unstore_req_cb,
+ .require_api = require_api_cb
};
static const struct afb_daemon_itf hooked_daemon_itf = {
@@ -220,7 +240,8 @@ static const struct afb_daemon_itf hooked_daemon_itf = {
.rootdir_get_fd = hooked_rootdir_get_fd,
.rootdir_open_locale = hooked_rootdir_open_locale_cb,
.queue_job = hooked_queue_job_cb,
- .unstore_req = hooked_unstore_req_cb
+ .unstore_req = hooked_unstore_req_cb,
+ .require_api = hooked_require_api_cb
};
void afb_ditf_init_v2(struct afb_ditf *ditf, const char *api, struct afb_binding_data_v2 *data)
diff --git a/src/afb-hook.c b/src/afb-hook.c
index bf90732a..2f101bf5 100644
--- a/src/afb-hook.c
+++ b/src/afb-hook.c
@@ -647,6 +647,16 @@ static void hook_ditf_unstore_req_cb(void * closure, const struct afb_ditf *dit
_hook_ditf_(ditf, "unstore_req(%p)", sreq);
}
+static void hook_ditf_require_api_cb(void *closure, const struct afb_ditf *ditf, const char *name, int initialized)
+{
+ _hook_ditf_(ditf, "require_api(%s, %d)...", name, initialized);
+}
+
+static void hook_ditf_require_api_result_cb(void *closure, const struct afb_ditf *ditf, const char *name, int initialized, int result)
+{
+ _hook_ditf_(ditf, "...require_api(%s, %d) -> %d", name, initialized, result);
+}
+
static struct afb_hook_ditf_itf hook_ditf_default_itf = {
.hook_ditf_event_broadcast_before = hook_ditf_event_broadcast_before_cb,
.hook_ditf_event_broadcast_after = hook_ditf_event_broadcast_after_cb,
@@ -658,7 +668,9 @@ static struct afb_hook_ditf_itf hook_ditf_default_itf = {
.hook_ditf_rootdir_get_fd = hook_ditf_rootdir_get_fd_cb,
.hook_ditf_rootdir_open_locale = hook_ditf_rootdir_open_locale_cb,
.hook_ditf_queue_job = hook_ditf_queue_job_cb,
- .hook_ditf_unstore_req = hook_ditf_unstore_req_cb
+ .hook_ditf_unstore_req = hook_ditf_unstore_req_cb,
+ .hook_ditf_require_api = hook_ditf_require_api_cb,
+ .hook_ditf_require_api_result = hook_ditf_require_api_result_cb
};
/******************************************************************************
@@ -742,6 +754,17 @@ void afb_hook_ditf_unstore_req(const struct afb_ditf *ditf, struct afb_stored_re
_HOOK_DITF_(unstore_req, ditf, sreq);
}
+void afb_hook_ditf_require_api(const struct afb_ditf *ditf, const char *name, int initialized)
+{
+ _HOOK_DITF_(require_api, ditf, name, initialized);
+}
+
+int afb_hook_ditf_require_api_result(const struct afb_ditf *ditf, const char *name, int initialized, int result)
+{
+ _HOOK_DITF_(require_api_result, ditf, name, initialized, result);
+ return result;
+}
+
/******************************************************************************
* section: hooking ditf
*****************************************************************************/
diff --git a/src/afb-hook.h b/src/afb-hook.h
index 40700213..8e6fae3b 100644
--- a/src/afb-hook.h
+++ b/src/afb-hook.h
@@ -150,6 +150,8 @@ extern void afb_hook_xreq_unstore(const struct afb_xreq *xreq);
#define afb_hook_flag_ditf_rootdir_open_locale 0x000100
#define afb_hook_flag_ditf_queue_job 0x000200
#define afb_hook_flag_ditf_unstore_req 0x000400
+#define afb_hook_flag_ditf_require_api 0x000800
+#define afb_hook_flag_ditf_require_api_result 0x001000
#define afb_hook_flags_ditf_common (afb_hook_flag_ditf_vverbose\
|afb_hook_flag_ditf_event_make\
@@ -161,7 +163,9 @@ extern void afb_hook_xreq_unstore(const struct afb_xreq *xreq);
|afb_hook_flag_ditf_rootdir_get_fd\
|afb_hook_flag_ditf_rootdir_open_locale\
|afb_hook_flag_ditf_queue_job\
- |afb_hook_flag_ditf_unstore_req)
+ |afb_hook_flag_ditf_unstore_req\
+ |afb_hook_flag_ditf_require_api\
+ |afb_hook_flag_ditf_require_api_result)
#define afb_hook_flags_ditf_all (afb_hook_flags_ditf_common|afb_hook_flags_ditf_extra)
@@ -177,6 +181,8 @@ struct afb_hook_ditf_itf {
void (*hook_ditf_rootdir_open_locale)(void *closure, const struct afb_ditf *ditf, const char *filename, int flags, const char *locale, int result);
void (*hook_ditf_queue_job)(void *closure, const struct afb_ditf *ditf, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result);
void (*hook_ditf_unstore_req)(void *closure, const struct afb_ditf *ditf, struct afb_stored_req *sreq);
+ void (*hook_ditf_require_api)(void *closure, const struct afb_ditf *ditf, const char *name, int initialized);
+ void (*hook_ditf_require_api_result)(void *closure, const struct afb_ditf *ditf, const char *name, int initialized, int result);
};
extern void afb_hook_ditf_event_broadcast_before(const struct afb_ditf *ditf, const char *name, struct json_object *object);
@@ -190,6 +196,8 @@ extern int afb_hook_ditf_rootdir_get_fd(const struct afb_ditf *ditf, int result)
extern int afb_hook_ditf_rootdir_open_locale(const struct afb_ditf *ditf, const char *filename, int flags, const char *locale, int result);
extern int afb_hook_ditf_queue_job(const struct afb_ditf *ditf, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result);
extern void afb_hook_ditf_unstore_req(const struct afb_ditf *ditf, struct afb_stored_req *sreq);
+extern void afb_hook_ditf_require_api(const struct afb_ditf *ditf, const char *name, int initialized);
+extern int afb_hook_ditf_require_api_result(const struct afb_ditf *ditf, const char *name, int initialized, int result);
extern int afb_hook_flags_ditf(const char *api);
extern struct afb_hook_ditf *afb_hook_create_ditf(const char *api, int flags, struct afb_hook_ditf_itf *itf, void *closure);