Re: [Vala] Adding a GIOChannel to GMainLoop



On Wed, 2007-10-24 at 16:11 +0200, Jürg Billeter wrote:
On Wed, 2007-10-24 at 15:44 +0200, Xavier Bestel wrote:
Hi,

I have a GMainLoop (= new MainLoop(null, false)) and I wanted to add a
GIOChannel to that loop. In C I'd have written g_io_add_watch(), but I
can't find the equivalent in Vala. Could someone help me please ?

That's also still missing in the bindings.

This should work when added to the IOChannel class in glib-2.0.vapi:

[CCode (cname = "g_io_add_watch")]
public uint add_watch (IOCondition condition, IOFunc func, pointer
user_data);

Also add the following line after the IOChannel class:

public static delegate bool IOFunc (IOChannel source, IOCondition
condition, pointer data);

OK, just in case somebody wants to patch it in:

--- /usr/share/vala/vapi/glib-2.0.vapi.orig     2007-10-24 16:21:38.000000000 +0200
+++ /usr/share/vala/vapi/glib-2.0.vapi  2007-10-24 17:45:45.000000000 +0200
@@ -1216,6 +1216,10 @@
                [CCode (cname = "g_io_channel_unix_new")]
                public IOChannel.unix_new (int fd);
                public int unix_get_fd ();
+               [CCode (cname = "g_io_add_watch")]
+               public uint add_watch (IOCondition condition, IOFunc func, pointer user_data);
+               [CCode (cname = "g_io_add_watch_full")]
+               public uint add_watch_full (int priority, IOCondition condition, IOFunc func, pointer 
user_data, DestroyNotify notify);
                public IOStatus read_chars (string! buf, ulong count, out ulong bytes_read) throws 
ConvertError, IOChannelError;
                public IOStatus read_unichar (out unichar thechar) throws ConvertError, IOChannelError;
                public IOStatus read_line (out string str_return, out ulong length, out ulong terminator_pos) 
throws ConvertError, IOChannelError;
@@ -1228,6 +1232,8 @@
                public IOStatus shutdown (bool flush) throws IOChannelError;
        }
 
+       public static delegate bool IOFunc (IOChannel source, IOCondition condition, pointer data);
+
        [CCode (cprefix = "G_IO_", type_id = "G_TYPE_IO_CONDITION")]
        public enum IOCondition {
                IN,







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