LongExposureInfraredFrameSource.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. using RootSystem = System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. namespace Windows.Kinect
  5. {
  6. //
  7. // Windows.Kinect.LongExposureInfraredFrameSource
  8. //
  9. public sealed partial class LongExposureInfraredFrameSource : Helper.INativeWrapper
  10. {
  11. internal RootSystem.IntPtr _pNative;
  12. RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
  13. // Constructors and Finalizers
  14. internal LongExposureInfraredFrameSource(RootSystem.IntPtr pNative)
  15. {
  16. _pNative = pNative;
  17. Windows_Kinect_LongExposureInfraredFrameSource_AddRefObject(ref _pNative);
  18. }
  19. ~LongExposureInfraredFrameSource()
  20. {
  21. Dispose(false);
  22. }
  23. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  24. private static extern void Windows_Kinect_LongExposureInfraredFrameSource_ReleaseObject(ref RootSystem.IntPtr pNative);
  25. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  26. private static extern void Windows_Kinect_LongExposureInfraredFrameSource_AddRefObject(ref RootSystem.IntPtr pNative);
  27. private void Dispose(bool disposing)
  28. {
  29. if (_pNative == RootSystem.IntPtr.Zero)
  30. {
  31. return;
  32. }
  33. __EventCleanup();
  34. Helper.NativeObjectCache.RemoveObject<LongExposureInfraredFrameSource>(_pNative);
  35. Windows_Kinect_LongExposureInfraredFrameSource_ReleaseObject(ref _pNative);
  36. _pNative = RootSystem.IntPtr.Zero;
  37. }
  38. // Public Properties
  39. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  40. private static extern RootSystem.IntPtr Windows_Kinect_LongExposureInfraredFrameSource_get_FrameDescription(RootSystem.IntPtr pNative);
  41. public Windows.Kinect.FrameDescription FrameDescription
  42. {
  43. get
  44. {
  45. if (_pNative == RootSystem.IntPtr.Zero)
  46. {
  47. throw new RootSystem.ObjectDisposedException("LongExposureInfraredFrameSource");
  48. }
  49. RootSystem.IntPtr objectPointer = Windows_Kinect_LongExposureInfraredFrameSource_get_FrameDescription(_pNative);
  50. Helper.ExceptionHelper.CheckLastError();
  51. if (objectPointer == RootSystem.IntPtr.Zero)
  52. {
  53. return null;
  54. }
  55. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.FrameDescription>(objectPointer, n => new Windows.Kinect.FrameDescription(n));
  56. }
  57. }
  58. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  59. private static extern bool Windows_Kinect_LongExposureInfraredFrameSource_get_IsActive(RootSystem.IntPtr pNative);
  60. public bool IsActive
  61. {
  62. get
  63. {
  64. if (_pNative == RootSystem.IntPtr.Zero)
  65. {
  66. throw new RootSystem.ObjectDisposedException("LongExposureInfraredFrameSource");
  67. }
  68. return Windows_Kinect_LongExposureInfraredFrameSource_get_IsActive(_pNative);
  69. }
  70. }
  71. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  72. private static extern RootSystem.IntPtr Windows_Kinect_LongExposureInfraredFrameSource_get_KinectSensor(RootSystem.IntPtr pNative);
  73. public Windows.Kinect.KinectSensor KinectSensor
  74. {
  75. get
  76. {
  77. if (_pNative == RootSystem.IntPtr.Zero)
  78. {
  79. throw new RootSystem.ObjectDisposedException("LongExposureInfraredFrameSource");
  80. }
  81. RootSystem.IntPtr objectPointer = Windows_Kinect_LongExposureInfraredFrameSource_get_KinectSensor(_pNative);
  82. Helper.ExceptionHelper.CheckLastError();
  83. if (objectPointer == RootSystem.IntPtr.Zero)
  84. {
  85. return null;
  86. }
  87. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.KinectSensor>(objectPointer, n => new Windows.Kinect.KinectSensor(n));
  88. }
  89. }
  90. // Events
  91. private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle;
  92. [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  93. private delegate void _Windows_Kinect_FrameCapturedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
  94. 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>>>();
  95. [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Kinect_FrameCapturedEventArgs_Delegate))]
  96. private static void Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
  97. {
  98. List<RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs>> callbackList = null;
  99. Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
  100. lock(callbackList)
  101. {
  102. var objThis = Helper.NativeObjectCache.GetObject<LongExposureInfraredFrameSource>(pNative);
  103. var args = new Windows.Kinect.FrameCapturedEventArgs(result);
  104. foreach(var func in callbackList)
  105. {
  106. Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
  107. }
  108. }
  109. }
  110. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  111. private static extern void Windows_Kinect_LongExposureInfraredFrameSource_add_FrameCaptured(RootSystem.IntPtr pNative, _Windows_Kinect_FrameCapturedEventArgs_Delegate eventCallback, bool unsubscribe);
  112. public event RootSystem.EventHandler<Windows.Kinect.FrameCapturedEventArgs> FrameCaptured
  113. {
  114. add
  115. {
  116. Helper.EventPump.EnsureInitialized();
  117. Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  118. var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative];
  119. lock (callbackList)
  120. {
  121. callbackList.Add(value);
  122. if(callbackList.Count == 1)
  123. {
  124. var del = new _Windows_Kinect_FrameCapturedEventArgs_Delegate(Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler);
  125. _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
  126. Windows_Kinect_LongExposureInfraredFrameSource_add_FrameCaptured(_pNative, del, false);
  127. }
  128. }
  129. }
  130. remove
  131. {
  132. if (_pNative == RootSystem.IntPtr.Zero)
  133. {
  134. return;
  135. }
  136. Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  137. var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative];
  138. lock (callbackList)
  139. {
  140. callbackList.Remove(value);
  141. if(callbackList.Count == 0)
  142. {
  143. Windows_Kinect_LongExposureInfraredFrameSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true);
  144. _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free();
  145. }
  146. }
  147. }
  148. }
  149. private static RootSystem.Runtime.InteropServices.GCHandle _Windows_Data_PropertyChangedEventArgs_Delegate_Handle;
  150. [RootSystem.Runtime.InteropServices.UnmanagedFunctionPointer(RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  151. private delegate void _Windows_Data_PropertyChangedEventArgs_Delegate(RootSystem.IntPtr args, RootSystem.IntPtr pNative);
  152. 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>>>();
  153. [AOT.MonoPInvokeCallbackAttribute(typeof(_Windows_Data_PropertyChangedEventArgs_Delegate))]
  154. private static void Windows_Data_PropertyChangedEventArgs_Delegate_Handler(RootSystem.IntPtr result, RootSystem.IntPtr pNative)
  155. {
  156. List<RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs>> callbackList = null;
  157. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryGetValue(pNative, out callbackList);
  158. lock(callbackList)
  159. {
  160. var objThis = Helper.NativeObjectCache.GetObject<LongExposureInfraredFrameSource>(pNative);
  161. var args = new Windows.Data.PropertyChangedEventArgs(result);
  162. foreach(var func in callbackList)
  163. {
  164. Helper.EventPump.Instance.Enqueue(() => { try { func(objThis, args); } catch { } });
  165. }
  166. }
  167. }
  168. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  169. private static extern void Windows_Kinect_LongExposureInfraredFrameSource_add_PropertyChanged(RootSystem.IntPtr pNative, _Windows_Data_PropertyChangedEventArgs_Delegate eventCallback, bool unsubscribe);
  170. public event RootSystem.EventHandler<Windows.Data.PropertyChangedEventArgs> PropertyChanged
  171. {
  172. add
  173. {
  174. Helper.EventPump.EnsureInitialized();
  175. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  176. var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
  177. lock (callbackList)
  178. {
  179. callbackList.Add(value);
  180. if(callbackList.Count == 1)
  181. {
  182. var del = new _Windows_Data_PropertyChangedEventArgs_Delegate(Windows_Data_PropertyChangedEventArgs_Delegate_Handler);
  183. _Windows_Data_PropertyChangedEventArgs_Delegate_Handle = RootSystem.Runtime.InteropServices.GCHandle.Alloc(del);
  184. Windows_Kinect_LongExposureInfraredFrameSource_add_PropertyChanged(_pNative, del, false);
  185. }
  186. }
  187. }
  188. remove
  189. {
  190. if (_pNative == RootSystem.IntPtr.Zero)
  191. {
  192. return;
  193. }
  194. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  195. var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
  196. lock (callbackList)
  197. {
  198. callbackList.Remove(value);
  199. if(callbackList.Count == 0)
  200. {
  201. Windows_Kinect_LongExposureInfraredFrameSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
  202. _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
  203. }
  204. }
  205. }
  206. }
  207. // Public Methods
  208. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention=RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError=true)]
  209. private static extern RootSystem.IntPtr Windows_Kinect_LongExposureInfraredFrameSource_OpenReader(RootSystem.IntPtr pNative);
  210. public Windows.Kinect.LongExposureInfraredFrameReader OpenReader()
  211. {
  212. if (_pNative == RootSystem.IntPtr.Zero)
  213. {
  214. throw new RootSystem.ObjectDisposedException("LongExposureInfraredFrameSource");
  215. }
  216. RootSystem.IntPtr objectPointer = Windows_Kinect_LongExposureInfraredFrameSource_OpenReader(_pNative);
  217. Helper.ExceptionHelper.CheckLastError();
  218. if (objectPointer == RootSystem.IntPtr.Zero)
  219. {
  220. return null;
  221. }
  222. return Helper.NativeObjectCache.CreateOrGetObject<Windows.Kinect.LongExposureInfraredFrameReader>(objectPointer, n => new Windows.Kinect.LongExposureInfraredFrameReader(n));
  223. }
  224. private void __EventCleanup()
  225. {
  226. {
  227. Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  228. var callbackList = Windows_Kinect_FrameCapturedEventArgs_Delegate_callbacks[_pNative];
  229. lock (callbackList)
  230. {
  231. if (callbackList.Count > 0)
  232. {
  233. callbackList.Clear();
  234. if (_pNative != RootSystem.IntPtr.Zero)
  235. {
  236. Windows_Kinect_LongExposureInfraredFrameSource_add_FrameCaptured(_pNative, Windows_Kinect_FrameCapturedEventArgs_Delegate_Handler, true);
  237. }
  238. _Windows_Kinect_FrameCapturedEventArgs_Delegate_Handle.Free();
  239. }
  240. }
  241. }
  242. {
  243. Windows_Data_PropertyChangedEventArgs_Delegate_callbacks.TryAddDefault(_pNative);
  244. var callbackList = Windows_Data_PropertyChangedEventArgs_Delegate_callbacks[_pNative];
  245. lock (callbackList)
  246. {
  247. if (callbackList.Count > 0)
  248. {
  249. callbackList.Clear();
  250. if (_pNative != RootSystem.IntPtr.Zero)
  251. {
  252. Windows_Kinect_LongExposureInfraredFrameSource_add_PropertyChanged(_pNative, Windows_Data_PropertyChangedEventArgs_Delegate_Handler, true);
  253. }
  254. _Windows_Data_PropertyChangedEventArgs_Delegate_Handle.Free();
  255. }
  256. }
  257. }
  258. }
  259. }
  260. }