Example #1
0
        public object AddTimeout(uint timeout, TimeoutHandler handler)
        {
            IntPtr source = g_timeout_source_new(timeout);

            if(source == IntPtr.Zero)
                throw new ArgumentException("timeout");

            SourceID id_object = null;
            object[] args = new object[2];
            args[0] = handler;
            args[1] = id_object;

            IntPtr data = (IntPtr)GCHandle.Alloc(args);
            DestroyNotify notify = DestroyHelper.NotifyHandler;
            g_source_set_callback(source, TimeoutHandler, data, notify);

            uint id = g_source_attach(source, Context);
            g_source_unref(source);

            id_object = new SourceID(id);

            return (object)id_object;
        }
Example #2
0
        public virtual object AddWatch(OSHandle handle, WatchEventKind events, WatchHandler handler)
        {
            if(handle.HandleKind != HandleKind.FD)
                throw new ArgumentException(String.Format("Handle of type \"{0}\" not supported by {1}", handle.HandleKind, GetType()));

            SourceID id_object = null;
            IntPtr source = GIOChannel.CreateWatch((int)((IntPtr)handle),
                events, handler, id_object);

            uint id = g_source_attach(source, Context);
            g_source_unref(source);

            id_object = new SourceID(id);

            return (object)id_object;
        }