BaslerUniversalConfigurationEventHandler.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. //-----------------------------------------------------------------------------
  2. // Basler pylon SDK
  3. // Copyright (c) 2010-2021 Basler AG
  4. // http://www.baslerweb.com
  5. // Author: Andreas Gau
  6. //-----------------------------------------------------------------------------
  7. /**
  8. \file
  9. \brief Contains the configuration event handler base class.
  10. */
  11. #ifndef INCLUDED_BASLERUNIVERSALCONFIGURATIONEVENTHANDLERH
  12. #define INCLUDED_BASLERUNIVERSALCONFIGURATIONEVENTHANDLERH
  13. #pragma once
  14. #include <pylon/stdinclude.h>
  15. #ifdef _MSC_VER
  16. # pragma pack(push, PYLON_PACKING)
  17. #endif /* _MSC_VER */
  18. namespace Pylon
  19. {
  20. class CBaslerUniversalInstantCamera;
  21. /** \addtogroup Pylon_InstantCameraApiUniversal
  22. * @{
  23. */
  24. /**
  25. \class CBaslerUniversalConfigurationEventHandler
  26. \brief The configuration event handler base class.
  27. */
  28. class CBaslerUniversalConfigurationEventHandler
  29. {
  30. public:
  31. /**
  32. \brief This method is called before a %Pylon Device (Pylon::IPylonDevice) is attached by calling the Instant Camera object's Attach() method.
  33. This method can not be used for detecting that a camera device has been attached to the PC.
  34. The camera's Attach() method must not be called from here or from subsequent calls to avoid infinite recursion.
  35. \param[in] camera The source of the call.
  36. \error
  37. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  38. \threading
  39. This method is called inside the lock of the camera object.
  40. */
  41. virtual void OnAttach( CBaslerUniversalInstantCamera& camera )
  42. {
  43. PYLON_UNUSED( &camera );
  44. }
  45. /**
  46. \brief This method is called after a %Pylon Device (Pylon::IPylonDevice) has been attached by calling the Instant Camera object's Attach() method.
  47. This method can not be used for detecting that a camera device has been attached to the PC.
  48. The camera's Attach() method must not be called from here or from subsequent calls to avoid infinite recursion.
  49. \param[in] camera The source of the call.
  50. \error
  51. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  52. \threading
  53. This method is called inside the lock of the camera object.
  54. */
  55. virtual void OnAttached( CBaslerUniversalInstantCamera& camera )
  56. {
  57. PYLON_UNUSED( &camera );
  58. }
  59. /**
  60. \brief This method is called before the attached %Pylon Device is detached from the Instant Camera object.
  61. The camera's Detach() method must not be called from here or from subsequent calls to avoid infinite recursion.
  62. \param[in] camera The source of the call.
  63. \error
  64. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  65. \threading
  66. This method is called inside the lock of the camera object.
  67. */
  68. virtual void OnDetach( CBaslerUniversalInstantCamera& camera )
  69. {
  70. PYLON_UNUSED( &camera );
  71. }
  72. /**
  73. \brief This method is called after the attached %Pylon Device has been detached from the Instant Camera object.
  74. \param[in] camera The source of the call.
  75. \error
  76. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  77. \threading
  78. This method is called inside the lock of the camera object.
  79. */
  80. virtual void OnDetached( CBaslerUniversalInstantCamera& camera )
  81. {
  82. PYLON_UNUSED( &camera );
  83. }
  84. /**
  85. \brief This method is called before the attached %Pylon Device is destroyed.
  86. Camera DestroyDevice must not be called from here or from subsequent calls to avoid infinite recursion.
  87. \param[in] camera The source of the call.
  88. \error
  89. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  90. \threading
  91. This method is called inside the lock of the camera object.
  92. */
  93. virtual void OnDestroy( CBaslerUniversalInstantCamera& camera )
  94. {
  95. PYLON_UNUSED( &camera );
  96. }
  97. /**
  98. \brief This method is called after the attached %Pylon Device has been destroyed.
  99. \param[in] camera The source of the call.
  100. \error
  101. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  102. \threading
  103. This method is called inside the lock of the camera object.
  104. */
  105. virtual void OnDestroyed( CBaslerUniversalInstantCamera& camera )
  106. {
  107. PYLON_UNUSED( &camera );
  108. }
  109. /**
  110. \brief This method is called before the attached %Pylon Device is opened.
  111. \param[in] camera The source of the call.
  112. \error
  113. Exceptions from this call will propagate through. The notification of event handlers stops when an exception is triggered.
  114. \threading
  115. This method is called inside the lock of the camera object.
  116. */
  117. virtual void OnOpen( CBaslerUniversalInstantCamera& camera )
  118. {
  119. PYLON_UNUSED( &camera );
  120. }
  121. /**
  122. \brief This method is called after the attached %Pylon Device has been opened.
  123. \param[in] camera The source of the call.
  124. \error
  125. Exceptions from this call will propagate through. The notification of event handlers stops when an exception is triggered.
  126. \threading
  127. This method is called inside the lock of the camera object.
  128. */
  129. virtual void OnOpened( CBaslerUniversalInstantCamera& camera )
  130. {
  131. PYLON_UNUSED( &camera );
  132. }
  133. /**
  134. \brief This method is called before the attached %Pylon Device is closed.
  135. Camera Close must not be called from here or from subsequent calls to avoid infinite recursion.
  136. \param[in] camera The source of the call.
  137. \error
  138. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  139. \threading
  140. This method is called inside the lock of the camera object.
  141. */
  142. virtual void OnClose( CBaslerUniversalInstantCamera& camera )
  143. {
  144. PYLON_UNUSED( &camera );
  145. }
  146. /**
  147. \brief This method is called after the attached %Pylon Device has been closed.
  148. \param[in] camera The source of the call.
  149. \error
  150. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  151. \threading
  152. This method is called inside the lock of the camera object.
  153. */
  154. virtual void OnClosed( CBaslerUniversalInstantCamera& camera )
  155. {
  156. PYLON_UNUSED( &camera );
  157. }
  158. /**
  159. \brief This method is called before a grab session is started.
  160. Camera StartGrabbing must not be called from here or from subsequent calls to avoid infinite recursion.
  161. \param[in] camera The source of the call.
  162. \error
  163. Exceptions from this call will propagate through. The notification of event handlers stops when an exception is triggered.
  164. \threading
  165. This method is called inside the lock of the camera object.
  166. */
  167. virtual void OnGrabStart( CBaslerUniversalInstantCamera& camera )
  168. {
  169. PYLON_UNUSED( &camera );
  170. }
  171. /**
  172. \brief This method is called after a grab session has been started.
  173. \param[in] camera The source of the call.
  174. \error
  175. Exceptions from this call will propagate through. The notification of event handlers stops when an exception is triggered.
  176. \threading
  177. This method is called inside the lock of the camera object.
  178. */
  179. virtual void OnGrabStarted( CBaslerUniversalInstantCamera& camera )
  180. {
  181. PYLON_UNUSED( &camera );
  182. }
  183. /**
  184. \brief This method is called before a grab session is stopped.
  185. Camera StopGrabbing must not be called from here or from subsequent calls to avoid infinite recursion.
  186. \param[in] camera The source of the call.
  187. \error
  188. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  189. \threading
  190. This method is called inside the lock of the camera object.
  191. */
  192. virtual void OnGrabStop( CBaslerUniversalInstantCamera& camera )
  193. {
  194. PYLON_UNUSED( &camera );
  195. }
  196. /**
  197. \brief This method is called after a grab session has been stopped.
  198. \param[in] camera The source of the call.
  199. \error
  200. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  201. \threading
  202. This method is called inside the lock of the camera object.
  203. */
  204. virtual void OnGrabStopped( CBaslerUniversalInstantCamera& camera )
  205. {
  206. PYLON_UNUSED( &camera );
  207. }
  208. /**
  209. \brief This method is called when an exception has been triggered during grabbing.
  210. An exception has been triggered by a grab thread. The grab will be stopped after this event call.
  211. \param[in] camera The source of the call.
  212. \param[in] errorMessage The message of the exception that signaled an error during grabbing.
  213. \error
  214. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  215. \threading
  216. This method is called inside the lock of the camera object.
  217. */
  218. virtual void OnGrabError( CBaslerUniversalInstantCamera& camera, const char* errorMessage )
  219. {
  220. PYLON_UNUSED( &camera );
  221. PYLON_UNUSED( errorMessage );
  222. }
  223. /**
  224. \brief This method is called when a camera device removal from the PC has been detected.
  225. The %Pylon Device attached to the Instant Camera is not operable after this event.
  226. After it is made sure that no access to the %Pylon Device or any of its node maps is made anymore
  227. the %Pylon Device should be destroyed using InstantCamera::DeviceDestroy().
  228. The access to the %Pylon Device can be protected using the lock provided by GetLock(), e.g. when accessing parameters.
  229. \param[in] camera The source of the call.
  230. \error
  231. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  232. \threading
  233. This method is called inside the lock of the camera object from an additional thread.
  234. */
  235. virtual void OnCameraDeviceRemoved( CBaslerUniversalInstantCamera& camera )
  236. {
  237. PYLON_UNUSED( &camera );
  238. }
  239. /**
  240. \brief This method is called when the configuration event handler has been registered.
  241. \param[in] camera The source of the call.
  242. \error
  243. Exceptions from this call will propagate through.
  244. \threading
  245. This method is called inside the lock of the camera object.
  246. */
  247. virtual void OnConfigurationRegistered( CBaslerUniversalInstantCamera& camera )
  248. {
  249. PYLON_UNUSED( &camera );
  250. }
  251. /**
  252. \brief This method is called when the configuration event handler has been deregistered.
  253. The configuration event handler is automatically deregistered when the Instant Camera object
  254. is destroyed.
  255. \param[in] camera The source of the call.
  256. \error
  257. C++ exceptions from this call will be caught and ignored.
  258. \threading
  259. This method is called inside the lock of the camera object.
  260. */
  261. virtual void OnConfigurationDeregistered( CBaslerUniversalInstantCamera& camera )
  262. {
  263. PYLON_UNUSED( &camera );
  264. }
  265. /*!
  266. \brief Destroys the configuration event handler.
  267. \error
  268. C++ exceptions from this call will be caught and ignored.
  269. */
  270. virtual void DestroyConfiguration()
  271. {
  272. //If runtime errors occur here during delete, check the following:
  273. //Check that the cleanup procedure is correctly set when registering.
  274. //Ensure that the registered object has been allocated on the heap using new.
  275. //Ensure that the registered object has not already been deleted.
  276. delete this;
  277. }
  278. /// Create.
  279. CBaslerUniversalConfigurationEventHandler()
  280. : m_eventHandlerRegistrationCount( 0 )
  281. {
  282. }
  283. /// Copy.
  284. CBaslerUniversalConfigurationEventHandler( const CBaslerUniversalConfigurationEventHandler& )
  285. : m_eventHandlerRegistrationCount( 0 )
  286. {
  287. }
  288. /// Assign.
  289. CBaslerUniversalConfigurationEventHandler& operator=( const CBaslerUniversalConfigurationEventHandler& )
  290. {
  291. return *this;
  292. }
  293. /// Destruct.
  294. virtual ~CBaslerUniversalConfigurationEventHandler()
  295. {
  296. PYLON_ASSERT2( DebugGetEventHandlerRegistrationCount() == 0, "Error: The event handler must not be destroyed while it is registered." );
  297. }
  298. // Internal use only. Subject to change without notice.
  299. const long& DebugGetEventHandlerRegistrationCount()
  300. {
  301. return m_eventHandlerRegistrationCount;
  302. }
  303. private:
  304. long m_eventHandlerRegistrationCount; // Counts how many times the event handler is registered.
  305. };
  306. /**
  307. * @}
  308. */
  309. }
  310. #ifdef _MSC_VER
  311. # pragma pack(pop)
  312. #endif /* _MSC_VER */
  313. #endif /* INCLUDED_BASLERUNIVERSALCONFIGURATIONEVENTHANDLERH */