μHAL (v2.6.5)
Part of the IPbus software repository
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 "uhal/log/exception.hpp"
45 #include "uhal/HwInterface.hpp"
46 
47 #include <boost/filesystem/path.hpp>
48 #include <boost/noncopyable.hpp>
49 
50 #include <vector>
51 #include <set>
52 #include <map>
53 
54 
55 // Forward declarations
56 namespace pugi
57 {
58  class xml_node;
59 }
60 
61 namespace boost
62 {
63  class mutex;
64 }
65 
66 
67 namespace 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 
78  class ConnectionManager: private boost::noncopyable
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 
110 
111 
112  public:
118  ConnectionManager ( const std::string& aFilenameExpr );
119 
123  virtual ~ConnectionManager ();
124 
132  HwInterface getDevice ( const std::string& aId );
133 
138  std::vector<std::string> getDevices ( ) const;
139 
140 
146  std::vector<std::string> getDevices ( const std::string& aRegex ) const;
147 
148 
158  static HwInterface getDevice ( const std::string& aId , const std::string& aUri , const std::string& aAddressFileExpr );
159 
161  static void clearAddressFileCache();
162 
163  private:
165  static boost::mutex mMutex;
166 
173  void CallBack ( const std::string& aProtocol , const boost::filesystem::path& aPath , std::vector<uint8_t>& aFile );
174 
176  std::map< std::string, ConnectionDescriptor > mConnectionDescriptors; //connection identifier, parsed descriptor (also contains the connection identifier)
177 
179  std::set< std::string > mPreviouslyOpenedFiles;
180 
181  };
182 
183 
184 }
185 
186 #endif
187 
std::map< std::string, ConnectionDescriptor > mConnectionDescriptors
A map of connection identifiers to stucts containing details of the parsed XML node.
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
Definition: HwInterface.hpp:59
std::string address_table
The address table for building the node tree.
static boost::mutex mMutex
A mutex lock to protect access to the factory methods in multithreaded environments.
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:64
boost::filesystem::path connection_file
The connection file which provided this entry.
std::string uri
The full uri for making the connection.
std::set< std::string > mPreviouslyOpenedFiles
A set of previously opened filenames, so that the same file is not parsed multiple times...
A struct to hold the fields of each entry in the XML connections file.
std::string id
An identifier for an individual.
A class to open and manage XML connection files and wrap up the interfaces to the NodeTreeBuilder and...