BaslerUsbConfigurationEventHandler.h 13 KB

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