프로젝트

일반

사용자정보

통계
| 개정판:

t1 / TFDContents / Assets / Standard Assets / Windows / Kinect / InfraredFrameReader.cs @ 9

이력 | 보기 | 이력해설 | 다운로드 (15.2 KB)

1
#if !(UNITY_WSA_10_0 && NETFX_CORE)
2
using RootSystem = System;
3
using System.Linq;
4
using System.Collections.Generic;
5
namespace Windows.Kinect
6
{
7
    //
8
    // Windows.Kinect.InfraredFrameReader
9
    //
10
    public sealed partial class InfraredFrameReader : RootSystem.IDisposable, Helper.INativeWrapper
11

    
12
    {
13
        internal RootSystem.IntPtr _pNative;
14
        RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
15

    
16
        // Constructors and Finalizers
17
        internal InfraredFrameReader(RootSystem.IntPtr pNative)
18
        {
19
            _pNative = pNative;
20
            Windows_Kinect_InfraredFrameReader_AddRefObject(ref _pNative);
21
        }
22

    
23
        ~InfraredFrameReader()
24
        {
25
            Dispose(false);
26
        }
27

    
28
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
29
        private static extern void Windows_Kinect_InfraredFrameReader_ReleaseObject(ref RootSystem.IntPtr pNative);
30
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
31
        private static extern void Windows_Kinect_InfraredFrameReader_AddRefObject(ref RootSystem.IntPtr pNative);
32
        private void Dispose(bool disposing)
33
        {
34
            if (_pNative == RootSystem.IntPtr.Zero)
35
            {
36
                return;
37
            }
38

    
39
            __EventCleanup();
40

    
41
            Helper.NativeObjectCache.RemoveObject<InfraredFrameReader>(_pNative);
42

    
43
            if (disposing)
44
            {
45
                Windows_Kinect_InfraredFrameReader_Dispose(_pNative);
46
            }
47
                Windows_Kinect_InfraredFrameReader_ReleaseObject(ref _pNative);
48

    
49
            _pNative = RootSystem.IntPtr.Zero;
50
        }
51

    
52

    
53
        // Public Properties
54
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
55
        private static extern RootSystem.IntPtr Windows_Kinect_InfraredFrameReader_get_InfraredFrameSource(RootSystem.IntPtr pNative);
56
        public  Windows.Kinect.InfraredFrameSource InfraredFrameSource
57
        {
58
            get
59
            {
60
                if (_pNative == RootSystem.IntPtr.Zero)
61
                {
62
                    throw new RootSystem.ObjectDisposedException("InfraredFrameReader");
63
                }
64

    
65
                RootSystem.IntPtr objectPointer = Windows_Kinect_InfraredFrameReader_get_InfraredFrameSource(_pNative);
66
                Helper.ExceptionHelper.CheckLastError();
67
                if (objectPointer == RootSystem.IntPtr.Zero)
68
                {
69
                    return null;
70
                }
71

    
72
                return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.InfraredFrameSource>(objectPointer, n => new Windows.Kinect.InfraredFrameSource(n));
73
            }
74
        }
75

    
76
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
77
        private static extern bool Windows_Kinect_InfraredFrameReader_get_IsPaused(RootSystem.IntPtr pNative);
78
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
79
        private static extern void Windows_Kinect_InfraredFrameReader_put_IsPaused(RootSystem.IntPtr pNative, bool isPaused);
80
        public  bool IsPaused
81
        {
82
            get
83
            {
84
                if (_pNative == RootSystem.IntPtr.Zero)
85
                {
86
                    throw new RootSystem.ObjectDisposedException("InfraredFrameReader");
87
                }
88

    
89
                return Windows_Kinect_InfraredFrameReader_get_IsPaused(_pNative);
90
            }
91
            set
92
            {
93
                if (_pNative == RootSystem.IntPtr.Zero)
94
                {
95
                    throw new RootSystem.ObjectDisposedException("InfraredFrameReader");
96
                }
97

    
98
                Windows_Kinect_InfraredFrameReader_put_IsPaused(_pNative, value);
99
                Helper.ExceptionHelper.CheckLastError();
100
            }
101
        }
102

    
103

    
104
        // Events
105
        private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handle;
106
        [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
107
        private delegate void _Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
108
        private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.InfraredFrameArrivedEventArgs>>> Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.InfraredFrameArrivedEventArgs>>>();
109
        [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate))]
110
        private static void Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
111
        {
112
            List<RootSystem.EventHandler<Windows.Kinect.InfraredFrameArrivedEventArgs>> callbackList = null;
113
            Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
114
            lock(callbackList)
115
            {
116
                var objThis = Helper.NativeObjectCache.GetObject<InfraredFrameReader>(pNative);
117
                var args = new Windows.Kinect.InfraredFrameArrivedEventArgs(result);
118
                foreach(var func in callbackList)
119
                {
120
                    Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
121
                }
122
            }
123
        }
124
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
125
        private static extern void Windows_Kinect_InfraredFrameReader_add_FrameArrived(RootSystem.IntPtr pNative, _Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate eventCallback, bool unsubscribe);
126
        public  event RootSystem.EventHandler<Windows.Kinect.InfraredFrameArrivedEventArgs> FrameArrived
127
        {
128
            add
129
            {
130
                Helper.EventPump.EnsureInitialized();
131

    
132
                Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
133
                var callbackList = Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_callbacks[_pNative];
134
                lock (callbackList)
135
                {
136
                    callbackList.Add(value);
137
                    if(callbackList.Count == 1)
138
                    {
139
                        var del = new _Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate(Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handler);
140
                        _Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
141
                        Windows_Kinect_InfraredFrameReader_add_FrameArrived(_pNative, del, false);
142
                    }
143
                }
144
            }
145
            remove
146
            {
147
                if (_pNative == RootSystem.IntPtr.Zero)
148
                {
149
                    return;
150
                }
151

    
152
                Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
153
                var callbackList = Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_callbacks[_pNative];
154
                lock (callbackList)
155
                {
156
                    callbackList.Remove(value);
157
                    if(callbackList.Count == 0)
158
                    {
159
                        Windows_Kinect_InfraredFrameReader_add_FrameArrived(_pNative, Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handler, true);
160
                        _Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handle.Free();
161
                    }
162
                }
163
            }
164
        }
165

    
166
        private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle;
167
        [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
168
        private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
169
        private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>> Windows_Data_PropertyChangedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>>>();
170
        [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))]
