MultiSourceFrameReader.cs 16 KB

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