μHAL (v2.7.9)
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  public:
115  ConnectionManager ( const std::string& aFilenameExpr );
116 
117  ConnectionManager ( const std::string& aFilenameExpr , const std::vector<std::string>& aUserClientActivationList );
118 
120  virtual ~ConnectionManager ();
121 
129  HwInterface getDevice ( const std::string& aId );
130 
135  std::vector<std::string> getDevices ( ) const;
136 
142  std::vector<std::string> getDevices ( const std::string& aRegex ) const;
143 
153  static HwInterface getDevice ( const std::string& aId , const std::string& aUri , const std::string& aAddressFileExpr );
154 
155  static HwInterface getDevice ( const std::string& aId , const std::string& aUri , const std::string& aAddressFileExpr , const std::vector<std::string>& aUserClientActivationList );
156 
158  static void clearAddressFileCache();
159 
160  private:
162  static boost::mutex mMutex;
163 
170  void CallBack ( const std::string& aProtocol , const boost::filesystem::path& aPath , std::vector<uint8_t>& aFile );
171 
172  const std::vector<std::string> mUserClientActivationList;
173 
175  std::map< std::string, ConnectionDescriptor > mConnectionDescriptors; //connection identifier, parsed descriptor (also contains the connection identifier)
176 
178  std::set< std::string > mPreviouslyOpenedFiles;
179  };
180 
181 }
182 
183 #endif
184 
uhal::HwInterface
A class which bundles a node tree and an IPbus client interface together providing everything you nee...
Definition: HwInterface.hpp:61
uhal::ConnectionManager::ConnectionDescriptor::connection_file
boost::filesystem::path connection_file
The connection file which provided this entry.
Definition: ConnectionManager.hpp:106
UHAL_DEFINE_EXCEPTION_CLASS
#define UHAL_DEFINE_EXCEPTION_CLASS(ClassName, ClassDescription)
Definition: exception.hpp:59
uhal::ConnectionManager::mUserClientActivationList
const std::vector< std::string > mUserClientActivationList
Definition: ConnectionManager.hpp:172
uhal::ConnectionManager::ConnectionDescriptor::uri
std::string uri
The full uri for making the connection.
Definition: ConnectionManager.hpp:102
boost
Definition: log.hpp:13
uhal::ConnectionManager::mMutex
static boost::mutex mMutex
A mutex lock to protect access to the factory methods in multithreaded environments.
Definition: ConnectionManager.hpp:162
uhal
Definition: HttpResponseGrammar.hpp:49
pugi::xml_node
Definition: pugixml.hpp:455
uhal::ConnectionManager::ConnectionDescriptor::address_table
std::string address_table
The address table for building the node tree.
Definition: ConnectionManager.hpp:104
uhal::ConnectionManager::ConnectionDescriptor
A struct to hold the fields of each entry in the XML connections file.
Definition: ConnectionManager.hpp:83
uhal::ConnectionManager::ConnectionDescriptor::id
std::string id
An identifier for an individual.
Definition: ConnectionManager.hpp:100
uhal::ConnectionManager::mConnectionDescriptors
std::map< std::string, ConnectionDescriptor > mConnectionDescriptors
A map of connection identifiers to stucts containing details of the parsed XML node.
Definition: ConnectionManager.hpp:175
HwInterface.hpp
uhal::ConnectionManager
A class to open and manage XML connection files and wrap up the interfaces to the NodeTreeBuilder and...
Definition: ConnectionManager.hpp:79
uhal::ConnectionManager::mPreviouslyOpenedFiles
std::set< std::string > mPreviouslyOpenedFiles
A set of previously opened filenames, so that the same file is not parsed multiple times.
Definition: ConnectionManager.hpp:178
pugi
Definition: pugixml.hpp:124
exception.hpp