1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167
|
// GLib.MainContext.cs - mainContext class implementation
//
// Author: Radek Doulik <rodo@matfyz.cz>
//
// Copyright (c) 2003 Radek Doulik
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of version 2 of the Lesser GNU General
// Public License as published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the
// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
// Boston, MA 02111-1307, USA.
namespace GLib {
using System;
using System.Runtime.InteropServices;
public class MainContext {
IntPtr handle;
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_main_context_new ();
public MainContext ()
{
handle = g_main_context_new ();
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern void g_main_context_ref (IntPtr raw);
public MainContext (IntPtr raw)
{
handle = raw;
g_main_context_ref (handle);
}
public IntPtr Handle {
get {
return handle;
}
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern void g_main_context_unref (IntPtr raw);
~MainContext ()
{
g_main_context_unref (handle);
handle = IntPtr.Zero;
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_main_context_default ();
public static MainContext Default {
get {
return new MainContext (g_main_context_default ());
}
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern IntPtr g_main_context_thread_default ();
public MainContext ThreadDefault {
get {
IntPtr raw = g_main_context_thread_default ();
// NULL is returned if the thread-default main context is the default context. We'd rather not adopt this strange bahaviour.
return raw == IntPtr.Zero ? Default : new MainContext (raw);
}
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern void g_main_context_push_thread_default (IntPtr raw);
public void PushThreadDefault ()
{
g_main_context_push_thread_default (handle);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern void g_main_context_pop_thread_default (IntPtr raw);
public void PopThreadDefault ()
{
g_main_context_pop_thread_default (handle);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_main_context_iteration (IntPtr raw, bool may_block);
public bool RunIteration (bool may_block)
{
return g_main_context_iteration (handle, may_block);
}
public bool RunIteration ()
{
return RunIteration (false);
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern bool g_main_context_pending (IntPtr raw);
public bool HasPendingEvents
{
get {
return g_main_context_pending (handle);
}
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern void g_main_context_wakeup (IntPtr raw);
public void Wakeup ()
{
g_main_context_wakeup (handle);
}
public override bool Equals (object o)
{
if (!(o is MainContext))
return false;
return Handle == (o as MainContext).Handle;
}
public override int GetHashCode ()
{
return Handle.GetHashCode ();
}
[DllImport (Global.GLibNativeDll, CallingConvention = CallingConvention.Cdecl)]
static extern int g_main_depth ();
public static int Depth {
get { return g_main_depth (); }
}
public static bool Iteration ()
{
return Iteration (false);
}
public static bool Iteration (bool may_block)
{
return Default.RunIteration (may_block);
}
public static bool Pending ()
{
return Default.HasPendingEvents;
}
}
}
|