DeviceSpecificImageEventHandlerTie.h 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 an adapter class for device specific image event handlers.
  10. */
  11. #ifndef INCLUDED_DEVICESPECIFICIMAGEEVENTHANDLERTIE_H_009136379
  12. #define INCLUDED_DEVICESPECIFICIMAGEEVENTHANDLERTIE_H_009136379
  13. #include <pylon/ImageEventHandler.h>
  14. #include <pylon/stdinclude.h>
  15. namespace Pylon
  16. {
  17. /*!
  18. \class CDeviceSpecificImageEventHandlerTie
  19. \brief Implementation Detail: Adapter for device specific image event handlers.
  20. */
  21. template <typename DeviceSpecificCameraT, typename InterfaceT>
  22. class CDeviceSpecificImageEventHandlerTie : public CImageEventHandler
  23. {
  24. public:
  25. CDeviceSpecificImageEventHandlerTie( InterfaceT* ptr, bool isCleanupDelete )
  26. : m_ptr( ptr )
  27. , m_isCleanupDelete( isCleanupDelete )
  28. {
  29. }
  30. ~CDeviceSpecificImageEventHandlerTie()
  31. {
  32. }
  33. virtual void OnImagesSkipped( CInstantCamera& camera, size_t countOfSkippedImages )
  34. {
  35. PYLON_ASSERT2( dynamic_cast<DeviceSpecificCameraT*>(&camera) != NULL, "Unexpected camera type passed." );
  36. m_ptr->OnImagesSkipped( static_cast<DeviceSpecificCameraT&>(camera), countOfSkippedImages );
  37. }
  38. virtual void OnImageGrabbed( CInstantCamera& camera, const CGrabResultPtr& grabResult )
  39. {
  40. PYLON_ASSERT2( dynamic_cast<DeviceSpecificCameraT*>(&camera) != NULL, "Unexpected camera type passed." );
  41. typename DeviceSpecificCameraT::GrabResultPtr_t grabResultLocal = grabResult;
  42. PYLON_ASSERT2( grabResultLocal.IsValid(), "Unexpected condition that result is not convertible." );
  43. m_ptr->OnImageGrabbed( static_cast<DeviceSpecificCameraT&>(camera), grabResultLocal );
  44. }
  45. virtual void OnImageEventHandlerRegistered( CInstantCamera& camera )
  46. {
  47. PYLON_ASSERT2( dynamic_cast<DeviceSpecificCameraT*>(&camera) != NULL, "Unexpected camera type passed." );
  48. m_ptr->OnImageEventHandlerRegistered( static_cast<DeviceSpecificCameraT&>(camera) );
  49. }
  50. virtual void OnImageEventHandlerDeregistered( CInstantCamera& camera )
  51. {
  52. PYLON_ASSERT2( dynamic_cast<DeviceSpecificCameraT*>(&camera) != NULL, "Unexpected camera type passed." );
  53. m_ptr->OnImageEventHandlerDeregistered( static_cast<DeviceSpecificCameraT&>(camera) );
  54. }
  55. virtual void DestroyImageEventHandler()
  56. {
  57. try
  58. {
  59. // destroy only when demanded
  60. if (m_isCleanupDelete)
  61. {
  62. m_ptr->DestroyImageEventHandler();
  63. }
  64. m_ptr = NULL;
  65. }
  66. catch (...)
  67. {
  68. delete this;
  69. m_ptr = NULL;
  70. throw;
  71. }
  72. delete this;
  73. }
  74. private:
  75. InterfaceT* m_ptr;
  76. bool m_isCleanupDelete;
  77. };
  78. }
  79. #endif /* INCLUDED_DEVICESPECIFICIMAGEEVENTHANDLERTIE_H_009136379 */