Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00031 #ifndef __STRUCTPORT_H
00032 #define __STRUCTPORT_H
00033
00034 #include <cstring>
00035 #include <string.h>
00036 #include <GenApi/PortImpl.h>
00037
00038 namespace GENAPI_NAMESPACE
00039 {
00041 template <class CDataStruct>
00042 class CTestPortStruct : public CDataStruct, public GENAPI_NAMESPACE::CPortImpl
00043 {
00044 public:
00045 CTestPortStruct(int64_t BaseAddress = 0)
00046 : m_BaseAddress(BaseAddress)
00047 {
00048 MemSet(0);
00049 ResetStatistics();
00050 }
00051
00052
00053
00054
00055
00057 virtual GENAPI_NAMESPACE::EAccessMode GetAccessMode() const
00058 {
00059 return RW;
00060 }
00061
00063 virtual GENAPI_NAMESPACE::EInterfaceType GetPrincipalInterfaceType() const
00064 {
00065 return intfIPort;
00066 }
00067
00068
00069
00070
00071
00073 virtual void Read(void *pBuffer, int64_t Address, int64_t Length)
00074 {
00075 int64_t InternalAddress = Address - m_BaseAddress;
00076
00077 CDataStruct *pDataStruct = static_cast<CDataStruct*>(this);
00078 if( InternalAddress < 0 || Length < 0 || InternalAddress + Length > sizeof(CDataStruct) )
00079 throw RUNTIME_EXCEPTION("CTestPortStruct::Read - Invalid address and/or length");
00080 memcpy( pBuffer, (uint8_t*)pDataStruct + InternalAddress, (size_t)Length );
00081 m_NumReads++;
00082 }
00083
00085 virtual void Write(const void *pBuffer, int64_t Address, int64_t Length)
00086 {
00087 int64_t InternalAddress = Address - m_BaseAddress;
00088
00089 CDataStruct *pDataStruct = static_cast<CDataStruct*>(this);
00090 if( InternalAddress < 0 || Length < 0 || InternalAddress + Length > sizeof(CDataStruct) )
00091 throw RUNTIME_EXCEPTION("CTestPortStruct::Write - Invalid address and/or length");
00092 memcpy( (uint8_t*)pDataStruct + InternalAddress, pBuffer, (size_t)Length );
00093 m_NumWrites++;
00094 }
00095
00096
00097
00098
00099
00100 void MemSet( const char FillValue )
00101 {
00102 memset( static_cast<CDataStruct*>(this), FillValue, sizeof(CDataStruct) );
00103 }
00104
00105
00106
00107
00108
00110 void ResetStatistics()
00111 {
00112 m_NumReads = 0;
00113 m_NumWrites = 0;
00114 }
00115
00117 int64_t GetNumReads()
00118 {
00119 return m_NumReads;
00120 }
00121
00123 int64_t GetNumWrites()
00124 {
00125 return m_NumWrites;
00126 }
00127
00128 protected:
00130 int64_t m_NumReads;
00131
00133 int64_t m_NumWrites;
00134
00136 int64_t m_BaseAddress;
00137 };
00138 }
00139
00140 #endif // __STRUCTPORT_H