BaslerUniversalImageEventHandler.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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 image event handler base class.
  10. */
  11. #ifndef INCLUDED_BASLERUNIVERSALIMAGEEVENTHANDLER_H
  12. #define INCLUDED_BASLERUNIVERSALIMAGEEVENTHANDLER_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 <pylon/BaslerUniversalGrabResultPtr.h>
  19. namespace Pylon
  20. {
  21. class CBaslerUniversalInstantCamera;
  22. /** \addtogroup Pylon_InstantCameraApiUniversal
  23. * @{
  24. */
  25. /**
  26. \class CBaslerUniversalImageEventHandler
  27. \brief The image event handler base class.
  28. */
  29. class CBaslerUniversalImageEventHandler
  30. {
  31. public:
  32. /**
  33. \brief This method is called when images have been skipped using the GrabStrategy_LatestImageOnly strategy or the GrabStrategy_LatestImages strategy.
  34. \param[in] camera The source of the call.
  35. \param[in] countOfSkippedImages The number of images skipped. This \c countOfSkippedImages does not include the number of images lost in the case of a buffer under run in the driver.
  36. \error
  37. Exceptions from this call will propagate through. The notification of event handlers stops when an exception is triggered.
  38. \threading
  39. This method is called outside the lock of the camera object but inside the lock of the image event handler registry.
  40. */
  41. virtual void OnImagesSkipped( CBaslerUniversalInstantCamera& camera, size_t countOfSkippedImages )
  42. {
  43. PYLON_UNUSED( &camera );
  44. PYLON_UNUSED( countOfSkippedImages );
  45. }
  46. /**
  47. \brief This method is called when an image has been grabbed.
  48. The grab result smart pointer passed does always reference a grab result data object.
  49. The status of the grab needs to be checked before accessing the grab result data.
  50. See CGrabResultData::GrabSucceeded(), CGrabResultData::GetErrorCode() and
  51. CGrabResultData::GetErrorDescription() for more information.
  52. \param[in] camera The source of the call.
  53. \param[in] grabResult The grab result data.
  54. \error
  55. Exceptions from this call will propagate through. The notification of event handlers stops when an exception is triggered.
  56. \threading
  57. This method is called outside the lock of the camera object but inside the lock of the image event handler registry.
  58. */
  59. virtual void OnImageGrabbed( CBaslerUniversalInstantCamera& camera, const CBaslerUniversalGrabResultPtr& grabResult )
  60. {
  61. PYLON_UNUSED( &camera );
  62. PYLON_UNUSED( grabResult );
  63. }
  64. /**
  65. \brief This method is called when the image event handler has been registered.
  66. \param[in] camera The source of the call.
  67. \error
  68. Exceptions from this call will propagate through.
  69. \threading
  70. This method is called inside the lock of the image event handler registry.
  71. */
  72. virtual void OnImageEventHandlerRegistered( CBaslerUniversalInstantCamera& camera )
  73. {
  74. PYLON_UNUSED( &camera );
  75. }
  76. /**
  77. \brief This method is called when the image event handler has been deregistered.
  78. The image event handler is automatically deregistered when the Instant Camera object
  79. is destroyed.
  80. \param[in] camera The source of the call.
  81. \error
  82. C++ exceptions from this call will be caught and ignored.
  83. \threading
  84. This method is called inside the lock of the image event handler registry.
  85. */
  86. virtual void OnImageEventHandlerDeregistered( CBaslerUniversalInstantCamera& camera )
  87. {
  88. PYLON_UNUSED( &camera );
  89. }
  90. /*!
  91. \brief Destroys the image event handler.
  92. \error
  93. C++ exceptions from this call will be caught and ignored.
  94. */
  95. virtual void DestroyImageEventHandler()
  96. {
  97. //If runtime errors occur here during delete, check the following:
  98. //Check that the cleanup procedure is correctly set when registering.
  99. //Ensure that the registered object has been allocated on the heap using new.
  100. //Ensure that the registered object has not already been deleted.
  101. delete this;
  102. }
  103. /// Create.
  104. CBaslerUniversalImageEventHandler()
  105. : m_eventHandlerRegistrationCount( 0 )
  106. {
  107. }
  108. /// Copy.
  109. CBaslerUniversalImageEventHandler( const CBaslerUniversalImageEventHandler& )
  110. : m_eventHandlerRegistrationCount( 0 )
  111. {
  112. }
  113. /// Assign.
  114. CBaslerUniversalImageEventHandler& operator=( const CBaslerUniversalImageEventHandler& )
  115. {
  116. return *this;
  117. }
  118. /// Destruct.
  119. virtual ~CBaslerUniversalImageEventHandler()
  120. {
  121. PYLON_ASSERT2( DebugGetEventHandlerRegistrationCount() == 0, "Error: The event handler must not be destroyed while it is registered." );
  122. }
  123. // Internal use only. Subject to change without notice.
  124. const long& DebugGetEventHandlerRegistrationCount()
  125. {
  126. return m_eventHandlerRegistrationCount;
  127. }
  128. private:
  129. long m_eventHandlerRegistrationCount; // Counts how many times the event handler is registered.
  130. };
  131. /**
  132. * @}
  133. */
  134. }
  135. #ifdef _MSC_VER
  136. # pragma pack(pop)
  137. #endif /* _MSC_VER */
  138. #endif /* INCLUDED_BASLERUNIVERSALIMAGEEVENTHANDLER_H */