t1 / TFDContents / Assets / Standard Assets / Windows / Kinect / InfraredFrameSource.cs @ 9
이력 | 보기 | 이력해설 | 다운로드 (14.7 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.InfraredFrameSource |
||
9 | // |
||
10 | public sealed partial class InfraredFrameSource : 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 InfraredFrameSource(RootSystem.IntPtr pNative) |
||
18 | { |
||
19 | _pNative = pNative; |
||
20 | Windows_Kinect_InfraredFrameSource_AddRefObject(ref _pNative); |
||
21 | } |
||
22 | |||
23 | ~InfraredFrameSource() |
||
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_InfraredFrameSource_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_InfraredFrameSource_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<InfraredFrameSource>(_pNative); |
||
42 | Windows_Kinect_InfraredFrameSource_ReleaseObject(ref _pNative); |
||
43 | |||
44 | _pNative = RootSystem.IntPtr.Zero; |
||
45 | } |
||
46 | |||
47 | |||
48 | // Public Properties |
||
49 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)] |
||
50 | private static extern RootSystem.IntPtr Windows_Kinect_InfraredFrameSource_get_FrameDescription(RootSystem.IntPtr pNative); |
||
51 | public Windows.Kinect.FrameDescription FrameDescription |
||
52 | { |
||
53 | get |
||
54 | { |
||
55 | if (_pNative == RootSystem.IntPtr.Zero) |
||
56 | { |
||
57 | throw new RootSystem.ObjectDisposedException("InfraredFrameSource"); |
||
58 | } |
||
59 | |||
60 | RootSystem.IntPtr objectPointer = Windows_Kinect_InfraredFrameSource_get_FrameDescription(_pNative); |
||
61 | Helper.ExceptionHelper.CheckLastError(); |
||
62 | if (objectPointer == RootSystem.IntPtr.Zero) |
||
63 | { |
||
64 | return null; |
||
65 | } |
||
66 | |||
67 | return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.FrameDescription>(objectPointer, n => new Windows.Kinect.FrameDescription(n)); |
||
68 | } |
||
69 | } |
||
70 | |||
71 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)] |
||
72 | private static extern bool Windows_Kinect_InfraredFrameSource_get_IsActive(RootSystem.IntPtr pNative); |
||
73 | public bool IsActive |
||
74 | { |
||
75 | get |
||
76 | { |
||
77 | if (_pNative == RootSystem.IntPtr.Zero) |
||
78 | { |
||
79 | throw new RootSystem.ObjectDisposedException("InfraredFrameSource"); |
||
80 | } |
||
81 | |||
82 | return Windows_Kinect_InfraredFrameSource_get_IsActive(_pNative); |
||
83 | } |
||
84 | } |
||
85 | |||
86 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)] |
||
87 | private static extern RootSystem.IntPtr Windows_Kinect_InfraredFrameSource_get_KinectSensor(RootSystem.IntPtr pNative); |
||
88 | public Windows.Kinect.KinectSensor KinectSensor |
||
89 | { |
||
90 | get |
||
91 | { |
||
92 | if (_pNative == RootSystem.IntPtr.Zero) |
||
93 | { |
||
94 | throw new RootSystem.ObjectDisposedException("InfraredFrameSource"); |
||
95 | } |
||
96 | |||
97 | RootSystem.IntPtr objectPointer = Windows_Kinect_InfraredFrameSource_get_KinectSensor(_pNative); |
||
98 | Helper.ExceptionHelper.CheckLastError(); |
||
99 | if (objectPointer == RootSystem.IntPtr.Zero) |
||
100 | { |
||
101 | return null; |
||
102 | } |
||
103 | |||
104 | return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectSensor>(objectPointer, n => new Windows.Kinect.KinectSensor(n)); |
||
105 | } |
||
106 | } |
||
107 | |||
108 | |||
109 | // Events |
||
110 | private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle; |
||
111 | [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)] |
||
112 | private delegate void _Windows_Kinect_FrameCapturedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative); |
||
113 | private static Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>>> Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks = new Helper.CollectionMap<RootSystem.IntPtr, List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>>>(); |
||
114 | [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_FrameCapturedEventArgs_Delegate))] |
||
115 | private static void Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative) |
||
116 | { |
||
117 | List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>> callbackList = null; |
||
118 | Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList); |
||
119 | lock(callbackList) |
||
120 | { |
||
121 | var objThis = Helper.NativeObjectCache.GetObject<InfraredFrameSource>(pNative); |
||
122 | var args = new Windows.Kinect.FrameCapturedEventArgs(result); |
||
123 | foreach(var func in callbackList) |
||
124 | { |
||
125 | Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } }); |
||
126 | } |
||
127 | } |
||
128 | } |
||
129 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)] |
||
130 | private static extern void Windows_Kinect_InfraredFrameSource_add_FrameCaptured(RootSystem.IntPtr pNative, _Windows_Kinect_FrameCapturedEventArgs_Delegate eventCallback, bool unsubscribe); |
||
131 | public event RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs> FrameCaptured |
||
132 | { |
||
133 | add |
||
134 | { |
||
135 | Helper.EventPump.EnsureInitialized(); |
||
136 | |||
137 | Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
138 | var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative]; |
||
139 | lock (callbackList) |
||
140 | { |
||
141 | callbackList.Add(value); |
||
142 | if(callbackList.Count == 1) |
||
143 | { |
||
144 | var del = new _Windows_Kinect_FrameCapturedEventArgs_Delegate(Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler); |
||
145 | _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del); |
||
146 | Windows_Kinect_InfraredFrameSource_add_FrameCaptured(_pNative, del, false); |
||
147 | } |
||
148 | } |
||
149 | } |
||
150 | remove |
||
151 | { |
||
152 | if (_pNative == RootSystem.IntPtr.Zero) |
||
153 | { |
||
154 | return; |
||
155 | } |
||
156 | |||
157 | Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
158 | var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative]; |
||
159 | lock (callbackList) |
||
160 | { |
||
161 | callbackList.Remove(value); |
||
162 | if(callbackList.Count == 0) |
||
163 | { |
||
164 | Windows_Kinect_InfraredFrameSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true); |
||
165 | _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free(); |
||
166 | } |
||
167 | } |
||
168 | } |
||
169 | } |
||
170 | |||
171 | private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle; |
||
172 | [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)] |
||
173 | private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative); |
||
174 | 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>>>(); |
||
175 | [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))] |
||
176 | private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative) |
||
177 | { |
||
178 | List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null; |
||
179 | Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList); |
||
180 | lock(callbackList) |
||
181 | { |
||
182 | var objThis = Helper.NativeObjectCache.GetObject<InfraredFrameSource>(pNative); |
||
183 | var args = new Windows.Data.PropertyChangedEventArgs(result); |
||
184 | foreach(var func in callbackList) |
||
185 | { |
||
186 | Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } }); |
||
187 | } |
||
188 | } |
||
189 | } |
||
190 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)] |
||
191 | private static extern void Windows_Kinect_InfraredFrameSource_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe); |
||
192 | public event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged |
||
193 | { |
||
194 | add |
||
195 | { |
||
196 | Helper.EventPump.EnsureInitialized(); |
||
197 | |||
198 | Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
199 | var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative]; |
||
200 | lock (callbackList) |
||
201 | { |
||
202 | callbackList.Add(value); |
||
203 | if(callbackList.Count == 1) |
||
204 | { |
||
205 | var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler); |
||
206 | _Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del); |
||
207 | Windows_Kinect_InfraredFrameSource_add_PropertyChanged(_pNative, del, false); |
||
208 | } |
||
209 | } |
||
210 | } |
||
211 | remove |
||
212 | { |
||
213 | if (_pNative == RootSystem.IntPtr.Zero) |
||
214 | { |
||
215 | return; |
||
216 | } |
||
217 | |||
218 | Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
219 | var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative]; |
||
220 | lock (callbackList) |
||
221 | { |
||
222 | callbackList.Remove(value); |
||
223 | if(callbackList.Count == 0) |
||
224 | { |
||
225 | Windows_Kinect_InfraredFrameSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true); |
||
226 | _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free(); |
||
227 | } |
||
228 | } |
||
229 | } |
||
230 | } |
||
231 | |||
232 | |||
233 | // Public Methods |
||
234 | [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)] |
||
235 | private static extern RootSystem.IntPtr Windows_Kinect_InfraredFrameSource_OpenReader(RootSystem.IntPtr pNative); |
||
236 | public Windows.Kinect.InfraredFrameReader OpenReader() |
||
237 | { |
||
238 | if (_pNative == RootSystem.IntPtr.Zero) |
||
239 | { |
||
240 | throw new RootSystem.ObjectDisposedException("InfraredFrameSource"); |
||
241 | } |
||
242 | |||
243 | RootSystem.IntPtr objectPointer = Windows_Kinect_InfraredFrameSource_OpenReader(_pNative); |
||
244 | Helper.ExceptionHelper.CheckLastError(); |
||
245 | if (objectPointer == RootSystem.IntPtr.Zero) |
||
246 | { |
||
247 | return null; |
||
248 | } |
||
249 | |||
250 | return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.InfraredFrameReader>(objectPointer, n => new Windows.Kinect.InfraredFrameReader(n)); |
||
251 | } |
||
252 | |||
253 | private void __EventCleanup() |
||
254 | { |
||
255 | { |
||
256 | Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
257 | var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative]; |
||
258 | lock (callbackList) |
||
259 | { |
||
260 | if (callbackList.Count > 0) |
||
261 | { |
||
262 | callbackList.Clear(); |
||
263 | if (_pNative != RootSystem.IntPtr.Zero) |
||
264 | { |
||
265 | Windows_Kinect_InfraredFrameSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true); |
||
266 | } |
||
267 | _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free(); |
||
268 | } |
||
269 | } |
||
270 | } |
||
271 | { |
||
272 | Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative); |
||
273 | var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative]; |
||
274 | lock (callbackList) |
||
275 | { |
||
276 | if (callbackList.Count > 0) |
||
277 | { |
||
278 | callbackList.Clear(); |
||
279 | if (_pNative != RootSystem.IntPtr.Zero) |
||
280 | { |
||
281 | Windows_Kinect_InfraredFrameSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true); |
||
282 | } |
||
283 | _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free(); |
||
284 | } |
||
285 | } |
||
286 | } |
||
287 | } |
||
288 | } |
||
289 | |||
290 | } |
||
291 | #endif |