summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-09-22 14:42:14 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-10-09 14:08:33 +0200
commit325e6a7f034c80562096d60ab01f2e4532eea98c (patch)
treef1794f3e9fc8610132a34f3c0e2ba91bfbdb9513
parent1874271ce06622664e3513e5335b29de2c55ace6 (diff)
Make single afb_request_subcall
Change-Id: I8cc96ef9c05781069f07b807bc6632d13668ac69 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--include/afb/afb-request-itf.h9
-rw-r--r--include/afb/afb-request.h4
-rw-r--r--src/afb-stub-ws.c2
-rw-r--r--src/afb-xreq.c73
-rw-r--r--src/afb-xreq.h4
5 files changed, 80 insertions, 12 deletions
diff --git a/include/afb/afb-request-itf.h b/include/afb/afb-request-itf.h
index a5c3f82a..9e55a361 100644
--- a/include/afb/afb-request-itf.h
+++ b/include/afb/afb-request-itf.h
@@ -171,5 +171,14 @@ struct afb_request_itf
int (*unsubscribe_eventid)(
struct afb_request *request,
struct afb_eventid *eventid);
+
+ void (*subcall_request)(
+ struct afb_request *request,
+ const char *api,
+ const char *verb,
+ struct json_object *args,
+ void (*callback)(void*, int, struct json_object*, struct afb_request *request),
+ void *cb_closure);
+
};
diff --git a/include/afb/afb-request.h b/include/afb/afb-request.h
index acfb7ea1..26b2ef11 100644
--- a/include/afb/afb-request.h
+++ b/include/afb/afb-request.h
@@ -274,9 +274,9 @@ static inline int afb_request_unsubscribe(struct afb_request *request, struct af
* - 'afb_request_subcall_req' that is convenient to keep request alive automatically.
* - 'afb_request_subcall_sync' the synchronous version
*/
-static inline void afb_request_subcall(struct afb_request *request, const char *api, const char *verb, struct json_object *args, void (*callback)(void *closure, int iserror, struct json_object *result), void *closure)
+static inline void afb_request_subcall(struct afb_request *request, const char *api, const char *verb, struct json_object *args, void (*callback)(void *closure, int iserror, struct json_object *result, struct afb_request *request), void *closure)
{
- request->itf->subcall(request, api, verb, args, callback, closure);
+ request->itf->subcall_request(request, api, verb, args, callback, closure);
}
/*
diff --git a/src/afb-stub-ws.c b/src/afb-stub-ws.c
index 625cea38..44247dd3 100644
--- a/src/afb-stub-ws.c
+++ b/src/afb-stub-ws.c
@@ -446,7 +446,7 @@ static void on_event_broadcast(void *closure, const char *event_name, struct jso
afb_evt_broadcast(event_name, data);
}
-static void client_subcall_reply_cb(void *closure, int status, json_object *object)
+static void client_subcall_reply_cb(void *closure, int status, json_object *object, struct afb_request *request)
{
struct afb_proto_ws_subcall *subcall = closure;
afb_proto_ws_subcall_reply(subcall, status, object);
diff --git a/src/afb-xreq.c b/src/afb-xreq.c
index f9f2324a..8bfb3639 100644
--- a/src/afb-xreq.c
+++ b/src/afb-xreq.c
@@ -97,7 +97,8 @@ struct subcall
struct {
union {
void (*callback)(void*, int, struct json_object*);
- void (*callback2)(void*, int, struct json_object*, struct afb_req);
+ void (*callback_req)(void*, int, struct json_object*, struct afb_req);
+ void (*callback_request)(void*, int, struct json_object*, struct afb_request*);
};
void *closure;
};
@@ -187,7 +188,12 @@ static void subcall_on_reply(struct subcall *subcall, int status, struct json_ob
static void subcall_req_on_reply(struct subcall *subcall, int status, struct json_object *result)
{
- subcall->callback2(subcall->closure, status, result, to_req(subcall->xreq.caller));
+ subcall->callback_req(subcall->closure, status, result, to_req(subcall->xreq.caller));
+}
+
+static void subcall_request_on_reply(struct subcall *subcall, int status, struct json_object *result)
+{
+ subcall->callback_request(subcall->closure, status, result, to_request(subcall->xreq.caller));
}
static void subcall_hooked_on_reply(struct subcall *subcall, int status, struct json_object *result)
@@ -202,6 +208,12 @@ static void subcall_req_hooked_on_reply(struct subcall *subcall, int status, str
subcall_req_on_reply(subcall, status, result);
}
+static void subcall_request_hooked_on_reply(struct subcall *subcall, int status, struct json_object *result)
+{
+ afb_hook_xreq_subcall_result(subcall->xreq.caller, status, result);
+ subcall_request_on_reply(subcall, status, result);
+}
+
static void subcall_reply_direct_cb(void *closure, int status, struct json_object *result)
{
struct afb_xreq *xreq = closure;
@@ -237,11 +249,18 @@ static void subcall(struct subcall *subcall, void (*callback)(void*, int, struct
static void subcall_req(struct subcall *subcall, void (*callback)(void*, int, struct json_object*, struct afb_req), void *cb_closure)
{
- subcall->callback2 = callback;
+ subcall->callback_req = callback;
subcall->closure = cb_closure;
subcall_process(subcall, subcall_req_on_reply);
}
+static void subcall_request(struct subcall *subcall, void (*callback)(void*, int, struct json_object*, struct afb_request*), void *cb_closure)
+{
+ subcall->callback_request = callback;
+ subcall->closure = cb_closure;
+ subcall_process(subcall, subcall_request_on_reply);
+}
+
static void subcall_hooked(struct subcall *subcall, void (*callback)(void*, int, struct json_object*), void *cb_closure)
{
subcall->callback = callback;
@@ -251,11 +270,18 @@ static void subcall_hooked(struct subcall *subcall, void (*callback)(void*, int,
static void subcall_req_hooked(struct subcall *subcall, void (*callback)(void*, int, struct json_object*, struct afb_req), void *cb_closure)
{
- subcall->callback2 = callback;
+ subcall->callback_req = callback;
subcall->closure = cb_closure;
subcall_process(subcall, subcall_req_hooked_on_reply);
}
+static void subcall_request_hooked(struct subcall *subcall, void (*callback)(void*, int, struct json_object*, struct afb_request*), void *cb_closure)
+{
+ subcall->callback_request = callback;
+ subcall->closure = cb_closure;
+ subcall_process(subcall, subcall_request_hooked_on_reply);
+}
+
static void subcall_sync_leave(struct subcall *subcall)
{
struct jobloop *jobloop = __atomic_exchange_n(&subcall->jobloop, NULL, __ATOMIC_RELAXED);
@@ -497,6 +523,21 @@ static void xreq_subcall_req_cb(struct afb_request *closure, const char *api, co
}
}
+static void xreq_subcall_request_cb(struct afb_request *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*, struct afb_request*), void *cb_closure)
+{
+ struct afb_xreq *xreq = from_request(closure);
+ struct subcall *sc;
+
+ sc = subcall_alloc(xreq, api, verb, args);
+ if (sc == NULL) {
+ if (callback)
+ callback(cb_closure, 1, afb_msg_json_internal_error(), to_request(xreq));
+ json_object_put(args);
+ } else {
+ subcall_request(sc, callback, cb_closure);
+ }
+}
+
static int xreq_subcallsync_cb(struct afb_request *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result)
{
@@ -697,6 +738,22 @@ static void xreq_hooked_subcall_req_cb(struct afb_request *closure, const char *
}
}
+static void xreq_hooked_subcall_request_cb(struct afb_request *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*, struct afb_request *), void *cb_closure)
+{
+ struct afb_xreq *xreq = from_request(closure);
+ struct subcall *sc;
+
+ afb_hook_xreq_subcall(xreq, api, verb, args);
+ sc = subcall_alloc(xreq, api, verb, args);
+ if (sc == NULL) {
+ if (callback)
+ callback(cb_closure, 1, afb_msg_json_internal_error(), to_request(xreq));
+ json_object_put(args);
+ } else {
+ subcall_request_hooked(sc, callback, cb_closure);
+ }
+}
+
static int xreq_hooked_subcallsync_cb(struct afb_request *closure, const char *api, const char *verb, struct json_object *args, struct json_object **result)
{
int r;
@@ -772,6 +829,7 @@ const struct afb_request_itf xreq_itf = {
.context_make = xreq_context_make_cb,
.subscribe_eventid = xreq_subscribe_eventid_cb,
.unsubscribe_eventid = xreq_unsubscribe_eventid_cb,
+ .subcall_request = xreq_subcall_request_cb,
};
const struct afb_request_itf xreq_hooked_itf = {
@@ -799,6 +857,7 @@ const struct afb_request_itf xreq_hooked_itf = {
.context_make = xreq_hooked_context_make_cb,
.subscribe_eventid = xreq_hooked_subscribe_eventid_cb,
.unsubscribe_eventid = xreq_hooked_unsubscribe_eventid_cb,
+ .subcall_request = xreq_hooked_subcall_request_cb,
};
/******************************************************************************/
@@ -864,12 +923,12 @@ void afb_xreq_unref(struct afb_xreq *xreq)
afb_request_unref(to_request(xreq));
}
-void afb_xreq_unhooked_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure)
+void afb_xreq_unhooked_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*, struct afb_request *), void *cb_closure)
{
- xreq_subcall_cb(to_request(xreq), api, verb, args, callback, cb_closure);
+ xreq_subcall_request_cb(to_request(xreq), api, verb, args, callback, cb_closure);
}
-void afb_xreq_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cb_closure)
+void afb_xreq_subcall(struct afb_xreq *xreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*, struct afb_request *), void *cb_closure)
{
afb_request_subcall(to_request(xreq), api, verb, args, callback, cb_closure);
}
diff --git a/src/afb-xreq.h b/src/afb-xreq.h
index 497b1635..d899a3d3 100644
--- a/src/afb-xreq.h
+++ b/src/afb-xreq.h
@@ -118,14 +118,14 @@ extern void afb_xreq_subcall(
const char *api,
const char *verb,
struct json_object *args,
- void (*callback)(void*, int, struct json_object*),
+ void (*callback)(void*, int, struct json_object*, struct afb_request *),
void *cb_closure);
extern void afb_xreq_unhooked_subcall(
struct afb_xreq *xreq,
const char *api,
const char *verb,
struct json_object *args,
- void (*callback)(void*, int, struct json_object*),
+ void (*callback)(void*, int, struct json_object*, struct afb_request *),
void *cb_closure);
extern int afb_xreq_unhooked_subcall_sync(