StreamGrabberProxy.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2007-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: AH
  6. //-----------------------------------------------------------------------------
  7. /*!
  8. \file
  9. \brief Low Level API: Pylon generic stream grabber interface declaration
  10. */
  11. #ifndef __PYLON_STREAMGRABBERPROXY__H__
  12. #define __PYLON_STREAMGRABBERPROXY__H__
  13. #if _MSC_VER > 1000
  14. #pragma once
  15. #endif
  16. #include <pylon/Platform.h>
  17. #ifdef _MSC_VER
  18. # pragma pack(push, PYLON_PACKING)
  19. #endif /* _MSC_VER */
  20. #include <Base/GCException.h>
  21. #include <pylon/StreamGrabber.h>
  22. #include "NodeMapProxy.h"
  23. //! Macro to define a custom Node map proxy
  24. #define PYLON_DEFINE_STREAMGRABBER(ClassName, BaseClass) \
  25. class ClassName : public BaseClass \
  26. { \
  27. public: \
  28. /** \name Construction */ \
  29. /*@{*/ \
  30. /** \brief \copybrief Pylon::CStreamGrabberProxyT::CStreamGrabberProxyT()
  31. \copydetails Pylon::CStreamGrabberProxyT::CStreamGrabberProxyT()
  32. */ \
  33. ClassName() \
  34. { \
  35. } \
  36. /** \brief \copybrief Pylon::CStreamGrabberProxyT::CStreamGrabberProxyT(Pylon::IStreamGrabber*)
  37. \copydetails Pylon::CStreamGrabberProxyT::CStreamGrabberProxyT(Pylon::IStreamGrabber*)
  38. */ \
  39. ClassName( IStreamGrabber* pStreamGrabber ) : BaseClass( pStreamGrabber ) \
  40. { \
  41. } \
  42. /*@}*/ \
  43. };
  44. namespace Pylon
  45. {
  46. //**************************************************************************************************
  47. //! Low Level API: The stream grabber class with parameter access methods
  48. /**
  49. This is the base class for pylon stream grabber providing access to configuration parameters.
  50. \see \ref configuringcameras
  51. \tparam TParams The specific parameter class (auto generated from the parameter xml file)
  52. \ingroup Pylon_LowLevelApi
  53. */
  54. //**************************************************************************************************
  55. template<class TParams>
  56. class CStreamGrabberProxyT : public CNodeMapProxyT<TParams>
  57. {
  58. public:
  59. //! \name Construction
  60. // \{
  61. //! Creates a CStreamGrabberProxyT object that is not attached to a pylon stream grabber. Use the Attach() method to attach the pylon stream grabber.
  62. CStreamGrabberProxyT();
  63. //! Creates a CStreamGrabberProxyT object and attaches it to a pylon stream grabber.
  64. CStreamGrabberProxyT( Pylon::IStreamGrabber* );
  65. //! Destructor
  66. virtual ~CStreamGrabberProxyT();
  67. //\}
  68. private:
  69. //! \name Assignment and copying is not supported
  70. // \{
  71. CStreamGrabberProxyT( const CStreamGrabberProxyT& );
  72. CStreamGrabberProxyT& operator=( const CStreamGrabberProxyT& );
  73. // \}
  74. public:
  75. //! \name Some smart pointer functionality
  76. // \{
  77. //! Attach a pylon stream grabber
  78. virtual void Attach( IStreamGrabber* );
  79. //! Checks if a pylon stream grabber is attached
  80. virtual bool IsAttached() const;
  81. //! Returns the pylon stream grabber interface pointer
  82. virtual IStreamGrabber* GetStreamGrabber() const;
  83. // \}
  84. public:
  85. //! \name Implementation of the IStreamGrabber interface
  86. //! See Pylon::IStreamGrabber for more details.
  87. // \{
  88. /** \brief \copybrief Pylon::IStreamGrabber::Open()
  89. \copydetails Pylon::IStreamGrabber::Open()
  90. */
  91. void Open()
  92. {
  93. CheckPtr();
  94. m_pStreamGrabber->Open();
  95. }
  96. /** \brief \copybrief Pylon::IStreamGrabber::Close()
  97. \copydetails Pylon::IStreamGrabber::Close()
  98. */
  99. void Close()
  100. {
  101. CheckPtr();
  102. m_pStreamGrabber->Close();
  103. }
  104. /** \brief \copybrief Pylon::IStreamGrabber::IsOpen()
  105. \copydetails Pylon::IStreamGrabber::IsOpen()
  106. */
  107. bool IsOpen() const
  108. {
  109. CheckPtr();
  110. return m_pStreamGrabber->IsOpen();
  111. }
  112. /** \brief \copybrief Pylon::IStreamGrabber::RegisterBuffer()
  113. \copydetails Pylon::IStreamGrabber::RegisterBuffer()
  114. */
  115. StreamBufferHandle RegisterBuffer( void* pBuffer, size_t bufferSize )
  116. {
  117. CheckPtr();
  118. return m_pStreamGrabber->RegisterBuffer( pBuffer, bufferSize );
  119. }
  120. /** \brief \copybrief Pylon::IStreamGrabber::DeregisterBuffer()
  121. \copydetails Pylon::IStreamGrabber::DeregisterBuffer()
  122. */
  123. const void* DeregisterBuffer( StreamBufferHandle hStreamBuffer )
  124. {
  125. CheckPtr();
  126. return m_pStreamGrabber->DeregisterBuffer( hStreamBuffer );
  127. }
  128. /** \brief \copybrief Pylon::IStreamGrabber::PrepareGrab()
  129. \copydetails Pylon::IStreamGrabber::PrepareGrab()
  130. */
  131. void PrepareGrab()
  132. {
  133. CheckPtr();
  134. m_pStreamGrabber->PrepareGrab();
  135. }
  136. /** \brief \copybrief Pylon::IStreamGrabber::IsStartAndStopStreamingMandatory()
  137. \copydetails Pylon::IStreamGrabber::IsStartAndStopStreamingMandatory()
  138. */
  139. bool IsStartAndStopStreamingMandatory()
  140. {
  141. CheckPtr();
  142. return m_pStreamGrabber->IsStartAndStopStreamingMandatory();
  143. }
  144. /** \brief \copybrief Pylon::IStreamGrabber::StartStreamingIfMandatory()
  145. \copydetails Pylon::IStreamGrabber::StartStreamingIfMandatory()
  146. */
  147. void StartStreamingIfMandatory()
  148. {
  149. CheckPtr();
  150. m_pStreamGrabber->StartStreamingIfMandatory();
  151. }
  152. /** \brief \copybrief Pylon::IStreamGrabber::StopStreamingIfMandatory()
  153. \copydetails Pylon::IStreamGrabber::StopStreamingIfMandatory()
  154. */
  155. void StopStreamingIfMandatory()
  156. {
  157. CheckPtr();
  158. m_pStreamGrabber->StopStreamingIfMandatory();
  159. }
  160. /** \brief \copybrief Pylon::IStreamGrabber::FinishGrab()
  161. \copydetails Pylon::IStreamGrabber::FinishGrab()
  162. */
  163. void FinishGrab()
  164. {
  165. CheckPtr();
  166. m_pStreamGrabber->FinishGrab();
  167. }
  168. /** \brief \copybrief Pylon::IStreamGrabber::QueueBuffer()
  169. \copydetails Pylon::IStreamGrabber::QueueBuffer()
  170. */
  171. void QueueBuffer( StreamBufferHandle hStreamBuffer, const void* pContext = NULL )
  172. {
  173. CheckPtr();
  174. m_pStreamGrabber->QueueBuffer( hStreamBuffer, pContext );
  175. }
  176. /** \brief \copybrief Pylon::IStreamGrabber::FlushBuffersToOutput()
  177. \copydetails Pylon::IStreamGrabber::FlushBuffersToOutput()
  178. */
  179. void FlushBuffersToOutput()
  180. {
  181. CheckPtr();
  182. m_pStreamGrabber->FlushBuffersToOutput();
  183. }
  184. // undocumented, deprecated
  185. void CancelGrab()
  186. {
  187. CheckPtr();
  188. m_pStreamGrabber->FlushBuffersToOutput();
  189. }
  190. /** \brief \copybrief Pylon::IStreamGrabber::RetrieveResult()
  191. \copydetails Pylon::IStreamGrabber::RetrieveResult()
  192. */
  193. bool RetrieveResult( GrabResult& Result )
  194. {
  195. CheckPtr();
  196. return m_pStreamGrabber->RetrieveResult( Result );
  197. }
  198. /** \brief \copybrief Pylon::IStreamGrabber::GetWaitObject()
  199. \copydetails Pylon::IStreamGrabber::GetWaitObject()
  200. */
  201. WaitObject& GetWaitObject() const
  202. {
  203. CheckPtr();
  204. return m_pStreamGrabber->GetWaitObject();
  205. }
  206. /** \brief \copybrief Pylon::IStreamGrabber::GetNodeMap()
  207. \copydetails Pylon::IStreamGrabber::GetNodeMap()
  208. */
  209. GenApi::INodeMap* GetNodeMap()
  210. {
  211. CheckPtr();
  212. return m_pStreamGrabber->GetNodeMap();
  213. }
  214. // \}
  215. protected:
  216. void CheckPtr() const
  217. {
  218. if (NULL == m_pStreamGrabber)
  219. {
  220. throw LOGICAL_ERROR_EXCEPTION( "The stream grabber class is not attached to a pylon stream grabber" );
  221. }
  222. }
  223. IStreamGrabber* m_pStreamGrabber;
  224. };
  225. //**************************************************************************************************
  226. // CStreamGrabberProxyT implementation
  227. //**************************************************************************************************
  228. template<class TParams>
  229. inline CStreamGrabberProxyT<TParams>::CStreamGrabberProxyT()
  230. : CNodeMapProxyT<TParams>(), m_pStreamGrabber( NULL )
  231. {
  232. }
  233. template<class TParams>
  234. inline CStreamGrabberProxyT<TParams>::CStreamGrabberProxyT( IStreamGrabber* pStreamGrabber )
  235. : CNodeMapProxyT<TParams>(), m_pStreamGrabber( NULL )
  236. {
  237. Attach( pStreamGrabber );
  238. }
  239. template<class TParams>
  240. inline CStreamGrabberProxyT<TParams>::~CStreamGrabberProxyT( void )
  241. {
  242. }
  243. template<class TParams>
  244. inline void CStreamGrabberProxyT<TParams>::Attach( IStreamGrabber* pStreamGrabber )
  245. {
  246. if (IsAttached())
  247. {
  248. throw LOGICAL_ERROR_EXCEPTION( "Object is already attached to a stream grabber" );
  249. }
  250. if (NULL == pStreamGrabber)
  251. {
  252. throw LOGICAL_ERROR_EXCEPTION( "Tried to attach a NULL pointer as stream grabber" );
  253. }
  254. CNodeMapProxyT<TParams>::Attach( pStreamGrabber->GetNodeMap() );
  255. m_pStreamGrabber = pStreamGrabber;
  256. }
  257. template<class TParams>
  258. inline bool CStreamGrabberProxyT<TParams>::IsAttached() const
  259. {
  260. return NULL != m_pStreamGrabber;
  261. }
  262. template<class TParams>
  263. inline IStreamGrabber* CStreamGrabberProxyT<TParams>::GetStreamGrabber() const
  264. {
  265. return m_pStreamGrabber;
  266. }
  267. } // namespace Pylon
  268. #ifdef _MSC_VER
  269. # pragma pack(pop)
  270. #endif /* _MSC_VER */
  271. #endif