프로젝트

일반

사용자정보

통계
| 개정판:

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

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

1 3 KTH
#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.MultiSourceFrameReader
9
    //
10
    public sealed partial class MultiSourceFrameReader : 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 MultiSourceFrameReader(RootSystem.IntPtr pNative)
18
        {
19
            _pNative = pNative;
20
            Windows_Kinect_MultiSourceFrameReader_AddRefObject(ref _pNative);
21
        }
22
23
        ~MultiSourceFrameReader()
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_MultiSourceFrameReader_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_MultiSourceFrameReader_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<MultiSourceFrameReader>(_pNative);
42
43
            if (disposing)
44
            {
45
                Windows_Kinect_MultiSourceFrameReader_Dispose(_pNative);
46
            }
47
                Windows_Kinect_MultiSourceFrameReader_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 Windows.Kinect.FrameSourceTypes Windows_Kinect_MultiSourceFrameReader_get_FrameSourceTypes(RootSystem.IntPtr pNative);
56
        public  Windows.Kinect.FrameSourceTypes FrameSourceTypes
57
        {
58
            get
59
            {
60
                if (_pNative == RootSystem.IntPtr.Zero)
61
                {
62
                    throw new RootSystem.ObjectDisposedException("MultiSourceFrameReader");
63
                }
64
65
                return Windows_Kinect_MultiSourceFrameReader_get_FrameSourceTypes(_pNative);
66
            }
67
        }
68
69
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
70
        private static extern bool Windows_Kinect_MultiSourceFrameReader_get_IsPaused(RootSystem.IntPtr pNative);
71
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
72
        private static extern void Windows_Kinect_MultiSourceFrameReader_put_IsPaused(RootSystem.IntPtr pNative, bool isPaused);
73
        public  bool IsPaused
74
        {
75
            get
76
            {
77
                if (_pNative == RootSystem.IntPtr.Zero)
78
                {
79
                    throw new RootSystem.ObjectDisposedException("MultiSourceFrameReader");
80
                }
81
82
                return Windows_Kinect_MultiSourceFrameReader_get_IsPaused(_pNative);
83
            }
84
            set
85
            {
86
                if (_pNative == RootSystem.IntPtr.Zero)
87
                {
88
                    throw new RootSystem.ObjectDisposedException("MultiSourceFrameReader");
89
                }
90
91
                Windows_Kinect_MultiSourceFrameReader_put_IsPaused(_pNative, value);
92
                Helper.ExceptionHelper.CheckLastError();
93
            }
94
        }
95
96
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
97
        private static extern RootSystem.IntPtr Windows_Kinect_MultiSourceFrameReader_get_KinectSensor(RootSystem.IntPtr pNative);
98
        public  Windows.Kinect.KinectSensor KinectSensor
99
        {
100
            get
101
            {
102
                if (_pNative == RootSystem.IntPtr.Zero)
103
                {
104
                    throw new RootSystem.ObjectDisposedException("MultiSourceFrameReader");
105
                }
106
107
                RootSystem.IntPtr objectPointer = Windows_Kinect_MultiSourceFrameReader_get_KinectSensor(_pNative);
108
                Helper.ExceptionHelper.CheckLastError();
109
                if (objectPointer == RootSystem.IntPtr.Zero)
110
                {
111
                    return null;
112
                }
113
114
                return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectSensor>(objectPointer, n => new Windows.Kinect.KinectSensor(n));
115
            }
116
        }
117
118
119
        // Events
120
        private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_Handle;
121
        [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
122
        private delegate void _Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
123
        private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.MultiSourceFrameArrivedEventArgs>>> Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.MultiSourceFrameArrivedEventArgs>>>();
124
        [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate))]
125
        private static void Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
126
        {
127
            List<RootSystem.EventHandler<Windows.Kinect.MultiSourceFrameArrivedEventArgs>> callbackList = null;
128
            Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
129
            lock(callbackList)
130
            {
131
                var objThis = Helper.NativeObjectCache.GetObject<MultiSourceFrameReader>(pNative);
132
                var args = new Windows.Kinect.MultiSourceFrameArrivedEventArgs(result);
133
                foreach(var func in callbackList)
134
                {
135
                    Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
136
                }
137
            }
138
        }
139
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
140
        private static extern void Windows_Kinect_MultiSourceFrameReader_add_MultiSourceFrameArrived(RootSystem.IntPtr pNative, _Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate eventCallback, bool unsubscribe);
141
        public  event RootSystem.EventHandler<Windows.Kinect.MultiSourceFrameArrivedEventArgs> MultiSourceFrameArrived
