#include <pthread.h>
#include <json-c/json.h>
-#include <systemd/sd-event.h>
-
-#include "afb-common.h"
#include "afb-ws.h"
#include "afb-msg-json.h"
#include "afb-proto-ws.h"
-#include "verbose.h"
struct afb_proto_ws;
goto success;
}
}
- ERROR("error while sending success");
success:
return rc;
}
goto success;
}
}
- ERROR("error while sending fail");
success:
return rc;
}
}
}
}
- ERROR("error while sending subcall");
success:
return rc;
}
goto success;
}
}
- ERROR("error while subscribing event");
success:
return rc;
}
goto success;
}
}
- ERROR("error while subscribing event");
success:
return rc;
}
/* get event data from the message */
if (!readbuf_uint32(rb, &callid)) {
- ERROR("Invalid message");
return 0;
}
/* get the call */
*call = client_call_search(protows, callid);
if (*call == NULL) {
- ERROR("message not found");
return 0;
}
/*****************************************************/
-static struct afb_proto_ws *afb_proto_ws_create(int fd, const struct afb_proto_ws_server_itf *itfs, const struct afb_proto_ws_client_itf *itfc, void *closure, const struct afb_ws_itf *itf)
+static struct afb_proto_ws *afb_proto_ws_create(struct sd_event *eloop, int fd, const struct afb_proto_ws_server_itf *itfs, const struct afb_proto_ws_client_itf *itfc, void *closure, const struct afb_ws_itf *itf)
{
struct afb_proto_ws *protows;
else {
fcntl(fd, F_SETFD, FD_CLOEXEC);
fcntl(fd, F_SETFL, O_NONBLOCK);
- protows->ws = afb_ws_create(afb_common_get_event_loop(), fd, itf, protows);
+ protows->ws = afb_ws_create(eloop, fd, itf, protows);
if (protows->ws != NULL) {
protows->fd = fd;
protows->refcount = 1;
return NULL;
}
-struct afb_proto_ws *afb_proto_ws_create_client(int fd, const struct afb_proto_ws_client_itf *itf, void *closure)
+struct afb_proto_ws *afb_proto_ws_create_client(struct sd_event *eloop, int fd, const struct afb_proto_ws_client_itf *itf, void *closure)
{
- return afb_proto_ws_create(fd, NULL, itf, closure, &proto_ws_client_ws_itf);
+ return afb_proto_ws_create(eloop, fd, NULL, itf, closure, &proto_ws_client_ws_itf);
}
-struct afb_proto_ws *afb_proto_ws_create_server(int fd, const struct afb_proto_ws_server_itf *itf, void *closure)
+struct afb_proto_ws *afb_proto_ws_create_server(struct sd_event *eloop, int fd, const struct afb_proto_ws_server_itf *itf, void *closure)
{
- return afb_proto_ws_create(fd, itf, NULL, closure, &server_ws_itf);
+ return afb_proto_ws_create(eloop, fd, itf, NULL, closure, &server_ws_itf);
}
void afb_proto_ws_unref(struct afb_proto_ws *protows)
#pragma once
+struct sd_event;
struct afb_proto_ws;
struct afb_proto_ws_call;
struct afb_proto_ws_subcall;
struct afb_proto_ws_client_itf
{
+ /* can't be NULL */
void (*on_reply_success)(void *closure, void *request, struct json_object *result, const char *info);
void (*on_reply_fail)(void *closure, void *request, const char *status, const char *info);
+ /* can be NULL */
void (*on_event_create)(void *closure, const char *event_name, int event_id);
void (*on_event_remove)(void *closure, const char *event_name, int event_id);
void (*on_event_subscribe)(void *closure, void *request, const char *event_name, int event_id);
void (*on_describe)(void *closure, struct afb_proto_ws_describe *describe);
};
-extern struct afb_proto_ws *afb_proto_ws_create_client(int fd, const struct afb_proto_ws_client_itf *itf, void *closure);
-extern struct afb_proto_ws *afb_proto_ws_create_server(int fd, const struct afb_proto_ws_server_itf *itf, void *closure);
+extern struct afb_proto_ws *afb_proto_ws_create_client(struct sd_event *eloop, int fd, const struct afb_proto_ws_client_itf *itf, void *closure);
+extern struct afb_proto_ws *afb_proto_ws_create_server(struct sd_event *eloop, int fd, const struct afb_proto_ws_server_itf *itf, void *closure);
extern void afb_proto_ws_unref(struct afb_proto_ws *protows);
extern void afb_proto_ws_addref(struct afb_proto_ws *protows);
#include <pthread.h>
#include <json-c/json.h>
-#include <systemd/sd-event.h>
#include <afb/afb-event.h>
errno = ENOMEM;
else {
if (client)
- stubws->proto = afb_proto_ws_create_client(fd, &client_itf, stubws);
+ stubws->proto = afb_proto_ws_create_client(afb_common_get_event_loop(), fd, &client_itf, stubws);
else
- stubws->proto = afb_proto_ws_create_server(fd, &server_itf, stubws);
+ stubws->proto = afb_proto_ws_create_server(afb_common_get_event_loop(), fd, &server_itf, stubws);
if (stubws->proto != NULL) {
strcpy(stubws->apiname, apiname);
stubws->apiset = afb_apiset_addref(apiset);