171
        private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
172
        {
173
            List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null;
174
            Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
175
            lock(callbackList)
176
            {
177
                var objThis = Helper.NativeObjectCache.GetObject<InfraredFrameReader>(pNative);
178
                var args = new Windows.Data.PropertyChangedEventArgs(result);
179
                foreach(var func in callbackList)
180
                {
181
                    Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
182
                }
183
            }
184
        }
185
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
186
        private static extern void Windows_Kinect_InfraredFrameReader_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe);
187
        public  event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged
188
        {
189
            add
190
            {
191
                Helper.EventPump.EnsureInitialized();
192

    
193
                Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
194
                var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
195
                lock (callbackList)
196
                {
197
                    callbackList.Add(value);
198
                    if(callbackList.Count == 1)
199
                    {
200
                        var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
201
                        _Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
202
                        Windows_Kinect_InfraredFrameReader_add_PropertyChanged(_pNative, del, false);
203
                    }
204
                }
205
            }
206
            remove
207
            {
208
                if (_pNative == RootSystem.IntPtr.Zero)
209
                {
210
                    return;
211
                }
212

    
213
                Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
214
                var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
215
                lock (callbackList)
216
                {
217
                    callbackList.Remove(value);
218
                    if(callbackList.Count == 0)
219
                    {
220
                        Windows_Kinect_InfraredFrameReader_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
221
                        _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
222
                    }
223
                }
224
            }
225
        }
226

    
227

    
228
        // Public Methods
229
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
230
        private static extern RootSystem.IntPtr Windows_Kinect_InfraredFrameReader_AcquireLatestFrame(RootSystem.IntPtr pNative);
231
        public Windows.Kinect.InfraredFrame AcquireLatestFrame()
232
        {
233
            if (_pNative == RootSystem.IntPtr.Zero)
234
            {
235
                throw new RootSystem.ObjectDisposedException("InfraredFrameReader");
236
            }
237

    
238
            RootSystem.IntPtr objectPointer = Windows_Kinect_InfraredFrameReader_AcquireLatestFrame(_pNative);
239
            Helper.ExceptionHelper.CheckLastError();
240
            if (objectPointer == RootSystem.IntPtr.Zero)
241
            {
242
                return null;
243
            }
244

    
245
            return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.InfraredFrame>(objectPointer, n => new Windows.Kinect.InfraredFrame(n));
246
        }
247

    
248
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
249
        private static extern void Windows_Kinect_InfraredFrameReader_Dispose(RootSystem.IntPtr pNative);
250
        public void Dispose()
251
        {
252
            if (_pNative == RootSystem.IntPtr.Zero)
253
            {
254
                return;
255
            }
256

    
257
            Dispose(true);
258
            RootSystem.GC.SuppressFinalize(this);
259
        }
260

    
261
        private void __EventCleanup()
262
        {
263
            {
264
                Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
265
                var callbackList = Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_callbacks[_pNative];
266
                lock (callbackList)
267
                {
268
                    if (callbackList.Count > 0)
269
                    {
270
                        callbackList.Clear();
271
                        if (_pNative != RootSystem.IntPtr.Zero)
272
                        {
273
                            Windows_Kinect_InfraredFrameReader_add_FrameArrived(_pNative, Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handler, true);
274
                        }
275
                        _Windows_Kinect_InfraredFrameArrivedEventArgs_Delegate_Handle.Free();
276
                    }
277
                }
278
            }
279
            {
280
                Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
281
                var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
282
                lock (callbackList)
283
                {
284
                    if (callbackList.Count > 0)
285
                    {
286
                        callbackList.Clear();
287
                        if (_pNative != RootSystem.IntPtr.Zero)
288
                        {
289
                            Windows_Kinect_InfraredFrameReader_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
290
                        }
291
                        _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
292
                    }
293
                }
294
            }
295
        }
296
    }
297

    
298
}
299
#endif