μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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
44#include "uhal/log/log.hpp"
45
46#include <iomanip>
47#include <iostream>
48#include <string>
49
50
51namespace 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 ( std::shared_ptr< Buffers > aBuffers );
106
111 virtual uint32_t getPreambleSize();
112
117 virtual void predispatch ( std::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
155 {
158
167 };
168
170 std::deque< tpreamble > mPreambles;
172 std::mutex mPreamblesMutex;
173 };
174
175
176}
177
178#endif
Wrapper to generate a new Python exception type.
Definition: pybind11.h:2517
\rst Holds a reference to a Python object (no reference counting)
Definition: pytypes.h:194
\rst Wraps a Python iterator so that it can also be used as a C++ input iterator
Definition: pytypes.h:1102
Transport protocol to transfer an IPbus buffer via ControlHub.
std::deque< tpreamble > mPreambles
A queue of preample structs making the memory used by the preambles persistent during the dispatch....
uint32_t mDeviceIPaddress
The IP address of the target device that is connected to the Control Hub.
std::mutex mPreamblesMutex
Mutex to be used when accessing mPreambles.
uint16_t mDevicePort
The port number of the target device that is connected to the Control Hub.
An abstract base exception class, including an interface to throw as the derived type (for passing ex...
Definition: exception.hpp:71
#define UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(ClassName, BaseClassName, ClassDescription)
Macro for simplifying the declaration and definition of derived exception types.
Definition: exception.hpp:49
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:59
std::pair< uint32_t, uint16_t > ExtractTargetID(const URI &aUri)
Extract an IP-address and port number from a URI object.
A struct representing the preamble which will be prepended to an IPbus buffer for the benefit of the ...
uint16_t * mSendWordCountPtr
The number of 32-bit words in the IPbus packet (legacy and could be removed)
uint32_t mReplyChunkByteCounter
A legacy counter.
uint16_t mReplyDevicePort
The returned target device ID (port number)
uint16_t mReplyErrorCode
An error code returned describing the status of the control hub.
uint32_t mReplyDeviceIPaddress
The returned target device ID (IP address)
Struct to store a URI when parsed by boost spirit.
Definition: URI.hpp:50