1 /* SPDX-License-Identifier: MIT-0 */
5 #include <systemd/sd-event.h>
7 typedef struct SDEventSource
{
13 static gboolean
event_prepare(GSource
*source
, gint
*timeout_
) {
14 return sd_event_prepare(((SDEventSource
*)source
)->event
) > 0;
17 static gboolean
event_check(GSource
*source
) {
18 return sd_event_wait(((SDEventSource
*)source
)->event
, 0) > 0;
21 static gboolean
event_dispatch(GSource
*source
, GSourceFunc callback
, gpointer user_data
) {
22 return sd_event_dispatch(((SDEventSource
*)source
)->event
) > 0;
25 static void event_finalize(GSource
*source
) {
26 sd_event_unref(((SDEventSource
*)source
)->event
);
29 static GSourceFuncs event_funcs
= {
30 .prepare
= event_prepare
,
32 .dispatch
= event_dispatch
,
33 .finalize
= event_finalize
,
36 GSource
*g_sd_event_create_source(sd_event
*event
) {
37 SDEventSource
*source
;
39 source
= (SDEventSource
*)g_source_new(&event_funcs
, sizeof(SDEventSource
));
41 source
->event
= sd_event_ref(event
);
42 source
->pollfd
.fd
= sd_event_get_fd(event
);
43 source
->pollfd
.events
= G_IO_IN
| G_IO_HUP
| G_IO_ERR
;
45 g_source_add_poll((GSource
*)source
, &source
->pollfd
);
47 return (GSource
*)source
;