LongExposureInfraredFrameReader.cs 16 KB

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