Back to development
[platform/upstream/gstreamer.git] / subprojects / gstreamer-sharp / sources / generated / Gst / GstSharp.TaskFunctionNative.cs
1 // This file was generated by the Gtk# code generator.
2 // Any changes made will be lost if regenerated.
3
4 namespace GstSharp {
5
6         using System;
7         using System.Runtime.InteropServices;
8
9 #region Autogenerated code
10         [UnmanagedFunctionPointer (CallingConvention.Cdecl)]
11         internal delegate void TaskFunctionNative(IntPtr user_data);
12
13         internal class TaskFunctionInvoker {
14
15                 TaskFunctionNative native_cb;
16                 IntPtr __data;
17                 GLib.DestroyNotify __notify;
18
19                 ~TaskFunctionInvoker ()
20                 {
21                         if (__notify == null)
22                                 return;
23                         __notify (__data);
24                 }
25
26                 internal TaskFunctionInvoker (TaskFunctionNative native_cb) : this (native_cb, IntPtr.Zero, null) {}
27
28                 internal TaskFunctionInvoker (TaskFunctionNative native_cb, IntPtr data) : this (native_cb, data, null) {}
29
30                 internal TaskFunctionInvoker (TaskFunctionNative native_cb, IntPtr data, GLib.DestroyNotify notify)
31                 {
32                         this.native_cb = native_cb;
33                         __data = data;
34                         __notify = notify;
35                 }
36
37                 internal Gst.TaskFunction Handler {
38                         get {
39                                 return new Gst.TaskFunction(InvokeNative);
40                         }
41                 }
42
43                 void InvokeNative ()
44                 {
45                         native_cb (__data);
46                 }
47         }
48
49         internal class TaskFunctionWrapper {
50
51                 public void NativeCallback (IntPtr user_data)
52                 {
53                         try {
54                                 managed ();
55                                 if (release_on_call)
56                                         gch.Free ();
57                         } catch (Exception e) {
58                                 GLib.ExceptionManager.RaiseUnhandledException (e, false);
59                         }
60                 }
61
62                 bool release_on_call = false;
63                 GCHandle gch;
64
65                 public void PersistUntilCalled ()
66                 {
67                         release_on_call = true;
68                         gch = GCHandle.Alloc (this);
69                 }
70
71                 internal TaskFunctionNative NativeDelegate;
72                 Gst.TaskFunction managed;
73
74                 public TaskFunctionWrapper (Gst.TaskFunction managed)
75                 {
76                         this.managed = managed;
77                         if (managed != null)
78                                 NativeDelegate = new TaskFunctionNative (NativeCallback);
79                 }
80
81                 public static Gst.TaskFunction GetManagedDelegate (TaskFunctionNative native)
82                 {
83                         if (native == null)
84                                 return null;
85                         TaskFunctionWrapper wrapper = (TaskFunctionWrapper) native.Target;
86                         if (wrapper == null)
87                                 return null;
88                         return wrapper.managed;
89                 }
90         }
91 #endregion
92 }