Re: Question on g_io_add_watch



David Helder <dhelder@umich.edu> writes: 
> g_source_remove removes the watch.  The naming convention here is weird
> (why g_io_add_watch instead of g_io_channel_add_watch?) 

The function adds a source that monitors IO, it only happens to do
that via GIOChannel. It operates on the main loop, it is not an
IOChannel method.

For example, in C++ you would not expect IOChannel to have anything to
do with the main loop, or to have an add_watch() method. You would
expect the main loop to have the add_watch() method that took the
IOChannel argument. At least, that is what I would expect (since
there's no main loop information contained in the IOChannel object,
and a good rule of thumb is that object methods aren't supposed to
have weird side effects unrelated to the object).

> and I'm suprised
> there isn't a g_io_channel_remove_watch too.
> 

g_source_remove() just removes all event sources, there's no need for
a specific one.

GDK/GTK has wrappers like gdk_input_add()/gdk_input_remove(), but look
at the implementation:
 void
 gdk_input_remove (gint tag)
 {
   g_source_remove (tag);
 }

this is just a leftover from when the main loop was not in glib.

Havoc



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