μHAL (v2.7.4)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
TCPDummyHardware.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  Marc Magrans de Abril, CERN
24  email: marc.magrans.de.abril <AT> cern.ch
25 
26  Andrew Rose, Imperial College, London
27  email: awr01 <AT> imperial.ac.uk
28 
29 ---------------------------------------------------------------------------
30 */
31 
32 #ifndef _uhal_tests_TCPDummyHardware_hpp_
33 #define _uhal_tests_TCPDummyHardware_hpp_
34 
35 
36 #include <boost/asio.hpp>
37 
39 
40 
41 namespace uhal {
42  namespace tests {
43 
45  template< uint8_t IPbus_major , uint8_t IPbus_minor >
46  class TCPDummyHardware : public DummyHardware< IPbus_major , IPbus_minor >
47  {
48  public:
51 
58  TCPDummyHardware ( const uint16_t& aPort , const uint32_t& aReplyDelay, const bool& aBigEndianHack ) :
59  DummyHardware< IPbus_major , IPbus_minor > ( aReplyDelay , aBigEndianHack ) ,
60  mIOservice(),
61  mAcceptor ( mIOservice , boost::asio::ip::tcp::endpoint ( boost::asio::ip::tcp::v4() , aPort ) ),
63  {
64  mAcceptor.listen();
65  }
66 
69  {
70  }
71 
76  void run();
77 
78  void stop();
79 
80  private:
81  void handle_accept(const boost::system::error_code& aError);
82 
83  void handle_read_chunk_header(const boost::system::error_code& ec, std::size_t length);
84 
85  void handle_read_chunk_payload(const boost::system::error_code& ec, std::size_t length);
86 
88  boost::asio::io_service mIOservice;
90  boost::asio::ip::tcp::acceptor mAcceptor;
92  boost::asio::ip::tcp::socket mSocket;
93 
95  boost::asio::ip::tcp::endpoint mSenderEndpoint;
97  uint32_t mByteCountHeader;
98  };
99  }
100 }
101 
102 #endif
103 
void handle_accept(const boost::system::error_code &aError)
void handle_read_chunk_header(const boost::system::error_code &ec, std::size_t length)
Definition: log.hpp:13
uint32_t mByteCountHeader
Value of &#39;byte count&#39; header at start of latest TCP chunk.
boost::asio::ip::tcp::acceptor mAcceptor
The TCP acceptor which opens the TCP port and handles the connection.
DummyHardware< IPbus_major, IPbus_minor > base_type
Define the underlying DummyHardware type to be a more convenient label.
TCPDummyHardware(const uint16_t &aPort, const uint32_t &aReplyDelay, const bool &aBigEndianHack)
Constructor.
Concrete implementation of emulator of hardware using TCP.
boost::asio::ip::tcp::endpoint mSenderEndpoint
The endpoint which sent the UDP datagram.
boost::asio::io_service mIOservice
The BOOST ASIO io_service used by the TCP server.
void handle_read_chunk_payload(const boost::system::error_code &ec, std::size_t length)
boost::asio::ip::tcp::socket mSocket
The socket opened by the TCP server.
Abstract base class to emulate IPbus hardware.
void run()
Concrete implementation of the run function Starts the TCP server and runs indefinitely, until exception or user kills the server.
void stop()
Stops this dummy hardware instance - i.e. makes the &#39;run&#39; method return.