ChunkPort.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. #ifdef _MSC_VER
  36. # pragma warning(push)
  37. # pragma warning(disable: 4251) // GenApi::CChunkPort::m_ptrPort' : class 'GenApi::CPointer<T>' needs to have dll-interface
  38. #endif
  39. namespace GENAPI_NAMESPACE
  40. {
  41. /**
  42. \brief Port attachable to a chunk in a buffer
  43. \ingroup GenApi_PublicUtilities
  44. */
  45. class GENAPI_DECL CChunkPort : public IPortConstruct
  46. {
  47. public:
  48. //! Constructor; can attach to a port
  49. CChunkPort(IPort* pPort = NULL);
  50. //! Destructor; detaches from the port
  51. virtual ~CChunkPort();
  52. //-------------------------------------------------------------
  53. // IPortConstruct implementation
  54. //-------------------------------------------------------------
  55. //! Get the access mode of the node
  56. virtual EAccessMode GetAccessMode() const;
  57. //! Get the type of the main interface of a node
  58. virtual EInterfaceType GetPrincipalInterfaceType() const;
  59. //! Reads a chunk of bytes from the port
  60. virtual void Read(void *pBuffer, int64_t Address, int64_t Length);
  61. //! Writes a chunk of bytes to the port
  62. virtual void Write(const void *pBuffer, int64_t Address, int64_t Length);
  63. //! Called from the port node to give the chunk port a pointer to itself
  64. virtual void SetPortImpl(GENAPI_NAMESPACE::IPort* pPort);
  65. //! Determines if the port adapter must perform an endianess swap
  66. virtual EYesNo GetSwapEndianess()
  67. {
  68. return No;
  69. }
  70. //---------------------------------------------------------------
  71. // Implementation
  72. //---------------------------------------------------------------
  73. // Invalidates the chunk port node
  74. void InvalidateNode();
  75. //-------------------------------------------------------------
  76. // Initializing
  77. //-------------------------------------------------------------
  78. //! Attaches the ChunkPort to the Port
  79. bool AttachPort(GENAPI_NAMESPACE::IPort* pPort);
  80. //! Detaches the ChunkPort to the Port
  81. void DetachPort();
  82. //! Attaches the Chunk to the ChunkPort
  83. void AttachChunk(uint8_t *pBaseAddress, int64_t ChunkOffset, int64_t Length, bool Cache);
  84. //! Detaches the Chunk from the ChunkPort
  85. void DetachChunk();
  86. //! Gets the ChunkID length
  87. int GetChunkIDLength()
  88. {
  89. return m_ChunkIDLength;
  90. }
  91. //! Checks if a ChunkID matches
  92. bool CheckChunkID(uint8_t* pChunkIDBuffer, int ChunkIDLength);
  93. //! Checks if a ChunkID matches, version using uint64_t ID representation
  94. bool CheckChunkID(uint64_t ChunkID);
  95. //! Updates the base address of the chunk
  96. void UpdateBuffer(uint8_t *pBaseAddress);
  97. //! Clears the chunk cache
  98. void ClearCache();
  99. protected:
  100. CLock& GetLock() const
  101. {
  102. if (!m_ptrPort.IsValid())
  103. throw RUNTIME_EXCEPTION("The event port is not attached to a node");
  104. return m_ptrPort->GetNodeMap()->GetLock();
  105. }
  106. //-------------------------------------------------------------
  107. // Member variables
  108. //-------------------------------------------------------------
  109. //! Pointer to the begin of the buffer
  110. uint8_t *m_pBaseAddress;
  111. //! The chunk's offset within the buffer
  112. int64_t m_ChunkOffset;
  113. //! Length of the chunk
  114. int64_t m_Length;
  115. //! Space allocated for the chunk
  116. int64_t m_LengthAlloc;
  117. //! Pointer to the node holding a reference to this implementation
  118. CNodePtr m_ptrPort;
  119. //! Binary version of the chunk ID
  120. uint8_t *m_pChunkIDBuffer;
  121. //! Length of the chunk ID buffer
  122. int m_ChunkIDLength;
  123. //! cache for the chunk data
  124. uint8_t *m_pChunkData;
  125. //! indicates if the data needs to be cached
  126. bool m_CacheData;
  127. //! Chunk ID stored as a number (for more straightforward access)
  128. uint64_t m_ChunkIDNumber;
  129. //! indicates if the m_ChunkIDNumber is valid (could be invalid eg. if the ID does not fit in 64-bit range)
  130. bool m_ChunkIDNumberValid;
  131. };
  132. }
  133. #ifdef _MSC_VER
  134. # pragma warning(pop)
  135. #endif
  136. #endif // GENAPI_CHUNKPORT_H