Re: using select() with gtk_main()



On Sun, 2007-01-14 at 00:57 +1000, kimet wrote:
I want to write an gtk based app that monitors the serial port and dumps
data to a textview, while at the same time responding to gui callbacks
(classic gtk functionality). So do I need to:

(1) somehow set up a gtk signal handler for the serial port event
(2) use threads and monitor the serial port in a thread that
communicates to main()
(3) use a separate daemon and get the gui to communicate with the daemon

I lean towards option (1) but do not know how to do it at this stage.

It's fairly simple but not particularly obvious.

1. Make the serial port fd nonblocking with fcntl
2. Create a GIOChannel from the fd with g_io_channel_unix_new ()
3. Add the GIOChannel into the event loop with g_io_add_watch (); the
conditions you want for reading a fd are G_IO_IN | G_IO_PRI | G_IO_HUP.
4. In the condition callback, if the condition has G_IO_HUP set, it's
been closed; update the GUI and return FALSE to remove the event source.
Otherwise read from the GIOChannel with the g_io_channel_read_*
functions.

Hth,

Ed





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]