μHAL (v2.7.9)
Part of the IPbus software repository
Buffers.hxx
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 
34 #include <stdint.h> // for uint32_t, uint8_t
35 #include <string.h> // for memcpy
36 #include <deque> // for deque
37 #include <utility> // for make_pair, pair
38 #include <vector> // for vector
39 
40 
41 namespace uhal
42 {
43  template< typename T >
44  uint8_t* Buffers::send ( const T* aPtr )
45  {
46  uint32_t lSize ( sizeof ( T ) );
47  uint8_t* lStartPtr ( &mSendBuffer[0]+mSendCounter );
48  memcpy ( lStartPtr , aPtr , lSize );
49  mSendCounter += lSize;
50  return lStartPtr;
51  }
52 
53  template< typename T >
54  uint8_t* Buffers::send ( const T& aRef )
55  {
56  uint32_t lSize ( sizeof ( T ) );
57  uint8_t* lStartPtr ( &mSendBuffer[0]+mSendCounter );
58  memcpy ( lStartPtr , &aRef , lSize );
59  mSendCounter += lSize;
60  return lStartPtr;
61  }
62 
63  template< typename T >
64  void Buffers::receive ( T* aPtr )
65  {
66  uint32_t lSize ( sizeof ( T ) );
67  mReplyBuffer.push_back ( std::make_pair ( ( uint8_t* ) ( aPtr ) , lSize ) );
68  mReplyCounter += lSize;
69  }
70 
71  template< typename T >
72  void Buffers::receive ( T& aRef )
73  {
74  uint32_t lSize ( sizeof ( T ) );
75  mReplyBuffer.push_back ( std::make_pair ( ( uint8_t* ) ( &aRef ) , lSize ) );
76  mReplyCounter += lSize;
77  }
78 
79 }
80 
81 
uhal::Buffers::mSendCounter
uint32_t mSendCounter
The number of bytes that are currently in the send buffer.
Definition: Buffers.hpp:164
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::receive
void receive(T *aPtr)
Helper function to add a destination object to the reply queue.
Definition: Buffers.hxx:64
uhal::Buffers::send
uint8_t * send(const T *aPtr)
Helper function to copy an object to the send buffer.
Definition: Buffers.hxx:44