μHAL (v2.7.9)
Part of the IPbus software repository
Buffers.cpp
Go to the documentation of this file.
1 /*
2 ---------------------------------------------------------------------------
3 
4  This file is part of uHAL.
5 
6  uHAL is a hardware access library and programming framework
7  originally developed for upgrades of the Level-1 trigger of the CMS
8  experiment at CERN.
9 
10  uHAL is free software: you can redistribute it and/or modify
11  it under the terms of the GNU General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  uHAL is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU General Public License for more details.
19 
20  You should have received a copy of the GNU General Public License
21  along with uHAL. If not, see <http://www.gnu.org/licenses/>.
22 
23 
24  Andrew Rose, Imperial College, London
25  email: awr01 <AT> imperial.ac.uk
26 
27  Marc Magrans de Abril, CERN
28  email: marc.magrans.de.abril <AT> cern.ch
29 
30 ---------------------------------------------------------------------------
31 */
32 
33 #include "uhal/Buffers.hpp"
34 
35 
36 #include <string.h>
37 
38 
39 namespace uhal
40 {
41 
42  Buffers::Buffers ( const uint32_t& aMaxSendSize ) :
43  mSendCounter ( 0 ),
44  mReplyCounter ( 0 ),
45  mSendBuffer ( aMaxSendSize , 0x00 )
46  {
47  }
48 
49 
51  {
52  }
53 
54 
55  const uint32_t& Buffers::sendCounter()
56  {
57  return mSendCounter;
58  }
59 
60  const uint32_t& Buffers::replyCounter()
61  {
62  return mReplyCounter;
63  }
64 
65 
66  uint8_t* Buffers::send ( const uint8_t* aPtr , const uint32_t& aSize )
67  {
68  uint8_t* lStartPtr ( &mSendBuffer[0]+mSendCounter );
69  memcpy ( lStartPtr , aPtr , aSize );
70  mSendCounter += aSize;
71  return lStartPtr;
72  }
73 
74 
75  void Buffers::receive ( uint8_t* aPtr , const uint32_t& aSize )
76  {
77  mReplyBuffer.push_back ( std::make_pair ( aPtr , aSize ) );
78  mReplyCounter += aSize;
79  }
80 
81  void Buffers::add ( const ValHeader& aValMem )
82  {
83  mValHeaders.push_back ( aValMem );
84  }
85 
86  void Buffers::add ( const ValWord< uint32_t >& aValMem )
87  {
88  mUnsignedValWords.push_back ( aValMem );
89  }
90 
91  void Buffers::add ( const ValVector< uint32_t >& aValMem )
92  {
93  mUnsignedValVectors.push_back ( aValMem );
94  }
95 
97  {
98  return &mSendBuffer[0];
99  }
100 
101  std::deque< std::pair< uint8_t* , uint32_t > >& Buffers::getReplyBuffer()
102  {
103  return mReplyBuffer;
104  }
105 
106 
108  {
109  for ( std::deque< ValHeader >::iterator lIt = mValHeaders.begin() ; lIt != mValHeaders.end() ; ++lIt )
110  {
111  lIt->valid ( true );
112  }
113 
114  for ( std::deque< ValWord< uint32_t > >::iterator lIt = mUnsignedValWords.begin() ; lIt != mUnsignedValWords.end() ; ++lIt )
115  {
116  lIt->valid ( true );
117  }
118 
119  for ( std::deque< ValVector< uint32_t > >::iterator lIt = mUnsignedValVectors.begin() ; lIt != mUnsignedValVectors.end() ; ++lIt )
120  {
121  lIt->valid ( true );
122  }
123  }
124 
125 
127  {
128  mSendCounter = 0 ;
129  mReplyCounter = 0 ;
130  mReplyBuffer.clear();
131  mValHeaders.clear();
132  mUnsignedValWords.clear();
133  mUnsignedValVectors.clear();
134  }
135 
136 }
137 
138 
uhal::Buffers::mSendCounter
uint32_t mSendCounter
The number of bytes that are currently in the send buffer.
Definition: Buffers.hpp:164
uhal::ValVector< uint32_t >
uhal::Buffers::mUnsignedValWords
std::deque< ValWord< uint32_t > > mUnsignedValWords
Deque holding validated memories so that they are guaranteed to exist when the transaction is perform...
Definition: Buffers.hpp:176
uhal::Buffers::getSendBuffer
uint8_t * getSendBuffer()
Get a pointer to the start of the send buffer.
Definition: Buffers.cpp:96
uhal::Buffers::replyCounter
const uint32_t & replyCounter()
Get the number of bytes that are currently expected by the reply buffer.
Definition: Buffers.cpp:60
uhal::Buffers::sendCounter
const uint32_t & sendCounter()
Get the number of bytes that are currently in the send buffer.
Definition: Buffers.cpp:55
uhal::Buffers::mUnsignedValVectors
std::deque< ValVector< uint32_t > > mUnsignedValVectors
Deque holding validated memories so that they are guaranteed to exist when the transaction is perform...
Definition: Buffers.hpp:178
uhal::ValHeader
A class which wraps a single word of data and marks whether or not it is valid.
Definition: ValMem.hpp:148
uhal::Buffers::mSendBuffer
std::vector< uint8_t > mSendBuffer
The start location of the memory buffer.
Definition: Buffers.hpp:169
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::Buffers::mReplyCounter
uint32_t mReplyCounter
The number of bytes that are currently expected by the reply buffer.
Definition: Buffers.hpp:166
uhal::Buffers::mReplyBuffer
std::deque< std::pair< uint8_t *, uint32_t > > mReplyBuffer
The queue of reply destinations.
Definition: Buffers.hpp:171
uhal::Buffers::add
void add(const ValHeader &aValMem)
Helper function to associate a validated memory with this buffer so that it is guaranteed to exist wh...
Definition: Buffers.cpp:81
uhal::Buffers::receive
void receive(T *aPtr)
Helper function to add a destination object to the reply queue.
Definition: Buffers.hxx:64
uhal::Buffers::~Buffers
virtual ~Buffers()
Destructor.
Definition: Buffers.cpp:50
uhal::Buffers::clear
void clear()
Clear the counters and the reply buffers.
Definition: Buffers.cpp:126
uhal::Buffers::getReplyBuffer
std::deque< std::pair< uint8_t *, uint32_t > > & getReplyBuffer()
Get a reference to the reply queue.
Definition: Buffers.cpp:101
uhal::Buffers::Buffers
Buffers(const uint32_t &aMaxSendSize=65536)
Constructor.
Definition: Buffers.cpp:42
uhal::Buffers::mValHeaders
std::deque< ValHeader > mValHeaders
Deque holding validated memories so that they are guaranteed to exist when the transaction is perform...
Definition: Buffers.hpp:174
uhal::ValWord< uint32_t >
uhal::Buffers::validate
void validate()
Helper function to mark all validated memories associated with this buffer as valid.
Definition: Buffers.cpp:107
uhal::Buffers::send
uint8_t * send(const T *aPtr)
Helper function to copy an object to the send buffer.
Definition: Buffers.hxx:44
Buffers.hpp