142
        {
143
            add
144
            {
145
                Helper.EventPump.EnsureInitialized();
146
147
                Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
148
                var callbackList = Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_callbacks[_pNative];
149
                lock (callbackList)
150
                {
151
                    callbackList.Add(value);
152
                    if(callbackList.Count == 1)
153
                    {
154
                        var del = new _Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate(Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_Handler);
155
                        _Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
156
                        Windows_Kinect_MultiSourceFrameReader_add_MultiSourceFrameArrived(_pNative, del, false);
157
                    }
158
                }
159
            }
160
            remove
161
            {
162
                if (_pNative == RootSystem.IntPtr.Zero)
163
                {
164
                    return;
165
                }
166
167
                Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
168
                var callbackList = Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_callbacks[_pNative];
169
                lock (callbackList)
170
                {
171
                    callbackList.Remove(value);
172
                    if(callbackList.Count == 0)
173
                    {
174
                        Windows_Kinect_MultiSourceFrameReader_add_MultiSourceFrameArrived(_pNative, Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_Handler, true);
175
                        _Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_Handle.Free();
176
                    }
177
                }
178
            }
179
        }
180
181
        private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle;
182
        [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
183
        private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
184
        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>>>();
185
        [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))]
186
        private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
187
        {
188
            List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null;
189
            Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
190
            lock(callbackList)
191
            {
192
                var objThis = Helper.NativeObjectCache.GetObject<MultiSourceFrameReader>(pNative);
193
                var args = new Windows.Data.PropertyChangedEventArgs(result);
194
                foreach(var func in callbackList)
195
                {
196
                    Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
197
                }
198
            }
199
        }
200
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
201
        private static extern void Windows_Kinect_MultiSourceFrameReader_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe);
202
        public  event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged
203
        {
204
            add
205
            {
206
                Helper.EventPump.EnsureInitialized();
207
208
                Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
209
                var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
210
                lock (callbackList)
211
                {
212
                    callbackList.Add(value);
213
                    if(callbackList.Count == 1)
214
                    {
215
                        var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
216
                        _Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
217
                        Windows_Kinect_MultiSourceFrameReader_add_PropertyChanged(_pNative, del, false);
218
                    }
219
                }
220
            }
221
            remove
222
            {
223
                if (_pNative == RootSystem.IntPtr.Zero)
224
                {
225
                    return;
226
                }
227
228
                Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
229
                var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
230
                lock (callbackList)
231
                {
232
                    callbackList.Remove(value);
233
                    if(callbackList.Count == 0)
234
                    {
235
                        Windows_Kinect_MultiSourceFrameReader_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
236
                        _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
237
                    }
238
                }
239
            }
240
        }
241
242
243
        // Public Methods
244
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
245
        private static extern RootSystem.IntPtr Windows_Kinect_MultiSourceFrameReader_AcquireLatestFrame(RootSystem.IntPtr pNative);
246
        public Windows.Kinect.MultiSourceFrame AcquireLatestFrame()
247
        {
248
            if (_pNative == RootSystem.IntPtr.Zero)
249
            {
250
                throw new RootSystem.ObjectDisposedException("MultiSourceFrameReader");
251
            }
252
253
            RootSystem.IntPtr objectPointer = Windows_Kinect_MultiSourceFrameReader_AcquireLatestFrame(_pNative);
254
            Helper.ExceptionHelper.CheckLastError();
255
            if (objectPointer == RootSystem.IntPtr.Zero)
256
            {
257
                return null;
258
            }
259
260
            return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.MultiSourceFrame>(objectPointer, n => new Windows.Kinect.MultiSourceFrame(n));
261
        }
262
263
        [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
264
        private static extern void Windows_Kinect_MultiSourceFrameReader_Dispose(RootSystem.IntPtr pNative);
265
        public void Dispose()
266
        {
267
            if (_pNative == RootSystem.IntPtr.Zero)
268
            {
269
                return;
270
            }
271
272
            Dispose(true);
273
            RootSystem.GC.SuppressFinalize(this);
274
        }
275
276
        private void __EventCleanup()
277
        {
278
            {
279
                Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
280
                var callbackList = Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_callbacks[_pNative];
281
                lock (callbackList)
282
                {
283
                    if (callbackList.Count > 0)
284
                    {
285
                        callbackList.Clear();
286
                        if (_pNative != RootSystem.IntPtr.Zero)
287
                        {
288
                            Windows_Kinect_MultiSourceFrameReader_add_MultiSourceFrameArrived(_pNative, Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_Handler, true);
289
                        }
290
                        _Windows_Kinect_MultiSourceFrameArrivedEventArgs_Delegate_Handle.Free();
291
                    }
292
                }
293
            }
294
            {
295
                Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
296
                var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
297
                lock (callbackList)
298
                {
299
                    if (callbackList.Count > 0)
300
                    {
301
                        callbackList.Clear();
302
                        if (_pNative != RootSystem.IntPtr.Zero)
303
                        {
304
                            Windows_Kinect_MultiSourceFrameReader_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
305
                        }
306
                        _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
307
                    }
308
                }
309
            }
310
        }
311
    }
312
313
}
314
#endif