#include <json-c/json.h>
#include <systemd/sd-event.h>
-#include <afb/afb-event-itf.h>
+#include <afb/afb-event.h>
#include "afb-common.h"
struct client_event
{
struct client_event *next;
- struct afb_event event;
- int eventid;
+ struct afb_eventid *eventid;
+ int id;
int refcount;
};
ERROR("error while sending subcall");
}
-static int server_req_subscribe_cb(struct afb_xreq *xreq, struct afb_event event)
+static int server_req_subscribe_cb(struct afb_xreq *xreq, struct afb_eventid *event)
{
int rc;
struct server_req *wreq = CONTAINER_OF_XREQ(struct server_req, xreq);
rc = afb_evt_add_watch(wreq->stubws->listener, event);
if (rc >= 0)
- rc = afb_proto_ws_call_subscribe(wreq->call, afb_evt_event_name(event), afb_evt_event_id(event));
+ rc = afb_proto_ws_call_subscribe(wreq->call, afb_evt_event_fullname(event), afb_evt_event_id(event));
if (rc < 0)
ERROR("error while subscribing event");
return rc;
}
-static int server_req_unsubscribe_cb(struct afb_xreq *xreq, struct afb_event event)
+static int server_req_unsubscribe_cb(struct afb_xreq *xreq, struct afb_eventid *event)
{
int rc, rc2;
struct server_req *wreq = CONTAINER_OF_XREQ(struct server_req, xreq);
- rc = afb_proto_ws_call_unsubscribe(wreq->call, afb_evt_event_name(event), afb_evt_event_id(event));
+ rc = afb_proto_ws_call_unsubscribe(wreq->call, afb_evt_event_fullname(event), afb_evt_event_id(event));
rc2 = afb_evt_remove_watch(wreq->stubws->listener, event);
if (rc >= 0 && rc2 < 0)
rc = rc2;
struct client_event *ev;
ev = stubws->events;
- while (ev != NULL && (ev->eventid != eventid || 0 != strcmp(afb_evt_event_name(ev->event), name)))
+ while (ev != NULL && (ev->id != eventid || 0 != strcmp(afb_evt_event_fullname(ev->eventid), name)))
ev = ev->next;
return ev;
/* no conflict, try to add it */
ev = malloc(sizeof *ev);
if (ev != NULL) {
- ev->event = afb_evt_create_event(event_name);
- if (ev->event.closure != NULL) {
+ ev->eventid = afb_evt_create_event(event_name);
+ if (ev->eventid != NULL) {
ev->refcount = 1;
- ev->eventid = event_id;
+ ev->id = event_id;
ev->next = stubws->events;
stubws->events = ev;
return;
*prv = ev->next;
/* destroys the event */
- afb_event_drop(ev->event);
+ afb_evt_event_unref(ev->eventid);
free(ev);
}
if (ev == NULL)
return;
- if (afb_xreq_subscribe(xreq, ev->event) < 0)
+ if (afb_xreq_subscribe(xreq, ev->eventid) < 0)
ERROR("can't subscribe: %m");
}
if (ev == NULL)
return;
- if (afb_xreq_unsubscribe(xreq, ev->event) < 0)
+ if (afb_xreq_unsubscribe(xreq, ev->eventid) < 0)
ERROR("can't unsubscribe: %m");
}
/* check conflicts */
ev = client_event_search(stubws, event_id, event_name);
if (ev)
- afb_event_push(ev->event, data);
+ afb_evt_push(ev->eventid, data);
else
ERROR("unreadable push event");
}
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);
while (ev) {
nxt = ev->next;
- afb_event_drop(ev->event);
+ afb_evt_event_unref(ev->eventid);
free(ev);
ev = nxt;
}