μHAL (v2.6.5)
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 <iostream>
47 #include <iomanip>
48 
49 #include <string>
50 
51 
52 namespace uhal
53 {
54 
55  namespace exception
56  {
58  UHAL_DEFINE_EXCEPTION_CLASS ( ParsingTargetURLfailed , "Exception class to handle the case where parsing the target URL failed." )
59 
60 
61  UHAL_DEFINE_EXCEPTION_CLASS ( HostnameToIPlookupFailed , "Exception class to handle the case where hostname to IP lookup failed." )
62 
64  UHAL_DEFINE_EXCEPTION_CLASS ( XMLfileMissingRequiredParameters , "Exception class to handle the case where the received header does not match the expected header." )
65 
67  UHAL_DEFINE_EXCEPTION_CLASS ( ControlHubReturnedWrongAddress , "Exception class to handle the case where the ControlHub returned the wrong IP or Port" )
68 
70  UHAL_DEFINE_DERIVED_EXCEPTION_CLASS ( ControlHubTargetTimeout , ClientTimeout , "Exception class to handle the case where the target does not respond to the ControlHub" )
71 
73  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)" )
74  }
75 
81  std::pair< uint32_t , uint16_t > ExtractTargetID ( const URI& aUri );
82 
83 
85  template < typename InnerProtocol >
86  class ControlHub : public InnerProtocol
87  {
88 
89  public:
95  ControlHub ( const std::string& aId, const URI& aUri );
96 
100  virtual ~ControlHub();
101 
102  protected:
103 
108  virtual void preamble ( boost::shared_ptr< Buffers > aBuffers );
109 
114  virtual uint32_t getPreambleSize();
115 
120  virtual void predispatch ( boost::shared_ptr< Buffers > aBuffers );
121 
122 
131  virtual exception::exception* validate ( uint8_t* aSendBufferStart ,
132  uint8_t* aSendBufferEnd ,
133  std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyStartIt ,
134  std::deque< std::pair< uint8_t* , uint32_t > >::iterator aReplyEndIt );
135 
143  virtual uint32_t getMaxNumberOfBuffers()
144  {
145  return 60;
146  }
147 
151  virtual void dispatchExceptionHandler();
152 
153 
154  private:
155  static void translateErrorCode(std::ostream& aStream, const uint16_t& aErrorCode);
156 
159 
161  uint16_t mDevicePort;
162 
164  struct tpreamble
165  {
166  // The total number of bytes that follow (outgoing) forming a logical packet (IDs + IPbus packet)
167  // uint32_t* mSendByteCountPtr;
169  uint16_t* mSendWordCountPtr;
170 
171  // The total number of bytes that follow (incoming) forming a logical packet (IDs + IPbus packet)
172  // uint32_t mReplyTotalByteCounter;
180  uint16_t mReplyErrorCode;
181  };
182 
184  std::deque< tpreamble > mPreambles;
186  boost::mutex mPreamblesMutex;
187 
188  };
189 
190 
191 }
192 
193 #endif
uint32_t mDeviceIPaddress
The IP address of the target device that is connected to the Control Hub.
uint32_t mReplyChunkByteCounter
A legacy counter.
uint32_t mReplyDeviceIPaddress
The returned target device ID (IP address)
uint16_t * mSendWordCountPtr
The number of 32-bit words in the IPbus packet (legacy and could be removed)
boost::mutex mPreamblesMutex
Mutex to be used when accessing mPreambles.
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:64
#define UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(ClassName, BaseClassName, ClassDescription)
Macro for simplifying the declaration and definition of derived exception types.
Definition: exception.hpp:54
An abstract base exception class providing an interface to a throw/ThrowAsDerivedType mechanism which...
Definition: exception.hpp:89
std::deque< tpreamble > mPreambles
A queue of preample structs making the memory used by the preambles persistent during the dispatch...
A struct representing the preamble which will be prepended to an IPbus buffer for the benefit of the ...
std::pair< uint32_t, uint16_t > ExtractTargetID(const URI &aUri)
Extract an IP-address and port number from a URI object.
Transport protocol to transfer an IPbus buffer via ControlHub.
virtual uint32_t getMaxNumberOfBuffers()
Returns the maximum number of buffers that should be in-flight from the uHAL client at any given time...
uint16_t mReplyErrorCode
An error code returned describing the status of the control hub.
uint16_t mReplyDevicePort
The returned target device ID (port number)
uint16_t mDevicePort
The port number of the target device that is connected to the Control Hub.
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:49