BufferFactory.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 interface for a buffer factory.
  10. */
  11. #ifndef INCLUDED_BUFFERFACTORY_H_264599
  12. #define INCLUDED_BUFFERFACTORY_H_264599
  13. #include <pylon/stdinclude.h>
  14. #ifdef _MSC_VER
  15. # pragma pack(push, PYLON_PACKING)
  16. #endif /* _MSC_VER */
  17. namespace Pylon
  18. {
  19. /*!
  20. \class IBufferFactory
  21. \brief Usable to create a custom buffer factory when needed.
  22. \ingroup Pylon_InstantCameraApiGeneric
  23. */
  24. interface IBufferFactory
  25. {
  26. public:
  27. /// Ensure proper destruction by using a virtual destructor.
  28. virtual ~IBufferFactory() = 0;
  29. /*!
  30. \brief Allocates a buffer and provides additional context information.
  31. \param[in] bufferSize The size of the buffer that has to be allocated.
  32. \param[out] pCreatedBuffer Return the pointer to the allocated buffer. May return NULL if the allocation fails.
  33. \param[out] bufferContext Context information that belongs to the buffer.
  34. This context information is provided when FreeBuffer() is called.
  35. The value can be left unchanged if not needed.
  36. \threading
  37. This method can be run by different threads. It is called from threads that
  38. call Pylon::CInstantCamera::StartGrabbing() and it can be called by the internal
  39. grab engine thread.
  40. \error
  41. May throw an exception if the allocation fails.
  42. */
  43. virtual void AllocateBuffer( size_t bufferSize, void** pCreatedBuffer, intptr_t& bufferContext ) = 0;
  44. /*!
  45. \brief Frees a previously allocated buffer.
  46. \param[in] pCreatedBuffer The pointer to the allocated buffer. Created by this factory.
  47. \param[in] bufferContext Context information of the buffer returned by AllocateBuffer().
  48. \error
  49. Does not throw C++ exceptions.
  50. */
  51. virtual void FreeBuffer( void* pCreatedBuffer, intptr_t bufferContext ) = 0;
  52. /*!
  53. \brief Destroys the buffer factory.
  54. This method is called when the buffer factory is not needed any longer.
  55. The object implementing IBufferFactory can be deleted by calling: delete this.
  56. \threading
  57. This method can be run by different threads. It is called from threads that are running the
  58. destructor of a Pylon::CGrabResultPtr or call Pylon::CInstantCamera::StopGrabbing().
  59. \error
  60. C++ exceptions from this call will be caught and ignored.
  61. */
  62. virtual void DestroyBufferFactory() = 0;
  63. };
  64. // Implementation required for Windows only.
  65. // Note: the C++ standards >= C11 prohibit pure virtual destructors with a function body
  66. // in the declaration. Consequently GCC 4.0 and newer GCC versions reject an inline implementation
  67. // in the class.
  68. inline IBufferFactory::~IBufferFactory()
  69. {
  70. }
  71. }
  72. #ifdef _MSC_VER
  73. # pragma pack(pop)
  74. #endif /* _MSC_VER */
  75. #endif /* INCLUDED_BUFFERFACTORY_H_264599 */