μHAL (v2.7.9)
Part of the IPbus software repository
Classes | Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
uhal::ConnectionManager Class Reference

A class to open and manage XML connection files and wrap up the interfaces to the NodeTreeBuilder and the ClientFactory. More...

#include <uhal/ConnectionManager.hpp>

Inheritance diagram for uhal::ConnectionManager:
[legend]
Collaboration diagram for uhal::ConnectionManager:
[legend]

Classes

struct  ConnectionDescriptor
 A struct to hold the fields of each entry in the XML connections file. More...
 

Public Member Functions

 ConnectionManager (const std::string &aFilenameExpr)
 Default constructor Given a semi-colon delimeted list of glob expressions, parse all the files matching it (e.g. More...
 
 ConnectionManager (const std::string &aFilenameExpr, const std::vector< std::string > &aUserClientActivationList)
 
virtual ~ConnectionManager ()
 Destructor. More...
 
HwInterface getDevice (const std::string &aId)
 Retrieves protocol, host, and port from the connection file to create an IPbus Client Retrieves the address table file from the connection file to create the Node tree Puts the two together to create a full HwInterface. More...
 
std::vector< std::string > getDevices () const
 Return all device IDs known to this connection manager. More...
 
std::vector< std::string > getDevices (const std::string &aRegex) const
 Return all device IDs known to this connection manager which match a (boost) regular expression. More...
 

Static Public Member Functions

static HwInterface getDevice (const std::string &aId, const std::string &aUri, const std::string &aAddressFileExpr)
 Use the specified protocol, host, and port to create an IPbus Client Use the specified address table to create the Node tree Puts the two together to create a full HwInterface. More...
 
static HwInterface getDevice (const std::string &aId, const std::string &aUri, const std::string &aAddressFileExpr, const std::vector< std::string > &aUserClientActivationList)
 
static void clearAddressFileCache ()
 Clears cache of Node tree structure for previously-opened address files (thread safe) More...
 

Private Member Functions

void CallBack (const std::string &aProtocol, const boost::filesystem::path &aPath, std::vector< uint8_t > &aFile)
 Method called once the file specified in the constructor has been opened. More...
 

Private Attributes

const std::vector< std::string > mUserClientActivationList
 
std::map< std::string, ConnectionDescriptormConnectionDescriptors
 A map of connection identifiers to stucts containing details of the parsed XML node. More...
 
std::set< std::string > mPreviouslyOpenedFiles
 A set of previously opened filenames, so that the same file is not parsed multiple times. More...
 

Static Private Attributes

static boost::mutex mMutex
 A mutex lock to protect access to the factory methods in multithreaded environments. More...
 

Detailed Description

A class to open and manage XML connection files and wrap up the interfaces to the NodeTreeBuilder and the ClientFactory.

Definition at line 78 of file ConnectionManager.hpp.

Constructor & Destructor Documentation

◆ ConnectionManager() [1/2]

uhal::ConnectionManager::ConnectionManager ( const std::string &  aFilenameExpr)

Default constructor Given a semi-colon delimeted list of glob expressions, parse all the files matching it (e.g.

$BUILD/config/c*.xml). If one parsing fails throw an exception and return filename and line number

Parameters
aFilenameExpra semi-colon delimeted list of glob expressions specifying one or more XML connection files to load

Definition at line 106 of file ConnectionManager.cpp.

References CallBack(), mMutex, uhal::utilities::OpenFile(), and uhal::utilities::ParseSemicolonDelimitedUriList().

◆ ConnectionManager() [2/2]

uhal::ConnectionManager::ConnectionManager ( const std::string &  aFilenameExpr,
const std::vector< std::string > &  aUserClientActivationList 
)

◆ ~ConnectionManager()

uhal::ConnectionManager::~ConnectionManager ( )
virtual

Destructor.

Definition at line 135 of file ConnectionManager.cpp.

Member Function Documentation

◆ CallBack()

void uhal::ConnectionManager::CallBack ( const std::string &  aProtocol,
const boost::filesystem::path &  aPath,
std::vector< uint8_t > &  aFile 
)
private

Method called once the file specified in the constructor has been opened.

Parameters
aProtocolThe protocol by which the file was loaded
aPathThe fully qualified path to the file which has been opened
aFileA byte vector containing the content of the opened file. Done like this since the routine handles local and http files identically

Definition at line 233 of file ConnectionManager.cpp.

References uhal::ConnectionManager::ConnectionDescriptor::address_table, pugi::xpath_node_set::begin(), pugi::xpath_node_set::end(), uhal::Error, uhal::ConnectionManager::ConnectionDescriptor::id, uhal::Info, pugi::xml_document::load_buffer_inplace(), uhal::log(), mConnectionDescriptors, mPreviouslyOpenedFiles, uhal::utilities::PugiXMLParseResultPrettifier(), uhal::Quote(), pugi::xml_node::select_nodes(), and uhal::ConnectionManager::ConnectionDescriptor::uri.

Referenced by ConnectionManager().

◆ clearAddressFileCache()

void uhal::ConnectionManager::clearAddressFileCache ( )
static

Clears cache of Node tree structure for previously-opened address files (thread safe)

Definition at line 224 of file ConnectionManager.cpp.

References uhal::NodeTreeBuilder::clearAddressFileCache(), uhal::NodeTreeBuilder::getInstance(), uhal::Info, uhal::log(), and mMutex.

◆ getDevice() [1/3]

HwInterface uhal::ConnectionManager::getDevice ( const std::string &  aId)

Retrieves protocol, host, and port from the connection file to create an IPbus Client Retrieves the address table file from the connection file to create the Node tree Puts the two together to create a full HwInterface.

Parameters
aIdthe unique identifier for the connection
Returns
a HwInterface which encapsulates the Node tree and the IPbus Client

Definition at line 140 of file ConnectionManager.cpp.

References uhal::ClientFactory::getInstance(), uhal::NodeTreeBuilder::getInstance(), uhal::Info, uhal::log(), mConnectionDescriptors, mMutex, mUserClientActivationList, and uhal::Quote().

Referenced by uhal::tests::MinimalFixture< type >::getHwInterface(), uhal::tests::MinimalFixture< IPBUS_2_0_PCIE >::getHwInterface(), and uhal::tests::job_multiple().

◆ getDevice() [2/3]

HwInterface uhal::ConnectionManager::getDevice ( const std::string &  aId,
const std::string &  aUri,
const std::string &  aAddressFileExpr 
)
static

Use the specified protocol, host, and port to create an IPbus Client Use the specified address table to create the Node tree Puts the two together to create a full HwInterface.

Parameters
aIdthe unique identifier for the connection
aUrithe URI string detailing how the connection is made
aAddressFileExpra file expression pointing to exactly one local or remote address file (note. this assumes a semi-colon delimited list which can contain glob file expressions, etc. This expression is parsed and evaluated, and the file count checked at runtime.)
Returns
a HwInterface which encapsulates the Node tree and the IPbus Client

Definition at line 169 of file ConnectionManager.cpp.

References uhal::ClientFactory::getInstance(), uhal::NodeTreeBuilder::getInstance(), uhal::Info, uhal::log(), and mMutex.

◆ getDevice() [3/3]

HwInterface uhal::ConnectionManager::getDevice ( const std::string &  aId,
const std::string &  aUri,
const std::string &  aAddressFileExpr,
const std::vector< std::string > &  aUserClientActivationList 
)
static

◆ getDevices() [1/2]

std::vector< std::string > uhal::ConnectionManager::getDevices ( ) const

Return all device IDs known to this connection manager.

Returns
all device IDs known to this connection manager

Definition at line 191 of file ConnectionManager.cpp.

References mConnectionDescriptors.

◆ getDevices() [2/2]

std::vector< std::string > uhal::ConnectionManager::getDevices ( const std::string &  aRegex) const

Return all device IDs known to this connection manager which match a (boost) regular expression.

Parameters
aRegexa string expression which is converted to a (boost) regular expression against which the device IDs are tested
Returns
all device IDs known to this connection manager

Definition at line 205 of file ConnectionManager.cpp.

References mConnectionDescriptors.

Member Data Documentation

◆ mConnectionDescriptors

std::map< std::string, ConnectionDescriptor > uhal::ConnectionManager::mConnectionDescriptors
private

A map of connection identifiers to stucts containing details of the parsed XML node.

Definition at line 175 of file ConnectionManager.hpp.

Referenced by CallBack(), getDevice(), and getDevices().

◆ mMutex

boost::mutex uhal::ConnectionManager::mMutex
staticprivate

A mutex lock to protect access to the factory methods in multithreaded environments.

Definition at line 162 of file ConnectionManager.hpp.

Referenced by clearAddressFileCache(), ConnectionManager(), and getDevice().

◆ mPreviouslyOpenedFiles

std::set< std::string > uhal::ConnectionManager::mPreviouslyOpenedFiles
private

A set of previously opened filenames, so that the same file is not parsed multiple times.

Definition at line 178 of file ConnectionManager.hpp.

Referenced by CallBack().

◆ mUserClientActivationList

const std::vector<std::string> uhal::ConnectionManager::mUserClientActivationList
private

Definition at line 172 of file ConnectionManager.hpp.

Referenced by getDevice().


The documentation for this class was generated from the following files: