BaslerUniversalCameraEventHandler.h 5.7 KB

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