Is it possible to integrate GLib mainloop into another?

39 Views Asked by At

I have a 3rd party library with mainloop. I want to use GLib/Gtk with the app I'm developing. Is it possible to integrate GLib mainloop into another host?

The host loop allows to register an fd and execute nonblocking callback. Does GLib mainloop expose an fd to poll on and a function to process single event?

2

There are 2 best solutions below

0
pan-mroku On

In general when joining two frameworks that both have main loops, you have to decide on one to be the "main one" and from inside its callbacks call the contents of the main loop of the other one.

But since your question seems to be "register an fd and execute nonblocking callback", maybe this could be your solution?

0
thaller On

For example, NetworkManaget integrates a GMainContex in another GMainContext. It also integrates a systemd event loop in a GMainContext.

It should also be possible, to integrate a GMainContext in another mainloop.

I'd look at the NetworkManager sources here.