BaslerUsbImageEventHandler.h 5.5 KB

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