μHAL (v2.7.9)
Part of the IPbus software repository
Buffers.hpp
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 
39 #ifndef _uhal_Buffers_hpp_
40 #define _uhal_Buffers_hpp_
41 
42 
43 #include <deque>
44 #include <stdint.h> // for uint32_t, uint8_t
45 #include <utility> // for pair
46 #include <vector> // for vector
47 
48 #include "uhal/ValMem.hpp"
49 
50 
51 namespace uhal
52 {
53 
55  class Buffers
56  {
57  public:
58 
64  Buffers ( const uint32_t& aMaxSendSize = 65536 );
65 
67  virtual ~Buffers();
68 
73  const uint32_t& sendCounter();
74 
79  const uint32_t& replyCounter();
80 
86  template< typename T >
87  uint8_t* send ( const T* aPtr );
88 
94  template< typename T >
95  uint8_t* send ( const T& aRef );
96 
103  uint8_t* send ( const uint8_t* aPtr , const uint32_t& aSize );
104 
109  template< typename T >
110  void receive ( T* aPtr );
111 
116  template< typename T >
117  void receive ( T& aRef );
118 
124  void receive ( uint8_t* aPtr , const uint32_t& aSize );
125 
130  void add ( const ValHeader& aValMem );
131 
136  void add ( const ValWord< uint32_t >& aValMem );
137 
142  void add ( const ValVector< uint32_t >& aValMem );
143 
148  uint8_t* getSendBuffer();
149 
154  std::deque< std::pair< uint8_t* , uint32_t > >& getReplyBuffer();
155 
157  void validate ();
158 
160  void clear();
161 
162  private:
164  uint32_t mSendCounter;
166  uint32_t mReplyCounter;
167 
169  std::vector<uint8_t> mSendBuffer;
171  std::deque< std::pair< uint8_t* , uint32_t > > mReplyBuffer;
172 
174  std::deque< ValHeader > mValHeaders;
176  std::deque< ValWord< uint32_t > > mUnsignedValWords;
178  std::deque< ValVector< uint32_t > > mUnsignedValVectors;
179  };
180 
181 }
182 
184 
185 #endif
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
Buffers.hxx
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
A class wrapping the send and recieve buffers that are to be filled and transported and the validated...
Definition: Buffers.hpp:56
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
ValMem.hpp
uhal::Buffers::send
uint8_t * send(const T *aPtr)
Helper function to copy an object to the send buffer.
Definition: Buffers.hxx:44