μHAL (v2.8.17)
Part of the IPbus software repository
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ConnectionManager.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
40#ifndef _uhal_ConnectionManager_hpp_
41#define _uhal_ConnectionManager_hpp_
42
43
44#include <map>
45#include <set>
46#include <unordered_map>
47#include <vector>
48
49#include <boost/filesystem/path.hpp>
50
52#include "uhal/HwInterface.hpp"
53
54
55// Forward declarations
56namespace pugi
57{
58 class xml_node;
59}
60
61namespace boost
62{
63 class mutex;
64}
65
66
67namespace uhal
68{
69 namespace exception
70 {
72 UHAL_DEFINE_EXCEPTION_CLASS ( DuplicatedUID , "Exception class to handle the case where the supposedly unique ID is duplicated." )
74 UHAL_DEFINE_EXCEPTION_CLASS ( ConnectionUIDDoesNotExist , "Exception class to handle the case where the UID requested does not exists in the map of connections." )
75 }
76
79 {
80 public:
83 {
90 ConnectionDescriptor ( const pugi::xml_node& aNode , const boost::filesystem::path& aConnectionFile , bool& aSuccess );
91
97 bool operator== ( const ConnectionDescriptor& aConnectionDescriptor ) const;
98
100 std::string id;
102 std::string uri;
104 std::string address_table;
106 boost::filesystem::path connection_file;
107 };
108
109 public:
110
113
119 ConnectionManager ( const std::string& aFilenameExpr );
120
121 ConnectionManager ( const std::string& aFilenameExpr , const std::vector<std::string>& aUserClientActivationList );
122
124 virtual ~ConnectionManager ();
125
133 HwInterface getDevice ( const std::string& aId );
134
139 std::vector<std::string> getDevices ( ) const;
140
146 std::vector<std::string> getDevices ( const std::string& aRegex ) const;
147
157 static HwInterface getDevice ( const std::string& aId , const std::string& aUri , const std::string& aAddressFileExpr );
158
159 static HwInterface getDevice ( const std::string& aId , const std::string& aUri , const std::string& aAddressFileExpr , const std::vector<std::string>& aUserClientActivationList );
160
162 static void clearAddressFileCache();
163
164 private:
166 static std::mutex mMutex;
167
174 void CallBack ( const std::string& aProtocol , const boost::filesystem::path& aPath , std::vector<uint8_t>& aFile );
175
176 const std::vector<std::string> mUserClientActivationList;
177
179 std::map< std::string, ConnectionDescriptor > mConnectionDescriptors; //connection identifier, parsed descriptor (also contains the connection identifier)
180
182 std::set< std::string > mPreviouslyOpenedFiles;
183 };
184
185}
186
187#endif
188
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
A class to open and manage XML connection files and wrap up the interfaces to the NodeTreeBuilder and...
ConnectionManager(const ConnectionManager &)=delete
ConnectionManager & operator=(const ConnectionManager &)=delete
const std::vector< std::string > mUserClientActivationList
std::map< std::string, ConnectionDescriptor > mConnectionDescriptors
A map of connection identifiers to stucts containing details of the parsed XML node.
std::set< std::string > mPreviouslyOpenedFiles
A set of previously opened filenames, so that the same file is not parsed multiple times.
static std::mutex mMutex
A mutex lock to protect access to the factory methods in multithreaded environments.
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
Definition: HwInterface.hpp:56
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:59
bool operator==(const HashMe &lhs, const HashMe &rhs)
A struct to hold the fields of each entry in the XML connections file.
std::string id
An identifier for an individual.
boost::filesystem::path connection_file
The connection file which provided this entry.
std::string uri
The full uri for making the connection.
std::string address_table
The address table for building the node tree.