BaslerUsbCameraEventHandler.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 camera event handler base class.
  10. */
  11. #ifndef INCLUDED_BASLERUSBCAMERAEVENTHANDLER_H_3102315
  12. #define INCLUDED_BASLERUSBCAMERAEVENTHANDLER_H_3102315
  13. #include <pylon/stdinclude.h>
  14. #ifdef _MSC_VER
  15. # pragma pack(push, PYLON_PACKING)
  16. #endif /* _MSC_VER */
  17. #include <GenApi/INode.h>
  18. #if _MSC_VER
  19. # pragma warning( push)
  20. # pragma warning( disable : 4100) //warning C4100: 'identifier' : unreferenced formal parameter
  21. #endif
  22. namespace Pylon
  23. {
  24. class CBaslerUsbInstantCamera;
  25. /** \addtogroup Pylon_InstantCameraApiUsb
  26. * @{
  27. */
  28. /**
  29. \class CBaslerUsbCameraEventHandler
  30. \brief The camera event handler base class.
  31. */
  32. class CBaslerUsbCameraEventHandler
  33. {
  34. public:
  35. /**
  36. \brief This method is called when a camera event has been received.
  37. Only very short processing tasks should be performed by this method. Otherwise, the event notification will block the
  38. processing of images.
  39. \param[in] camera The source of the call.
  40. \param[in] userProvidedId The ID passed when registering for the event. It can be used to distinguish between different events.
  41. \param[in] pNode The node identified by node name when registering.
  42. \error
  43. C++ exceptions from this call will be caught and ignored. All event handlers are notified.
  44. \threading
  45. This method is called outside the lock of the camera object, outside the lock of the node map, and inside the lock of the camera event handler registry.
  46. */
  47. virtual void OnCameraEvent( CBaslerUsbInstantCamera& camera, intptr_t userProvidedId, GenApi::INode* pNode )
  48. {
  49. }
  50. /**
  51. \brief This method is called when the camera event handler has been registered.
  52. \param[in] camera The source of the call.
  53. \param[in] nodeName The name of the event data node updated on camera event, e.g. "ExposureEndEventTimestamp" for exposure end event.
  54. \param[in] userProvidedId This ID is passed as a parameter in CBaslerUsbCameraEventHandler::OnCameraEvent and can be used to distinguish between different events.
  55. \error
  56. Exceptions from this call will propagate through.
  57. \threading
  58. This method is called inside the lock of the camera event handler registry.
  59. */
  60. virtual void OnCameraEventHandlerRegistered( CBaslerUsbInstantCamera& camera, const String_t& nodeName, intptr_t userProvidedId )
  61. {
  62. }
  63. /**
  64. \brief This method is called when the camera event handler has been deregistered.
  65. The camera event handler is automatically deregistered when the Instant Camera object
  66. is destroyed.
  67. \param[in] camera The source of the call.
  68. \param[in] nodeName The name of the event data node updated on camera event, e.g. "ExposureEndEventTimestamp" for exposure end event.
  69. \param[in] userProvidedId This ID is passed as a parameter in CBaslerUsbCameraEventHandler::OnCameraEvent and can be used to distinguish between different events.
  70. \error
  71. C++ exceptions from this call will be caught and ignored.
  72. \threading
  73. This method is called inside the lock of the camera event handler registry.
  74. */
  75. virtual void OnCameraEventHandlerDeregistered( CBaslerUsbInstantCamera& camera, const String_t& nodeName, intptr_t userProvidedId )
  76. {
  77. }
  78. /*!
  79. \brief Destroys the camera event handler.
  80. \error
  81. C++ exceptions from this call will be caught and ignored.
  82. */
  83. virtual void DestroyCameraEventHandler()
  84. {
  85. //If runtime errors occur here during delete, check the following:
  86. //Check that the cleanup procedure is correctly set when registering.
  87. //Ensure that the registered object has been allocated on the heap using new.
  88. //Ensure that the registered object has not already been deleted.
  89. delete this;
  90. }
  91. /// Create.
  92. CBaslerUsbCameraEventHandler()
  93. : m_eventHandlerRegistrationCount( 0 )
  94. {
  95. }
  96. /// Copy.
  97. CBaslerUsbCameraEventHandler( const CBaslerUsbCameraEventHandler& )
  98. : m_eventHandlerRegistrationCount( 0 )
  99. {
  100. }
  101. /// Assign.
  102. CBaslerUsbCameraEventHandler& operator=( const CBaslerUsbCameraEventHandler& )
  103. {
  104. return *this;
  105. }
  106. /// Destruct.
  107. virtual ~CBaslerUsbCameraEventHandler()
  108. {
  109. PYLON_ASSERT2( DebugGetEventHandlerRegistrationCount() == 0, "Error: The event handler must not be destroyed while it is registered." );
  110. }
  111. // Internal use only. Subject to change without notice.
  112. const long& DebugGetEventHandlerRegistrationCount()
  113. {
  114. return m_eventHandlerRegistrationCount;
  115. }
  116. private:
  117. long m_eventHandlerRegistrationCount; // Counts how many times the event handler is registered.
  118. };
  119. /**
  120. * @}
  121. */
  122. }
  123. #if _MSC_VER
  124. # pragma warning( pop)
  125. #endif
  126. #ifdef _MSC_VER
  127. # pragma pack(pop)
  128. #endif /* _MSC_VER */
  129. #endif /* INCLUDED_BASLERUSBCAMERAEVENTHANDLER_H_3102315 */