-/*
+/*
* Copyright (C) 2015, 2016 "IoT.bzh"
* Author "Fulup Ar Foll"
* Author José Bollo <jose.bollo@iot.bzh>
#include <systemd/sd-event.h>
-#include "afb-common.h" /* TODO: remove dependency to afb-common.h */
#include "afb-wsj1.h"
#include "afb-ws-client.h"
/* entry function */
int main(int ac, char **av, char **env)
{
+ int rc;
+ sd_event *loop;
+
/* check the argument count */
if (ac != 2 && ac != 4 && ac != 5)
usage(1, av[0]);
if (!strcmp(av[1], "-h") || !strcmp(av[1], "--help"))
usage(0, av[0]);
+ /* get the default event loop */
+ rc = sd_event_default(&loop);
+ if (rc < 0) {
+ fprintf(stderr, "connection to default event loop failed: %s\n", strerror(-rc));
+ return 1;
+ }
+
/* connect the websocket wsj1 to the uri given by the first argument */
- wsj1 = afb_ws_client_connect_wsj1(av[1], &itf, NULL);
+ wsj1 = afb_ws_client_connect_wsj1(loop, av[1], &itf, NULL);
if (wsj1 == NULL) {
fprintf(stderr, "connection to %s failed: %m\n", av[1]);
return 1;
if (ac == 2) {
/* get requests from stdin */
fcntl(0, F_SETFL, O_NONBLOCK);
- sd_event_add_io(afb_common_get_event_loop(), &evsrc, 0, EPOLLIN, io_event_callback, NULL);
+ sd_event_add_io(loop, &evsrc, 0, EPOLLIN, io_event_callback, NULL);
} else {
/* the request is defined by the arguments */
exonrep = 1;
/* loop until end */
for(;;)
- sd_event_run(afb_common_get_event_loop(), 30000000);
+ sd_event_run(loop, 30000000);
return 0;
}