KinectBuffer.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. using RootSystem = System;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Runtime.InteropServices;
  5. namespace Windows.Kinect
  6. {
  7. // NOTE: This uses an IBuffer under the covers, it is renamed here to give parity to our managed APIs.
  8. public class KinectBuffer : Helper.INativeWrapper, IDisposable
  9. {
  10. internal RootSystem.IntPtr _pNative;
  11. RootSystem.IntPtr Helper.INativeWrapper.nativePtr { get { return _pNative; } }
  12. // Constructors and Finalizers
  13. internal KinectBuffer(RootSystem.IntPtr pNative)
  14. {
  15. _pNative = pNative;
  16. Windows_Storage_Streams_IBuffer_AddRefObject(ref _pNative);
  17. }
  18. ~KinectBuffer()
  19. {
  20. Dispose(false);
  21. }
  22. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  23. private static extern void Windows_Storage_Streams_IBuffer_ReleaseObject(ref RootSystem.IntPtr pNative);
  24. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  25. private static extern void Windows_Storage_Streams_IBuffer_AddRefObject(ref RootSystem.IntPtr pNative);
  26. private void Dispose(bool disposing)
  27. {
  28. if (_pNative == RootSystem.IntPtr.Zero)
  29. {
  30. return;
  31. }
  32. Helper.NativeObjectCache.RemoveObject<KinectBuffer>(_pNative);
  33. if (disposing)
  34. {
  35. Windows_Storage_Streams_IBuffer_Dispose(_pNative);
  36. }
  37. Windows_Storage_Streams_IBuffer_ReleaseObject(ref _pNative);
  38. _pNative = RootSystem.IntPtr.Zero;
  39. }
  40. // Public Properties
  41. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  42. private static extern uint Windows_Storage_Streams_IBuffer_get_Capacity(RootSystem.IntPtr pNative);
  43. public uint Capacity
  44. {
  45. get
  46. {
  47. if (_pNative == RootSystem.IntPtr.Zero)
  48. {
  49. throw new RootSystem.ObjectDisposedException("KinectBuffer");
  50. }
  51. uint capacity = Windows_Storage_Streams_IBuffer_get_Capacity(_pNative);
  52. Helper.ExceptionHelper.CheckLastError();
  53. return capacity;
  54. }
  55. }
  56. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  57. private static extern uint Windows_Storage_Streams_IBuffer_get_Length(RootSystem.IntPtr pNative);
  58. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  59. private static extern void Windows_Storage_Streams_IBuffer_put_Length(RootSystem.IntPtr pNative, uint value);
  60. public uint Length
  61. {
  62. get
  63. {
  64. if (_pNative == RootSystem.IntPtr.Zero)
  65. {
  66. throw new RootSystem.ObjectDisposedException("KinectBuffer");
  67. }
  68. uint length = Windows_Storage_Streams_IBuffer_get_Length(_pNative);
  69. Helper.ExceptionHelper.CheckLastError();
  70. return length;
  71. }
  72. set
  73. {
  74. if (_pNative == RootSystem.IntPtr.Zero)
  75. {
  76. throw new RootSystem.ObjectDisposedException("KinectBuffer");
  77. }
  78. Windows_Storage_Streams_IBuffer_put_Length(_pNative, value);
  79. Helper.ExceptionHelper.CheckLastError();
  80. }
  81. }
  82. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl)]
  83. private static extern void Windows_Storage_Streams_IBuffer_Dispose(RootSystem.IntPtr pNative);
  84. // Constructors and Finalizers
  85. public void Dispose()
  86. {
  87. if (_pNative == RootSystem.IntPtr.Zero)
  88. {
  89. throw new RootSystem.ObjectDisposedException("KinectBuffer");
  90. }
  91. Dispose(true);
  92. RootSystem.GC.SuppressFinalize(this);
  93. }
  94. [RootSystem.Runtime.InteropServices.DllImport("KinectUnityAddin", CallingConvention = RootSystem.Runtime.InteropServices.CallingConvention.Cdecl, SetLastError = true)]
  95. private static extern RootSystem.IntPtr Windows_Storage_Streams_IBuffer_get_UnderlyingBuffer(RootSystem.IntPtr pNative);
  96. public IntPtr UnderlyingBuffer
  97. {
  98. get
  99. {
  100. if (_pNative == RootSystem.IntPtr.Zero)
  101. {
  102. throw new RootSystem.ObjectDisposedException("KinectBuffer");
  103. }
  104. RootSystem.IntPtr value = Windows_Storage_Streams_IBuffer_get_UnderlyingBuffer(_pNative);
  105. Helper.ExceptionHelper.CheckLastError();
  106. return value;
  107. }
  108. }
  109. }
  110. }