porting sd-bus event to libev

239 Views Asked by At

The sd-event is a event loop framework similar to libev, libuv, libevent, etc, I need to implement libev event loop for monitoring services. All the man pages I can find talk about the use of sd_bus_get_fd(), sd_bus_get_events() and sd_bus_get_timeout(), for example, on this page. Does anyone have a project example for using those three functions?

1

There are 1 best solutions below

0
SAS On

Don't have anything for libev but for libevent + sdbus , it goes something like this

        //Global
        static sd_bus *bus = NULL;
        static struct event_base *base = NULL;

        void bus_process(evutil_socket_t fd, short what, void *arg) {
            sd_bus_process(bus, NULL);
        }
        
        void main() {
        sd_bus_default_system(&bus);
        sd_bus_request_name(bus, BUS_NAME, 0);

        int fd = 0;
        int events = 0;
        uint64_t usec;
        struct event *ev_read;

        base = event_base_new()

        fd = sd_bus_get_fd(bus);
        events = sd_bus_get_events(bus);
        sd_bus_get_timeout(bus, &usec);

        evutil_make_socket_nonblocking(fd);
        ev_read = event_new(base, fd, EV_READ|EV_PERSIST, bus_process, NULL);
        event_add(ev_read, NULL);
        event_base_dispatch(base);
       
        // wont get here, loop is now running and processing
        return;
        }