StructPort.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2009 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 
31 #ifndef __STRUCTPORT_H
32 #define __STRUCTPORT_H
33 
34 #include <cstring>
35 #include <string.h>
36 #include <GenApi/PortImpl.h>
37 
38 namespace GENAPI_NAMESPACE
39 {
41  template <class CDataStruct>
42  class CTestPortStruct : public CDataStruct, public GENAPI_NAMESPACE::CPortImpl
43  {
44  public:
45  CTestPortStruct(int64_t BaseAddress = 0)
46  : m_BaseAddress(BaseAddress)
47  {
48  MemSet(0);
50  }
51 
52  //-------------------------------------------------------------
53  // IBase implementation
54  //-------------------------------------------------------------
55 
58  {
59  return RW;
60  }
61 
64  {
65  return intfIPort;
66  }
67 
68  //---------------------------------------------------------------
69  // IPort implementation
70  //---------------------------------------------------------------
71 
73  virtual void Read(void *pBuffer, int64_t Address, int64_t Length)
74  {
75  int64_t InternalAddress = Address - m_BaseAddress;
76 
77  CDataStruct *pDataStruct = static_cast<CDataStruct*>(this);
78  if( InternalAddress < 0 || Length < 0 || InternalAddress + Length > sizeof(CDataStruct) )
79  throw RUNTIME_EXCEPTION("CTestPortStruct::Read - Invalid address and/or length");
80  memcpy( pBuffer, (uint8_t*)pDataStruct + InternalAddress, (size_t)Length );
81  m_NumReads++;
82  }
83 
85  virtual void Write(const void *pBuffer, int64_t Address, int64_t Length)
86  {
87  int64_t InternalAddress = Address - m_BaseAddress;
88 
89  CDataStruct *pDataStruct = static_cast<CDataStruct*>(this);
90  if( InternalAddress < 0 || Length < 0 || InternalAddress + Length > sizeof(CDataStruct) )
91  throw RUNTIME_EXCEPTION("CTestPortStruct::Write - Invalid address and/or length");
92  memcpy( (uint8_t*)pDataStruct + InternalAddress, pBuffer, (size_t)Length );
93  m_NumWrites++;
94  }
95 
96  //-------------------------------------------------------------
97  // Utility functions
98  //-------------------------------------------------------------
99 
100  void MemSet( const char FillValue )
101  {
102  memset( static_cast<CDataStruct*>(this), FillValue, sizeof(CDataStruct) );
103  }
104 
105  //-------------------------------------------------------------
106  // Statistics functions
107  //-------------------------------------------------------------
108 
111  {
112  m_NumReads = 0;
113  m_NumWrites = 0;
114  }
115 
118  {
119  return m_NumReads;
120  }
121 
124  {
125  return m_NumWrites;
126  }
127 
128  protected:
131 
134 
137  };
138 }
139 
140 #endif // __STRUCTPORT_H
CTestPortStruct(int64_t BaseAddress=0)
Definition: StructPort.h:45
int64_t GetNumReads()
Returns the number of reads since lastReset Statistics.
Definition: StructPort.h:117
IPort interface.
Definition: Types.h:202
int64_t m_NumWrites
Number of writes since last reset.
Definition: StructPort.h:133
void ResetStatistics()
Resets the read/write statistics.
Definition: StructPort.h:110
__int64 int64_t
Definition: config-win32.h:21
void MemSet(const char FillValue)
Definition: StructPort.h:100
Implements a register spaces based on a C++ struct.
Definition: StructPort.h:42
#define RUNTIME_EXCEPTION
Fires a runtime exception, e.g. throw RUNTIME_EXCEPTION("buh!")
Definition: GCException.h:246
Definition of CPortImpl.
virtual void Read(void *pBuffer, int64_t Address, int64_t Length)
Reads a chunk of bytes from the port.
Definition: StructPort.h:73
virtual void Write(const void *pBuffer, int64_t Address, int64_t Length)
Writes a chunk of bytes to the port.
Definition: StructPort.h:85
interface GENAPI_DECL_ABSTRACT int64_t Address
Definition: IPort.h:57
int64_t m_BaseAddress
the base address used for the struct
Definition: StructPort.h:136
interface GENAPI_DECL_ABSTRACT int64_t int64_t Length
Definition: IPort.h:57
virtual GENAPI_NAMESPACE::EAccessMode GetAccessMode() const
Get the access mode of the node.
Definition: StructPort.h:57
enum GENAPI_NAMESPACE::_EAccessMode EAccessMode
access mode of a node
virtual GENAPI_NAMESPACE::EInterfaceType GetPrincipalInterfaceType() const
Get the type of the main interface of a node.
Definition: StructPort.h:63
Standard implementation for a port !
Definition: PortImpl.h:58
Read and Write.
Definition: Types.h:60
int64_t m_NumReads
Number of reads since last reset.
Definition: StructPort.h:130
int64_t GetNumWrites()
Returns the number of writes since lastReset Statistics.
Definition: StructPort.h:123
Part of the generic device API.
Definition: Autovector.h:48
enum GENAPI_NAMESPACE::_EInterfaceType EInterfaceType
typedef for interface type


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Thu Jun 6 2019 19:10:54