μHAL (v2.7.9)
Part of the IPbus software repository
ProtocolControlHub.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_ProtocolControlHub_hpp_
40 #define _uhal_ProtocolControlHub_hpp_
41 
42 #include "uhal/ClientInterface.hpp"
43 #include "uhal/log/exception.hpp"
44 #include "uhal/log/log.hpp"
45 
46 #include <iomanip>
47 #include <iostream>
48 #include <string>
49 
50 
51 namespace uhal
52 {
53 
54  namespace exception
55  {
57  UHAL_DEFINE_EXCEPTION_CLASS ( ParsingTargetURLfailed , "Exception class to handle the case where parsing the target URL failed." )
58 
59 
60  UHAL_DEFINE_EXCEPTION_CLASS ( HostnameToIPlookupFailed , "Exception class to handle the case where hostname to IP lookup failed." )
61 
63  UHAL_DEFINE_EXCEPTION_CLASS ( XMLfileMissingRequiredParameters , "Exception class to handle the case where the received header does not match the expected header." )
64 
66  UHAL_DEFINE_EXCEPTION_CLASS ( ControlHubReturnedWrongAddress , "Exception class to handle the case where the ControlHub returned the wrong IP or Port" )
67 
69  UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( ControlHubTargetTimeout , ClientTimeout , "Exception class to handle the case where the target does not respond to the ControlHub" )
70 
72  UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( ControlHubErrorCodeSet, PacketLevelError , "Exception class to handle cases in which the ControlHub returns a non-zero error code (excluding target timeouts)" )
73  }
74 
80  std::pair< uint32_t , uint16_t > ExtractTargetID ( const URI& aUri );
81 
82 
84  template < typename InnerProtocol >
85  class ControlHub : public InnerProtocol
86  {
87 
88  public:
94  ControlHub ( const std::string& aId, const URI& aUri );
95 
97  virtual ~ControlHub();
98 
99  protected:
100 
105  virtual void preamble ( boost::shared_ptr< Buffers > aBuffers );
106 
111  virtual uint32_t getPreambleSize();
112 
117  virtual void predispatch ( boost::shared_ptr< Buffers > aBuffers );
118 
127  virtual exception::exception* validate ( uint8_t* aSendBufferStart ,
128  uint8_t* aSendBufferEnd ,
129  std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyStartIt ,
130  std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyEndIt );
131 
139  virtual uint32_t getMaxNumberOfBuffers();
140 
142  virtual void dispatchExceptionHandler();
143 
144  private:
145  static void translateErrorCode(std::ostream& aStream, const uint16_t& aErrorCode);
146 
149 
151  uint16_t mDevicePort;
152 
154  struct tpreamble
155  {
157  uint16_t* mSendWordCountPtr;
158 
166  uint16_t mReplyErrorCode;
167  };
168 
170  std::deque< tpreamble > mPreambles;
172  boost::mutex mPreamblesMutex;
173 
174  };
175 
176 
177 }
178 
179 #endif
UHAL_DEFINE_EXCEPTION_CLASS
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:59
uhal::ControlHub::mDevicePort
uint16_t mDevicePort
The port number of the target device that is connected to the Control Hub.
Definition: ProtocolControlHub.hpp:151
boost::shared_ptr
Definition: DerivedNodeFactory.hpp:52
uhal::ControlHub::tpreamble::mReplyChunkByteCounter
uint32_t mReplyChunkByteCounter
A legacy counter.
Definition: ProtocolControlHub.hpp:160
uhal::ControlHub::mPreamblesMutex
boost::mutex mPreamblesMutex
Mutex to be used when accessing mPreambles.
Definition: ProtocolControlHub.hpp:172
uhal::ControlHub::mPreambles
std::deque< tpreamble > mPreambles
A queue of preample structs making the memory used by the preambles persistent during the dispatch....
Definition: ProtocolControlHub.hpp:170
uhal::ControlHub::tpreamble::mReplyDeviceIPaddress
uint32_t mReplyDeviceIPaddress
The returned target device ID (IP address)
Definition: ProtocolControlHub.hpp:162
uhal::ControlHub::mDeviceIPaddress
uint32_t mDeviceIPaddress
The IP address of the target device that is connected to the Control Hub.
Definition: ProtocolControlHub.hpp:148
UHAL_DEFINE_DERIVED_EXCEPTION_CLASS
#define UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(ClassName, BaseClassName, ClassDescription)
Macro for simplifying the declaration and definition of derived exception types.
Definition: exception.hpp:49
uhal::ControlHub::tpreamble::mSendWordCountPtr
uint16_t * mSendWordCountPtr
The number of 32-bit words in the IPbus packet (legacy and could be removed)
Definition: ProtocolControlHub.hpp:157
uhal::ControlHub::tpreamble::mReplyDevicePort
uint16_t mReplyDevicePort
The returned target device ID (port number)
Definition: ProtocolControlHub.hpp:164
uhal::exception::exception
An abstract base exception class, including an interface to throw as the derived type (for passing ex...
Definition: exception.hpp:71
uhal
Definition: HttpResponseGrammar.hpp:49
uhal::ControlHub::tpreamble::mReplyErrorCode
uint16_t mReplyErrorCode
An error code returned describing the status of the control hub.
Definition: ProtocolControlHub.hpp:166
uhal::ControlHub::tpreamble
A struct representing the preamble which will be prepended to an IPbus buffer for the benefit of the ...
Definition: ProtocolControlHub.hpp:155
uhal::ExtractTargetID
std::pair< uint32_t, uint16_t > ExtractTargetID(const URI &aUri)
Extract an IP-address and port number from a URI object.
Definition: ProtocolControlHub.cpp:50
log.hpp
uhal::URI
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:50
exception.hpp
uhal::ControlHub
Transport protocol to transfer an IPbus buffer via ControlHub.
Definition: ProtocolControlHub.hpp:86
ClientInterface.hpp