]>
git.ipfire.org Git - thirdparty/systemd.git/blob - man/glib-event-glue.c
1 /* SPDX-License-Identifier: MIT */
2 /* Copyright 2014 Tom Gundersen */
6 #include <systemd/sd-event.h>
8 typedef struct SDEventSource
{
14 static gboolean
event_prepare(GSource
*source
, gint
*timeout_
) {
15 return sd_event_prepare(((SDEventSource
*)source
)->event
) > 0;
18 static gboolean
event_check(GSource
*source
) {
19 return sd_event_wait(((SDEventSource
*)source
)->event
, 0) > 0;
22 static gboolean
event_dispatch(GSource
*source
, GSourceFunc callback
, gpointer user_data
) {
23 return sd_event_dispatch(((SDEventSource
*)source
)->event
) > 0;
26 static void event_finalize(GSource
*source
) {
27 sd_event_unref(((SDEventSource
*)source
)->event
);
30 static GSourceFuncs event_funcs
= {
31 .prepare
= event_prepare
,
33 .dispatch
= event_dispatch
,
34 .finalize
= event_finalize
,
37 GSource
*g_sd_event_create_source(sd_event
*event
) {
38 SDEventSource
*source
;
40 source
= (SDEventSource
*)g_source_new(&event_funcs
, sizeof(SDEventSource
));
42 source
->event
= sd_event_ref(event
);
43 source
->pollfd
.fd
= sd_event_get_fd(event
);
44 source
->pollfd
.events
= G_IO_IN
| G_IO_HUP
| G_IO_ERR
;
46 g_source_add_poll((GSource
*)source
, &source
->pollfd
);
48 return (GSource
*)source
;