aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-06-02 16:32:44 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-06-02 17:05:37 +0200
commitc6380108964e71f533d8c672bb9c217020a95e8d (patch)
tree2b3678d53bee7e55ef8befe113fd7e8744067875 /src
parentd3c80685ed6067f4899635c0328bbd8b70a2ed90 (diff)
Provide efficient store/unstore for afb_req
Change-Id: I231e2506f58227fb8d192df042539b1551a765c5 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r--src/afb-api-dbus.c2
-rw-r--r--src/afb-apiset.c2
-rw-r--r--src/afb-ditf.c22
-rw-r--r--src/afb-hook.c41
-rw-r--r--src/afb-hook.h17
-rw-r--r--src/afb-hreq.c2
-rw-r--r--src/afb-hswitch.c1
-rw-r--r--src/afb-stub-ws.c2
-rw-r--r--src/afb-subcall.c2
-rw-r--r--src/afb-ws-json1.c2
-rw-r--r--src/afb-xreq.c28
-rw-r--r--src/afb-xreq.h3
12 files changed, 106 insertions, 18 deletions
diff --git a/src/afb-api-dbus.c b/src/afb-api-dbus.c
index 4689ad1f..0e51c636 100644
--- a/src/afb-api-dbus.c
+++ b/src/afb-api-dbus.c
@@ -27,7 +27,7 @@
#include <systemd/sd-bus.h>
#include <json-c/json.h>
-#include <afb/afb-req-itf.h>
+#include <afb/afb-event-itf.h>
#include "afb-common.h"
diff --git a/src/afb-apiset.c b/src/afb-apiset.c
index 410ff276..c934e8cd 100644
--- a/src/afb-apiset.c
+++ b/src/afb-apiset.c
@@ -31,8 +31,6 @@
#include "afb-xreq.h"
#include "jobs.h"
-#include <afb/afb-req-itf.h>
-
#define INCR 8 /* CAUTION: must be a power of 2 */
/**
diff --git a/src/afb-ditf.c b/src/afb-ditf.c
index b5a50930..66136760 100644
--- a/src/afb-ditf.c
+++ b/src/afb-ditf.c
@@ -29,6 +29,7 @@
#include "afb-ditf.h"
#include "afb-evt.h"
#include "afb-common.h"
+#include "afb-xreq.h"
#include "afb-hook.h"
#include "jobs.h"
#include "verbose.h"
@@ -100,6 +101,11 @@ static int queue_job_cb(void *closure, void (*callback)(int signum, void *arg),
return jobs_queue(group, timeout, callback, argument);
}
+static struct afb_req unstore_req_cb(void *closure, struct afb_stored_req *sreq)
+{
+ return afb_xreq_unstore(sreq);
+}
+
/**********************************************
* hooked flow
**********************************************/
@@ -179,6 +185,16 @@ static int hooked_queue_job_cb(void *closure, void (*callback)(int signum, void
return afb_hook_ditf_queue_job(ditf, callback, argument, group, timeout, r);
}
+static struct afb_req hooked_unstore_req_cb(void *closure, struct afb_stored_req *sreq)
+{
+ struct afb_ditf *ditf = closure;
+ afb_hook_ditf_unstore_req(ditf, sreq);
+ return unstore_req_cb(closure, sreq);
+}
+
+/**********************************************
+* vectors
+**********************************************/
static const struct afb_daemon_itf daemon_itf = {
.vverbose_v1 = old_vverbose_cb,
.vverbose_v2 = vverbose_cb,
@@ -189,7 +205,8 @@ static const struct afb_daemon_itf daemon_itf = {
.get_system_bus = afb_common_get_system_bus,
.rootdir_get_fd = afb_common_rootdir_get_fd,
.rootdir_open_locale = rootdir_open_locale_cb,
- .queue_job = queue_job_cb
+ .queue_job = queue_job_cb,
+ .unstore_req = unstore_req_cb
};
static const struct afb_daemon_itf hooked_daemon_itf = {
@@ -202,7 +219,8 @@ static const struct afb_daemon_itf hooked_daemon_itf = {
.get_system_bus = hooked_get_system_bus,
.rootdir_get_fd = hooked_rootdir_get_fd,
.rootdir_open_locale = hooked_rootdir_open_locale_cb,
- .queue_job = hooked_queue_job_cb
+ .queue_job = hooked_queue_job_cb,
+ .unstore_req = hooked_unstore_req_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 6a11341c..bf90732a 100644
--- a/src/afb-hook.c
+++ b/src/afb-hook.c
@@ -27,7 +27,7 @@
#include <json-c/json.h>
-#include <afb/afb-req-itf.h>
+#include <afb/afb-req-common.h>
#include <afb/afb-event-itf.h>
#include "afb-context.h"
@@ -271,6 +271,16 @@ static void hook_xreq_vverbose_default_cb(void * closure, const struct afb_xreq
}
}
+static void hook_xreq_store_default_cb(void * closure, const struct afb_xreq *xreq, struct afb_stored_req *sreq)
+{
+ _hook_xreq_(xreq, "store() -> %p", sreq);
+}
+
+static void hook_xreq_unstore_default_cb(void * closure, const struct afb_xreq *xreq)
+{
+ _hook_xreq_(xreq, "unstore()");
+}
+
static struct afb_hook_xreq_itf hook_xreq_default_itf = {
.hook_xreq_begin = hook_xreq_begin_default_cb,
.hook_xreq_end = hook_xreq_end_default_cb,
@@ -290,7 +300,9 @@ static struct afb_hook_xreq_itf hook_xreq_default_itf = {
.hook_xreq_subcall_result = hook_xreq_subcall_result_default_cb,
.hook_xreq_subcallsync = hook_xreq_subcallsync_default_cb,
.hook_xreq_subcallsync_result = hook_xreq_subcallsync_result_default_cb,
- .hook_xreq_vverbose = hook_xreq_vverbose_default_cb
+ .hook_xreq_vverbose = hook_xreq_vverbose_default_cb,
+ .hook_xreq_store = hook_xreq_store_default_cb,
+ .hook_xreq_unstore = hook_xreq_unstore_default_cb
};
/******************************************************************************
@@ -416,6 +428,16 @@ void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const char *
_HOOK_XREQ_(vverbose, xreq, level, file ?: "?", line, func ?: "?", fmt, args);
}
+void afb_hook_xreq_store(const struct afb_xreq *xreq, struct afb_stored_req *sreq)
+{
+ _HOOK_XREQ_(store, xreq, sreq);
+}
+
+void afb_hook_xreq_unstore(const struct afb_xreq *xreq)
+{
+ _HOOK_XREQ_(unstore, xreq);
+}
+
/******************************************************************************
* section: hooking xreqs
*****************************************************************************/
@@ -615,11 +637,16 @@ static void hook_ditf_rootdir_open_locale_cb(void *closure, const struct afb_dit
}
}
-static 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)
+static void hook_ditf_queue_job_cb(void *closure, const struct afb_ditf *ditf, void (*callback)(int signum, void *arg), void *argument, void *group, int timeout, int result)
{
_hook_ditf_(ditf, "queue_job(%p, %p, %p, %d) -> %d", callback, argument, group, timeout, result);
}
+static void hook_ditf_unstore_req_cb(void * closure, const struct afb_ditf *ditf, struct afb_stored_req *sreq)
+{
+ _hook_ditf_(ditf, "unstore_req(%p)", sreq);
+}
+
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,
@@ -630,7 +657,8 @@ static struct afb_hook_ditf_itf hook_ditf_default_itf = {
.hook_ditf_event_make = hook_ditf_event_make_cb,
.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
+ .hook_ditf_queue_job = hook_ditf_queue_job_cb,
+ .hook_ditf_unstore_req = hook_ditf_unstore_req_cb
};
/******************************************************************************
@@ -709,6 +737,11 @@ int afb_hook_ditf_queue_job(const struct afb_ditf *ditf, void (*callback)(int si
return result;
}
+void afb_hook_ditf_unstore_req(const struct afb_ditf *ditf, struct afb_stored_req *sreq)
+{
+ _HOOK_DITF_(unstore_req, ditf, sreq);
+}
+
/******************************************************************************
* section: hooking ditf
*****************************************************************************/
diff --git a/src/afb-hook.h b/src/afb-hook.h
index 91736386..40700213 100644
--- a/src/afb-hook.h
+++ b/src/afb-hook.h
@@ -28,6 +28,7 @@ struct afb_session;
struct afb_xreq;
struct afb_ditf;
struct afb_svc;
+struct afb_stored_req;
struct sd_bus;
struct sd_event;
@@ -56,6 +57,8 @@ struct afb_hook_xreq;
#define afb_hook_flag_req_subcallsync 0x020000
#define afb_hook_flag_req_subcallsync_result 0x040000
#define afb_hook_flag_req_vverbose 0x080000
+#define afb_hook_flag_req_store 0x100000
+#define afb_hook_flag_req_unstore 0x200000
/* common flags */
#define afb_hook_flags_req_life (afb_hook_flag_req_begin|afb_hook_flag_req_end)
@@ -69,12 +72,14 @@ struct afb_hook_xreq;
/* extra flags */
#define afb_hook_flags_req_ref (afb_hook_flag_req_addref|afb_hook_flag_req_unref)
#define afb_hook_flags_req_context (afb_hook_flag_req_context_get|afb_hook_flag_req_context_set)
+#define afb_hook_flags_req_store (afb_hook_flag_req_store|afb_hook_flag_req_unstore)
/* predefined groups */
#define afb_hook_flags_req_common (afb_hook_flags_req_life|afb_hook_flags_req_args|afb_hook_flags_req_result\
|afb_hook_flags_req_session|afb_hook_flags_req_event|afb_hook_flags_req_subcall\
|afb_hook_flag_req_vverbose)
-#define afb_hook_flags_req_extra (afb_hook_flags_req_common|afb_hook_flags_req_ref|afb_hook_flags_req_context)
+#define afb_hook_flags_req_extra (afb_hook_flags_req_common|afb_hook_flags_req_ref|afb_hook_flags_req_context\
+ |afb_hook_flags_req_store)
#define afb_hook_flags_req_all (afb_hook_flags_req_extra)
struct afb_hook_xreq_itf {
@@ -97,6 +102,8 @@ struct afb_hook_xreq_itf {
void (*hook_xreq_subcallsync)(void * closure, const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
void (*hook_xreq_subcallsync_result)(void * closure, const struct afb_xreq *xreq, int status, struct json_object *result);
void (*hook_xreq_vverbose)(void * closure, const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args);
+ void (*hook_xreq_store)(void * closure, const struct afb_xreq *xreq, struct afb_stored_req *sreq);
+ void (*hook_xreq_unstore)(void * closure, const struct afb_xreq *xreq);
};
extern void afb_hook_init_xreq(struct afb_xreq *xreq);
@@ -125,6 +132,8 @@ extern void afb_hook_xreq_subcall_result(const struct afb_xreq *xreq, int status
extern void afb_hook_xreq_subcallsync(const struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args);
extern int afb_hook_xreq_subcallsync_result(const struct afb_xreq *xreq, int status, struct json_object *result);
extern void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const char *file, int line, const char *func, const char *fmt, va_list args);
+extern void afb_hook_xreq_store(const struct afb_xreq *xreq, struct afb_stored_req *sreq);
+extern void afb_hook_xreq_unstore(const struct afb_xreq *xreq);
/*********************************************************
* section hooking ditf (daemon interface)
@@ -140,6 +149,7 @@ extern void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const
#define afb_hook_flag_ditf_rootdir_get_fd 0x000080
#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_flags_ditf_common (afb_hook_flag_ditf_vverbose\
|afb_hook_flag_ditf_event_make\
@@ -150,7 +160,8 @@ extern void afb_hook_xreq_vverbose(const struct afb_xreq *xreq, int level, const
|afb_hook_flag_ditf_get_system_bus\
|afb_hook_flag_ditf_rootdir_get_fd\
|afb_hook_flag_ditf_rootdir_open_locale\
- |afb_hook_flag_ditf_queue_job)
+ |afb_hook_flag_ditf_queue_job\
+ |afb_hook_flag_ditf_unstore_req)
#define afb_hook_flags_ditf_all (afb_hook_flags_ditf_common|afb_hook_flags_ditf_extra)
@@ -165,6 +176,7 @@ struct afb_hook_ditf_itf {
void (*hook_ditf_rootdir_get_fd)(void *closure, const struct afb_ditf *ditf, int result);
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);
};
extern void afb_hook_ditf_event_broadcast_before(const struct afb_ditf *ditf, const char *name, struct json_object *object);
@@ -177,6 +189,7 @@ extern struct afb_event afb_hook_ditf_event_make(const struct afb_ditf *ditf, co
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 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);
diff --git a/src/afb-hreq.c b/src/afb-hreq.c
index b87251be..9c630912 100644
--- a/src/afb-hreq.c
+++ b/src/afb-hreq.c
@@ -33,7 +33,7 @@
#endif
#include "afb-method.h"
-#include <afb/afb-req-itf.h>
+#include <afb/afb-req-common.h>
#include "afb-msg-json.h"
#include "afb-context.h"
#include "afb-hreq.h"
diff --git a/src/afb-hswitch.c b/src/afb-hswitch.c
index 34eafd5b..8132f232 100644
--- a/src/afb-hswitch.c
+++ b/src/afb-hswitch.c
@@ -23,7 +23,6 @@
#include <microhttpd.h>
-#include <afb/afb-req-itf.h>
#include "afb-context.h"
#include "afb-hreq.h"
#include "afb-apiset.h"
diff --git a/src/afb-stub-ws.c b/src/afb-stub-ws.c
index 43837e58..1dc19fb4 100644
--- a/src/afb-stub-ws.c
+++ b/src/afb-stub-ws.c
@@ -35,7 +35,7 @@
#include <json-c/json.h>
#include <systemd/sd-event.h>
-#include <afb/afb-req-itf.h>
+#include <afb/afb-event-itf.h>
#include "afb-common.h"
diff --git a/src/afb-subcall.c b/src/afb-subcall.c
index 857f48ed..3c75b179 100644
--- a/src/afb-subcall.c
+++ b/src/afb-subcall.c
@@ -21,7 +21,7 @@
#include <string.h>
#include <json-c/json.h>
-#include <afb/afb-req-itf.h>
+#include <afb/afb-event-itf.h>
#include "afb-subcall.h"
#include "afb-msg-json.h"
diff --git a/src/afb-ws-json1.c b/src/afb-ws-json1.c
index 4b6c04eb..45e1cdb0 100644
--- a/src/afb-ws-json1.c
+++ b/src/afb-ws-json1.c
@@ -25,7 +25,7 @@
#include <json-c/json.h>
-#include <afb/afb-req-itf.h>
+#include <afb/afb-event-itf.h>
#include "afb-wsj1.h"
#include "afb-ws-json1.h"
diff --git a/src/afb-xreq.c b/src/afb-xreq.c
index 9c4cab8f..80fa9636 100644
--- a/src/afb-xreq.c
+++ b/src/afb-xreq.c
@@ -279,6 +279,12 @@ static void xreq_vverbose_cb(void*closure, int level, const char *file, int line
vverbose(level, file, line, func, fmt, args);
}
+static struct afb_stored_req *xreq_store_cb(void *closure)
+{
+ xreq_addref_cb(closure);
+ return closure;
+}
+
/******************************************************************************/
static struct json_object *xreq_hooked_json_cb(void *closure)
@@ -429,6 +435,14 @@ static void xreq_hooked_vverbose_cb(void*closure, int level, const char *file, i
va_end(ap);
}
+static struct afb_stored_req *xreq_hooked_store_cb(void *closure)
+{
+ struct afb_xreq *xreq = closure;
+ struct afb_stored_req *r = xreq_store_cb(closure);
+ afb_hook_xreq_store(xreq, r);
+ return r;
+}
+
/******************************************************************************/
const struct afb_req_itf xreq_itf = {
@@ -448,7 +462,8 @@ const struct afb_req_itf xreq_itf = {
.unsubscribe = xreq_unsubscribe_cb,
.subcall = xreq_subcall_cb,
.subcallsync = xreq_subcallsync_cb,
- .vverbose = xreq_vverbose_cb
+ .vverbose = xreq_vverbose_cb,
+ .store = xreq_store_cb
};
const struct afb_req_itf xreq_hooked_itf = {
@@ -468,7 +483,8 @@ const struct afb_req_itf xreq_hooked_itf = {
.unsubscribe = xreq_hooked_unsubscribe_cb,
.subcall = xreq_hooked_subcall_cb,
.subcallsync = xreq_hooked_subcallsync_cb,
- .vverbose = xreq_hooked_vverbose_cb
+ .vverbose = xreq_hooked_vverbose_cb,
+ .store = xreq_hooked_store_cb
};
static inline struct afb_req to_req(struct afb_xreq *xreq)
@@ -478,6 +494,14 @@ static inline struct afb_req to_req(struct afb_xreq *xreq)
/******************************************************************************/
+struct afb_req afb_xreq_unstore(struct afb_stored_req *sreq)
+{
+ struct afb_xreq *xreq = (struct afb_xreq *)sreq;
+ if (xreq->hookflags)
+ afb_hook_xreq_unstore(xreq);
+ return to_req(xreq);
+}
+
struct json_object *afb_xreq_json(struct afb_xreq *xreq)
{
return afb_req_json(to_req(xreq));
diff --git a/src/afb-xreq.h b/src/afb-xreq.h
index a37b6bfd..42307742 100644
--- a/src/afb-xreq.h
+++ b/src/afb-xreq.h
@@ -27,6 +27,8 @@ struct afb_apiset;
struct afb_event;
struct afb_verb_desc_v1;
struct afb_verb_v2;
+struct afb_req;
+struct afb_stored_req;
struct afb_xreq_query_itf {
struct json_object *(*json)(struct afb_xreq *xreq);
@@ -85,6 +87,7 @@ struct afb_xreq
#define CONTAINER_OF_XREQ(type,x) CONTAINER_OF(type,xreq,x)
/* req wrappers for xreq */
+extern struct afb_req afb_xreq_unstore(struct afb_stored_req *sreq);
extern void afb_xreq_addref(struct afb_xreq *xreq);
extern void afb_xreq_unref(struct afb_xreq *xreq);