PylonDeviceProxy.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  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 device interface declaration
  10. */
  11. #ifndef __PYLON_PYLONDEVICEPROXY__H__
  12. #define __PYLON_PYLONDEVICEPROXY__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 "Device.h"
  22. #include "TlFactory.h"
  23. //! Macro to define a custom camera class
  24. #define PYLON_DEFINE_CAMERA(ClassName, BaseClass) \
  25. PYLON_6_0_DEPRECATED("Use CBaslerUniversalInstantCamera") \
  26. class ClassName : public BaseClass \
  27. { \
  28. public: \
  29. /** \name Construction */ \
  30. /*@{*/ \
  31. /** \brief \copybrief Pylon::CPylonDeviceProxyT::CPylonDeviceProxyT()
  32. \copydetails Pylon::CPylonDeviceProxyT::CPylonDeviceProxyT()
  33. */ \
  34. ClassName() \
  35. { \
  36. } \
  37. /** \brief \copybrief Pylon::CPylonDeviceProxyT::CPylonDeviceProxyT(IPylonDevice*,bool)
  38. \copydetails Pylon::CPylonDeviceProxyT::CPylonDeviceProxyT(IPylonDevice*,bool)
  39. */ \
  40. ClassName( IPylonDevice* pDevice, bool takeOwnership = true ) : BaseClass( pDevice, takeOwnership ) \
  41. { \
  42. } \
  43. /** \brief \copybrief Pylon::CPylonDeviceProxyT::~CPylonDeviceProxyT()
  44. \copydetails Pylon::CPylonDeviceProxyT::~CPylonDeviceProxyT()
  45. */ \
  46. virtual ~ClassName() \
  47. { \
  48. } \
  49. /*@}*/ \
  50. };
  51. namespace Pylon
  52. {
  53. //**************************************************************************************************
  54. //! Low Level API: The camera class for generic camera devices
  55. /**
  56. This is the base class for pylon camera classes providing access to camera parameters.
  57. \see \ref configuringcameras
  58. \tparam TCameraParams The camera specific parameter class (auto generated from camera xml file)
  59. \ingroup Pylon_LowLevelApi
  60. */
  61. //**************************************************************************************************
  62. template<class TCameraParams>
  63. class CPylonDeviceProxyT : public TCameraParams
  64. {
  65. public:
  66. //! \name Construction
  67. // \{
  68. //! Creates a camera object that is not attached to an pylon device. Use the Attach() method to attach the device
  69. CPylonDeviceProxyT();
  70. /** \brief Creates a camera object and attaches a camera object to a pylon device that takes the ownership over an pylon device.
  71. When having the ownership, the destructor of this camera object destroys the pylon device
  72. the camera object is attached to. Otherwise, the pylon device object remains valid when the camera
  73. object has been destroyed.
  74. */
  75. CPylonDeviceProxyT( IPylonDevice*, bool takeOwnership = true );
  76. //! Destructor
  77. virtual ~CPylonDeviceProxyT();
  78. //\}
  79. private:
  80. //! \name Assignment and copying is not supported
  81. // \{
  82. CPylonDeviceProxyT( const CPylonDeviceProxyT& );
  83. CPylonDeviceProxyT& operator=( const CPylonDeviceProxyT& );
  84. // \}
  85. public:
  86. //! \name Some smart pointer functionality
  87. // \{
  88. /** \brief Attach the camera object to a pylon device
  89. It is not allowed to call Attach when the camera object is already attached!
  90. When having the ownership, the destructor of this camera object destroys the pylon device
  91. the camera object is attached to. Otherwise, the pylon device object remains valid when the camera
  92. object has been destroyed.
  93. */
  94. virtual void Attach( IPylonDevice*, bool takeOwnership = true );
  95. //! Checks if a pylon device is attached to the camera object
  96. virtual bool IsAttached() const;
  97. //! Checks if the camera object has the ownership of the pylon device
  98. virtual bool HasOwnership() const;
  99. //! Returns the pylon device interface pointer
  100. virtual IPylonDevice* GetDevice() const;
  101. // \}
  102. public:
  103. //! \name Implementation of the IPylonDevice interface.
  104. //! See Pylon::IPylonDevice for more details.
  105. // \{
  106. /** \brief \copybrief Pylon::IPylonDevice::Open()
  107. \copydetails Pylon::IPylonDevice::Open()
  108. */
  109. void Open( AccessModeSet mode = (Stream | Control | Event) )
  110. {
  111. CheckDevicePtr();
  112. m_pDevice->Open( mode );
  113. }
  114. /** \brief \copybrief Pylon::IPylonDevice::Close()
  115. \copydetails Pylon::IPylonDevice::Close()
  116. */
  117. void Close( void )
  118. {
  119. CheckDevicePtr();
  120. m_pDevice->Close();
  121. }
  122. /** \brief \copybrief Pylon::IPylonDevice::IsOpen()
  123. \copydetails Pylon::IPylonDevice::IsOpen()
  124. */
  125. bool IsOpen( void ) const
  126. {
  127. CheckDevicePtr();
  128. return m_pDevice->IsOpen();
  129. }
  130. /** \brief \copybrief Pylon::IPylonDevice::AccessMode()
  131. \copydetails Pylon::IPylonDevice::AccessMode()
  132. */
  133. AccessModeSet AccessMode( void ) const
  134. {
  135. CheckDevicePtr();
  136. return m_pDevice->AccessMode();
  137. }
  138. /** \brief \copybrief Pylon::IPylonDevice::GetDeviceInfo()
  139. \copydetails Pylon::IPylonDevice::GetDeviceInfo()
  140. */
  141. const CDeviceInfo& GetDeviceInfo( void ) const
  142. {
  143. CheckDevicePtr();
  144. return m_pDevice->GetDeviceInfo();
  145. }
  146. /** \brief \copybrief Pylon::IPylonDevice::GetNumStreamGrabberChannels()
  147. \copydetails Pylon::IPylonDevice::GetNumStreamGrabberChannels()
  148. */
  149. uint32_t GetNumStreamGrabberChannels( void ) const
  150. {
  151. CheckDevicePtr();
  152. return m_pDevice->GetNumStreamGrabberChannels();
  153. }
  154. /** \brief \copybrief Pylon::IPylonDevice::GetStreamGrabber()
  155. \copydetails Pylon::IPylonDevice::GetStreamGrabber()
  156. */
  157. IStreamGrabber* GetStreamGrabber( uint32_t index )
  158. {
  159. CheckDevicePtr();
  160. return m_pDevice->GetStreamGrabber( index );
  161. }
  162. /** \brief \copybrief Pylon::IPylonDevice::GetEventGrabber()
  163. \copydetails Pylon::IPylonDevice::GetEventGrabber()
  164. */
  165. IEventGrabber* GetEventGrabber( void )
  166. {
  167. CheckDevicePtr();
  168. return m_pDevice->GetEventGrabber();
  169. }
  170. /** \brief \copybrief Pylon::IPylonDevice::GetNodeMap()
  171. \copydetails Pylon::IPylonDevice::GetNodeMap()
  172. */
  173. GenApi::INodeMap* GetNodeMap( void )
  174. {
  175. CheckDevicePtr();
  176. return m_pDevice->GetNodeMap();
  177. }
  178. /** \brief \copybrief Pylon::IPylonDevice::GetTLNodeMap()
  179. \copydetails Pylon::IPylonDevice::GetTLNodeMap()
  180. */
  181. GenApi::INodeMap* GetTLNodeMap( void )
  182. {
  183. CheckDevicePtr();
  184. return m_pDevice->GetTLNodeMap();
  185. }
  186. /** \brief \copybrief Pylon::IPylonDevice::CreateChunkParser()
  187. \copydetails Pylon::IPylonDevice::CreateChunkParser()
  188. */
  189. Pylon::IChunkParser* CreateChunkParser( void )
  190. {
  191. CheckDevicePtr();
  192. return m_pDevice->CreateChunkParser();
  193. }
  194. /** \brief \copybrief Pylon::IPylonDevice::DestroyChunkParser()
  195. \copydetails Pylon::IPylonDevice::DestroyChunkParser()
  196. */
  197. void DestroyChunkParser( Pylon::IChunkParser* pChunkParser )
  198. {
  199. CheckDevicePtr();
  200. m_pDevice->DestroyChunkParser( pChunkParser );
  201. }
  202. /** \brief \copybrief Pylon::IPylonDevice::CreateEventAdapter()
  203. \copydetails Pylon::IPylonDevice::CreateEventAdapter()
  204. */
  205. IEventAdapter* CreateEventAdapter( void )
  206. {
  207. CheckDevicePtr();
  208. return m_pDevice->CreateEventAdapter();
  209. }
  210. /** \brief \copybrief Pylon::IPylonDevice::DestroyEventAdapter()
  211. \copydetails Pylon::IPylonDevice::DestroyEventAdapter()
  212. */
  213. void DestroyEventAdapter( IEventAdapter* pAdapter )
  214. {
  215. CheckDevicePtr();
  216. m_pDevice->DestroyEventAdapter( pAdapter );
  217. }
  218. /** \brief \copybrief Pylon::IPylonDevice::CreateSelfReliantChunkParser()
  219. \copydetails Pylon::IPylonDevice::CreateSelfReliantChunkParser()
  220. */
  221. virtual ISelfReliantChunkParser* CreateSelfReliantChunkParser()
  222. {
  223. CheckDevicePtr();
  224. return m_pDevice->CreateSelfReliantChunkParser();
  225. }
  226. /** \brief \copybrief Pylon::IPylonDevice::DestroySelfReliantChunkParser()
  227. \copydetails Pylon::IPylonDevice::DestroySelfReliantChunkParser()
  228. */
  229. virtual void DestroySelfReliantChunkParser( ISelfReliantChunkParser* pChunkParser )
  230. {
  231. CheckDevicePtr();
  232. m_pDevice->DestroySelfReliantChunkParser( pChunkParser );
  233. }
  234. /** \brief \copybrief Pylon::IPylonDevice::RegisterRemovalCallback()
  235. \copydetails Pylon::IPylonDevice::RegisterRemovalCallback()
  236. */
  237. DeviceCallbackHandle RegisterRemovalCallback( DeviceCallback& d )
  238. {
  239. CheckDevicePtr();
  240. return m_pDevice->RegisterRemovalCallback( d );
  241. }
  242. /** \brief \copybrief Pylon::IPylonDevice::DeregisterRemovalCallback()
  243. \copydetails Pylon::IPylonDevice::DeregisterRemovalCallback()
  244. */
  245. bool DeregisterRemovalCallback( DeviceCallbackHandle h )
  246. {
  247. CheckDevicePtr();
  248. return m_pDevice->DeregisterRemovalCallback( h );
  249. }
  250. // \}
  251. protected:
  252. void CheckDevicePtr() const
  253. {
  254. if (NULL == m_pDevice)
  255. {
  256. throw LOGICAL_ERROR_EXCEPTION( "The camera class is not attached to a IPylonDevice" );
  257. }
  258. }
  259. IPylonDevice* m_pDevice;
  260. bool m_hasOwnership;
  261. };
  262. //**************************************************************************************************
  263. // CPylonDeviceProxyT implementation
  264. //**************************************************************************************************
  265. template<class TCameraParams>
  266. inline CPylonDeviceProxyT<TCameraParams>::CPylonDeviceProxyT( void )
  267. : m_pDevice( NULL )
  268. , m_hasOwnership( false )
  269. {
  270. }
  271. template<class TCameraParams>
  272. inline CPylonDeviceProxyT<TCameraParams>::CPylonDeviceProxyT( IPylonDevice* pDevice, bool takeOwnership )
  273. : m_pDevice( NULL )
  274. , m_hasOwnership( false )
  275. {
  276. Attach( pDevice, takeOwnership );
  277. }
  278. template<class TCameraParams>
  279. inline CPylonDeviceProxyT<TCameraParams>::~CPylonDeviceProxyT( void )
  280. {
  281. if (HasOwnership() && IsAttached())
  282. {
  283. CTlFactory::GetInstance().DestroyDevice( m_pDevice );
  284. }
  285. }
  286. template<class TCameraParams>
  287. inline void CPylonDeviceProxyT<TCameraParams>::Attach( IPylonDevice* pDevice, bool takeOwnership )
  288. {
  289. if (IsAttached())
  290. {
  291. throw LOGICAL_ERROR_EXCEPTION( "Object is already attached to a pylon device" );
  292. }
  293. if (NULL == pDevice)
  294. {
  295. throw LOGICAL_ERROR_EXCEPTION( "Tried to attach a NULL pointer as device" );
  296. }
  297. TCameraParams::_Initialize( pDevice->GetNodeMap() );
  298. m_pDevice = pDevice;
  299. m_hasOwnership = takeOwnership;
  300. }
  301. template<class TCameraParams>
  302. inline bool CPylonDeviceProxyT<TCameraParams>::IsAttached() const
  303. {
  304. return NULL != m_pDevice;
  305. }
  306. template<class TCameraParams>
  307. inline bool CPylonDeviceProxyT<TCameraParams>::HasOwnership() const
  308. {
  309. return m_hasOwnership;
  310. }
  311. template<class TCameraParams>
  312. inline IPylonDevice* CPylonDeviceProxyT<TCameraParams>::GetDevice() const
  313. {
  314. return m_pDevice;
  315. }
  316. } // namespace Pylon
  317. #ifdef _MSC_VER
  318. # pragma pack(pop)
  319. #endif /* _MSC_VER */
  320. #endif