ConfigurationEventHandler.h 13 KB

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