2003-02-08 17:33:17 +00:00
|
|
|
// GLib.MainContext.cs - mainContext class implementation
|
|
|
|
//
|
|
|
|
// Author: Radek Doulik <rodo@matfyz.cz>
|
|
|
|
//
|
2004-06-25 18:42:19 +00:00
|
|
|
// 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.
|
|
|
|
|
2003-02-08 17:33:17 +00:00
|
|
|
|
|
|
|
namespace GLib {
|
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
public class MainContext {
|
2009-08-19 16:07:44 +00:00
|
|
|
IntPtr handle;
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
static extern IntPtr g_main_context_new ();
|
|
|
|
|
|
|
|
public MainContext ()
|
|
|
|
{
|
|
|
|
handle = g_main_context_new ();
|
|
|
|
}
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
static extern void g_main_context_ref (IntPtr raw);
|
|
|
|
|
2013-10-09 17:44:50 +00:00
|
|
|
public MainContext (IntPtr raw)
|
2009-08-19 16:07:44 +00:00
|
|
|
{
|
|
|
|
handle = raw;
|
|
|
|
g_main_context_ref (handle);
|
|
|
|
}
|
|
|
|
|
2013-10-09 17:44:50 +00:00
|
|
|
public IntPtr Handle {
|
2009-08-19 16:07:44 +00:00
|
|
|
get {
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
static extern void g_main_context_unref (IntPtr raw);
|
|
|
|
|
|
|
|
~MainContext ()
|
|
|
|
{
|
|
|
|
g_main_context_unref (handle);
|
|
|
|
handle = IntPtr.Zero;
|
|
|
|
}
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
static extern IntPtr g_main_context_default ();
|
|
|
|
|
|
|
|
public static MainContext Default {
|
|
|
|
get {
|
|
|
|
return new MainContext (g_main_context_default ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
static extern void g_main_context_push_thread_default (IntPtr raw);
|
|
|
|
|
|
|
|
public void PushThreadDefault ()
|
|
|
|
{
|
|
|
|
g_main_context_push_thread_default (handle);
|
|
|
|
}
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
static extern void g_main_context_pop_thread_default (IntPtr raw);
|
|
|
|
|
|
|
|
public void PopThreadDefault ()
|
|
|
|
{
|
|
|
|
g_main_context_pop_thread_default (handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
static extern bool g_main_context_pending (IntPtr raw);
|
|
|
|
|
|
|
|
public bool HasPendingEvents
|
|
|
|
{
|
|
|
|
get {
|
|
|
|
return g_main_context_pending (handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-08-19 16:07:44 +00:00
|
|
|
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 ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-03 19:50:53 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2005-10-07 21:33:30 +00:00
|
|
|
static extern int g_main_depth ();
|
|
|
|
public static int Depth {
|
|
|
|
get { return g_main_depth (); }
|
|
|
|
}
|
|
|
|
|
2003-02-08 17:33:17 +00:00
|
|
|
|
|
|
|
public static bool Iteration ()
|
|
|
|
{
|
2009-08-19 16:07:44 +00:00
|
|
|
return Iteration (false);
|
2003-02-08 17:33:17 +00:00
|
|
|
}
|
|
|
|
|
2009-08-19 16:07:44 +00:00
|
|
|
public static bool Iteration (bool may_block)
|
2003-02-08 17:33:17 +00:00
|
|
|
{
|
2009-08-19 16:07:44 +00:00
|
|
|
return Default.RunIteration (may_block);
|
2003-02-08 17:33:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool Pending ()
|
|
|
|
{
|
2009-08-19 16:07:44 +00:00
|
|
|
return Default.HasPendingEvents;
|
2003-02-08 17:33:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|