2009-09-16 06:38:59 +00:00
|
|
|
// Gst.GLib.MainContext.cs - mainContext class implementation
|
2009-07-31 08:16:55 +00:00
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
|
|
|
|
2009-08-05 14:48:13 +00:00
|
|
|
namespace Gst.GLib {
|
2009-07-31 08:16:55 +00:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Runtime.InteropServices;
|
|
|
|
|
|
|
|
public class MainContext {
|
2009-09-03 09:07:43 +00:00
|
|
|
IntPtr handle;
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +00:00
|
|
|
static extern IntPtr g_main_context_new ();
|
|
|
|
|
|
|
|
public MainContext ()
|
|
|
|
{
|
|
|
|
handle = g_main_context_new ();
|
|
|
|
}
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +00:00
|
|
|
static extern void g_main_context_ref (IntPtr raw);
|
|
|
|
|
|
|
|
internal MainContext (IntPtr raw)
|
|
|
|
{
|
|
|
|
handle = raw;
|
|
|
|
g_main_context_ref (handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
internal IntPtr Handle {
|
|
|
|
get {
|
|
|
|
return handle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +00:00
|
|
|
static extern void g_main_context_unref (IntPtr raw);
|
|
|
|
|
|
|
|
~MainContext ()
|
|
|
|
{
|
|
|
|
g_main_context_unref (handle);
|
|
|
|
handle = IntPtr.Zero;
|
|
|
|
}
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +00:00
|
|
|
static extern IntPtr g_main_context_default ();
|
|
|
|
|
|
|
|
public static MainContext Default {
|
|
|
|
get {
|
|
|
|
return new MainContext (g_main_context_default ());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +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-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +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-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +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-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +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-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +00:00
|
|
|
static extern bool g_main_context_pending (IntPtr raw);
|
|
|
|
|
|
|
|
public bool HasPendingEvents
|
|
|
|
{
|
|
|
|
get {
|
|
|
|
return g_main_context_pending (handle);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-09-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-09-03 09:07:43 +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-11 06:37:33 +00:00
|
|
|
[DllImport ("libglib-2.0-0.dll", CallingConvention = CallingConvention.Cdecl)]
|
2009-07-31 08:16:55 +00:00
|
|
|
static extern int g_main_depth ();
|
|
|
|
public static int Depth {
|
|
|
|
get { return g_main_depth (); }
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static bool Iteration ()
|
|
|
|
{
|
2009-09-03 09:07:43 +00:00
|
|
|
return Iteration (false);
|
2009-07-31 08:16:55 +00:00
|
|
|
}
|
|
|
|
|
2009-09-03 09:07:43 +00:00
|
|
|
public static bool Iteration (bool may_block)
|
2009-07-31 08:16:55 +00:00
|
|
|
{
|
2009-09-03 09:07:43 +00:00
|
|
|
return Default.RunIteration (may_block);
|
2009-07-31 08:16:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public static bool Pending ()
|
|
|
|
{
|
2009-09-03 09:07:43 +00:00
|
|
|
return Default.HasPendingEvents;
|
2009-07-31 08:16:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|