EventGrabberProxy.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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 event grabber interface declaration
  10. */
  11. #ifndef __PYLON_EVENTGRABBERPROXY__H__
  12. #define __PYLON_EVENTGRABBERPROXY__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 "EventGrabber.h"
  22. #include "NodeMapProxy.h"
  23. //! Low Level API: Macro to define a custom Node map proxy
  24. #define PYLON_DEFINE_EVENTGRABBER(ClassName, BaseClass) \
  25. class ClassName : public BaseClass \
  26. { \
  27. public: \
  28. /** \name Construction */ \
  29. /*@{*/ \
  30. /** \brief \copybrief Pylon::CEventGrabberProxyT::CEventGrabberProxyT()
  31. \copydetails Pylon::CEventGrabberProxyT::CEventGrabberProxyT()
  32. */ \
  33. ClassName() \
  34. { \
  35. } \
  36. /** \brief \copybrief Pylon::CEventGrabberProxyT::CEventGrabberProxyT(Pylon::IEventGrabber*)
  37. \copydetails Pylon::CEventGrabberProxyT::CEventGrabberProxyT(Pylon::IEventGrabber*)
  38. */ \
  39. ClassName( Pylon::IEventGrabber* pEventGrabber ) : BaseClass( pEventGrabber ) \
  40. { \
  41. } \
  42. /*@}*/ \
  43. };
  44. namespace Pylon
  45. {
  46. //**************************************************************************************************
  47. //! Low Level API: The event grabber class with parameter access methods
  48. /**
  49. This is the base class for pylon event 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 CEventGrabberProxyT : public CNodeMapProxyT<TParams>
  57. {
  58. public:
  59. //! \name Construction
  60. // \{
  61. //! Creates a CEventGrabberProxyT object that is not attached to a pylon stream grabber. Use the Attach() method to attach the pylon event grabber.
  62. CEventGrabberProxyT();
  63. //! Creates a CEventGrabberProxyT object and attaches it to a pylon event grabber.
  64. CEventGrabberProxyT( Pylon::IEventGrabber* );
  65. //! Destructor
  66. virtual ~CEventGrabberProxyT();
  67. //\}
  68. private:
  69. //! \name Assignment and copying is not supported
  70. // \{
  71. CEventGrabberProxyT( const CEventGrabberProxyT& );
  72. CEventGrabberProxyT& operator=( const CEventGrabberProxyT& );
  73. // \}
  74. public:
  75. //! \name Some smart pointer functionality
  76. // \{
  77. //! Attach a pylon event grabber
  78. virtual void Attach( IEventGrabber* );
  79. //! Checks if a pylon stream grabber is attached
  80. virtual bool IsAttached() const;
  81. //! Returns the pylon event grabber interface pointer
  82. virtual IEventGrabber* GetEventGrabber() const;
  83. // \}
  84. public:
  85. //! \name Implementation of the IEventGrabber interface
  86. //! See Pylon::IEventGrabber for more details.
  87. // \{
  88. /** \brief \copybrief Pylon::IEventGrabber::Open()
  89. \copydetails Pylon::IEventGrabber::Open()
  90. */
  91. void Open()
  92. {
  93. CheckPtr();
  94. m_pEventGrabber->Open();
  95. }
  96. /** \brief \copybrief Pylon::IEventGrabber::Close()
  97. \copydetails Pylon::IEventGrabber::Close()
  98. */
  99. void Close()
  100. {
  101. CheckPtr();
  102. m_pEventGrabber->Close();
  103. }
  104. /** \brief \copybrief Pylon::IEventGrabber::IsOpen()
  105. \copydetails Pylon::IEventGrabber::IsOpen()
  106. */
  107. bool IsOpen() const
  108. {
  109. CheckPtr();
  110. return m_pEventGrabber->IsOpen();
  111. }
  112. /** \brief \copybrief Pylon::IEventGrabber::RetrieveEvent()
  113. \copydetails Pylon::IEventGrabber::RetrieveEvent()
  114. */
  115. bool RetrieveEvent( EventResult& Result )
  116. {
  117. CheckPtr();
  118. return m_pEventGrabber->RetrieveEvent( Result );
  119. }
  120. /** \brief \copybrief Pylon::IEventGrabber::GetWaitObject()
  121. \copydetails Pylon::IEventGrabber::GetWaitObject()
  122. */
  123. WaitObject& GetWaitObject() const
  124. {
  125. CheckPtr();
  126. return m_pEventGrabber->GetWaitObject();
  127. }
  128. /** \brief \copybrief Pylon::IEventGrabber::GetNodeMap()
  129. \copydetails Pylon::IEventGrabber::GetNodeMap()
  130. */
  131. GenApi::INodeMap* GetNodeMap()
  132. {
  133. CheckPtr();
  134. return m_pEventGrabber->GetNodeMap();
  135. }
  136. // \}
  137. protected:
  138. void CheckPtr() const
  139. {
  140. if (NULL == m_pEventGrabber)
  141. {
  142. throw LOGICAL_ERROR_EXCEPTION( "The stream grabber class is not attached to a pylon event grabber" );
  143. }
  144. }
  145. IEventGrabber* m_pEventGrabber;
  146. };
  147. //**************************************************************************************************
  148. // CEventGrabberProxyT implementation
  149. //**************************************************************************************************
  150. template<class TParams>
  151. inline CEventGrabberProxyT<TParams>::CEventGrabberProxyT()
  152. : CNodeMapProxyT<TParams>(), m_pEventGrabber( NULL )
  153. {
  154. }
  155. template<class TParams>
  156. inline CEventGrabberProxyT<TParams>::CEventGrabberProxyT( IEventGrabber* pEventGrabber )
  157. : CNodeMapProxyT<TParams>(), m_pEventGrabber( NULL )
  158. {
  159. Attach( pEventGrabber );
  160. }
  161. template<class TParams>
  162. inline CEventGrabberProxyT<TParams>::~CEventGrabberProxyT( void )
  163. {
  164. }
  165. template<class TParams>
  166. inline void CEventGrabberProxyT<TParams>::Attach( IEventGrabber* pEventGrabber )
  167. {
  168. if (IsAttached())
  169. {
  170. throw LOGICAL_ERROR_EXCEPTION( "Object is already attached to a stream grabber" );
  171. }
  172. if (NULL == pEventGrabber)
  173. {
  174. throw LOGICAL_ERROR_EXCEPTION( "Tried to attach a NULL pointer as event grabber" );
  175. }
  176. CNodeMapProxyT<TParams>::Attach( pEventGrabber->GetNodeMap() );
  177. m_pEventGrabber = pEventGrabber;
  178. }
  179. template<class TParams>
  180. inline bool CEventGrabberProxyT<TParams>::IsAttached() const
  181. {
  182. return NULL != m_pEventGrabber;
  183. }
  184. template<class TParams>
  185. inline IEventGrabber* CEventGrabberProxyT<TParams>::GetEventGrabber() const
  186. {
  187. return m_pEventGrabber;
  188. }
  189. } // namespace Pylon
  190. #ifdef _MSC_VER
  191. # pragma pack(pop)
  192. #endif /* _MSC_VER */
  193. #endif