ChunkPort.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. //-----------------------------------------------------------------------------
  2. // (c) 2006-8 by Basler Vision Technologies
  3. // Section: Vision Components
  4. // Project: GenApi
  5. // Author: Fritz Dierks
  6. // $Header$
  7. //
  8. // License: This file is published under the license of the EMVA GenICam Standard Group.
  9. // A text file describing the legal terms is included in your installation as 'GenICam_license.pdf'.
  10. // If for some reason you are missing this file please contact the EMVA or visit the website
  11. // (http://www.genicam.org) for a full copy.
  12. //
  13. // THIS SOFTWARE IS PROVIDED BY THE EMVA GENICAM STANDARD GROUP "AS IS"
  14. // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  15. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  16. // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE EMVA GENICAM STANDARD GROUP
  17. // OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  18. // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  19. // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  20. // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  21. // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  22. // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  23. // POSSIBILITY OF SUCH DAMAGE.
  24. //-----------------------------------------------------------------------------
  25. /**
  26. \file
  27. \brief Declaration of the CChunkPort class.
  28. \ingroup GenApi_PublicUtilities
  29. */
  30. #ifndef GENAPI_CHUNKPORT_H
  31. #define GENAPI_CHUNKPORT_H
  32. #include <GenApi/Pointer.h>
  33. #include <GenApi/IPortConstruct.h>
  34. #include <GenApi/INodeMap.h>
  35. #pragma warning(push)
  36. #pragma warning(disable: 4251) // GenApi::CChunkPort::m_ptrPort' : class 'GenApi::CPointer<T>' needs to have dll-interface
  37. namespace GENAPI_NAMESPACE
  38. {
  39. /**
  40. \brief Port attachable to a chunk in a buffer
  41. \ingroup GenApi_PublicUtilities
  42. */
  43. class GENAPI_DECL CChunkPort : public IPortConstruct
  44. {
  45. public:
  46. //! Constructor; can attach to a port
  47. CChunkPort(IPort* pPort = NULL);
  48. //! Destructor; detaches from the port
  49. virtual ~CChunkPort();
  50. //-------------------------------------------------------------
  51. // IPortConstruct implementation
  52. //-------------------------------------------------------------
  53. //! Get the access mode of the node
  54. virtual EAccessMode GetAccessMode() const;
  55. //! Get the type of the main interface of a node
  56. virtual EInterfaceType GetPrincipalInterfaceType() const;
  57. //! Reads a chunk of bytes from the port
  58. virtual void Read(void *pBuffer, int64_t Address, int64_t Length);
  59. //! Writes a chunk of bytes to the port
  60. virtual void Write(const void *pBuffer, int64_t Address, int64_t Length);
  61. //! Called from the port node to give the chunk port a pointer to itself
  62. virtual void SetPortImpl(GENAPI_NAMESPACE::IPort* pPort);
  63. //! Determines if the port adapter must perform an endianess swap
  64. virtual EYesNo GetSwapEndianess()
  65. {
  66. return No;
  67. }
  68. //---------------------------------------------------------------
  69. // Implementation
  70. //---------------------------------------------------------------
  71. // Invalidates the chunk port node
  72. void InvalidateNode();
  73. //-------------------------------------------------------------
  74. // Initializing
  75. //-------------------------------------------------------------
  76. //! Attaches the ChunkPort to the Port
  77. bool AttachPort(GENAPI_NAMESPACE::IPort* pPort);
  78. //! Detaches the ChunkPort to the Port
  79. void DetachPort();
  80. //! Attaches the Chunk to the ChunkPort
  81. void AttachChunk(uint8_t *pBaseAddress, int64_t ChunkOffset, int64_t Length, bool Cache);
  82. //! Detaches the Chunk from the ChunkPort
  83. void DetachChunk();
  84. //! Gets the ChunkID length
  85. int GetChunkIDLength()
  86. {
  87. return m_ChunkIDLength;
  88. }
  89. //! Checks if a ChunkID matches
  90. bool CheckChunkID(uint8_t* pChunkIDBuffer, int ChunkIDLength);
  91. //! Checks if a ChunkID matches, version using uint64_t ID representation
  92. bool CheckChunkID(uint64_t ChunkID);
  93. //! Updates the base address of the chunk
  94. void UpdateBuffer(uint8_t *pBaseAddress);
  95. //! Clears the chunk cache
  96. void ClearCache();
  97. protected:
  98. CLock& GetLock() const
  99. {
  100. if (!m_ptrPort.IsValid())
  101. throw RUNTIME_EXCEPTION("The event port is not attached to a node");
  102. return m_ptrPort->GetNodeMap()->GetLock();
  103. }
  104. //-------------------------------------------------------------
  105. // Member variables
  106. //-------------------------------------------------------------
  107. //! Pointer to the begin of the buffer
  108. uint8_t *m_pBaseAddress;
  109. //! The chunk's offset within the buffer
  110. int64_t m_ChunkOffset;
  111. //! Length of the chunk
  112. int64_t m_Length;
  113. //! Space allocated for the chunk
  114. int64_t m_LengthAlloc;
  115. //! Pointer to the node holding a reference to this implementation
  116. CNodePtr m_ptrPort;
  117. //! Binary version of the chunk ID
  118. uint8_t *m_pChunkIDBuffer;
  119. //! Length of the chunk ID buffer
  120. int m_ChunkIDLength;
  121. //! cache for the chunk data
  122. uint8_t *m_pChunkData;
  123. //! indicates if the data needs to be cached
  124. bool m_CacheData;
  125. //! Chunk ID stored as a number (for more straightforward access)
  126. uint64_t m_ChunkIDNumber;
  127. //! indicates if the m_ChunkIDNumber is valid (could be invalid eg. if the ID does not fit in 64-bit range)
  128. bool m_ChunkIDNumberValid;
  129. };
  130. }
  131. #pragma warning(pop)
  132. #endif // GENAPI_CHUNKPORT_H