#include <json-c/json.h>
+#include <afb/afb-req-itf.h>
+
#include "afb-wsj1.h"
#include "afb-ws-json1.h"
#include "afb-msg-json.h"
#include "session.h"
-#include <afb/afb-req-itf.h>
#include "afb-apis.h"
#include "afb-context.h"
#include "afb-evt.h"
+#include "afb-subcall.h"
#include "verbose.h"
static void aws_on_hangup(struct afb_ws_json1 *ws, struct afb_wsj1 *wsj1);
static void wsreq_send(struct afb_wsreq *wsreq, const char *buffer, size_t size);
static int wsreq_subscribe(struct afb_wsreq *wsreq, struct afb_event event);
static int wsreq_unsubscribe(struct afb_wsreq *wsreq, struct afb_event event);
+static void wsreq_subcall(struct afb_wsreq *wsreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure);
const struct afb_req_itf afb_ws_json1_req_itf = {
.json = (void*)wsreq_json,
.session_close = (void*)afb_context_close,
.session_set_LOA = (void*)afb_context_change_loa,
.subscribe = (void*)wsreq_subscribe,
- .unsubscribe = (void*)wsreq_unsubscribe
+ .unsubscribe = (void*)wsreq_unsubscribe,
+ .subcall = (void*)wsreq_subcall
};
static void aws_on_call(struct afb_ws_json1 *ws, const char *api, const char *verb, struct afb_wsj1_msg *msg)
static struct afb_arg wsreq_get(struct afb_wsreq *wsreq, const char *name)
{
- struct afb_arg arg;
- struct json_object *value, *root;
-
- root = wsreq_json(wsreq);
- if (json_object_object_get_ex(root, name, &value)) {
- arg.name = name;
- arg.value = json_object_get_string(value);
- } else {
- arg.name = NULL;
- arg.value = NULL;
- }
- arg.path = NULL;
- return arg;
+ return afb_msg_json_get_arg(wsreq_json(wsreq), name);
}
static void wsreq_fail(struct afb_wsreq *wsreq, const char *status, const char *info)
return afb_evt_remove_watch(wsreq->aws->listener, event);
}
+static void wsreq_subcall(struct afb_wsreq *wsreq, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *closure)
+{
+ afb_subcall(&wsreq->context, api, verb, args, callback, closure, (struct afb_req){ .itf = &afb_ws_json1_req_itf, .closure = wsreq });
+}
+