37#include <boost/spirit/include/qi.hpp>
80 mInstance->add<
PCIe > (
"ipbuspcie-2.0" ,
"Direct access to hardware via PCIe, using IPbus version 2.0", false );
81 mInstance->add<
Mmap > (
"ipbusmmap-2.0" ,
"Direct access to hardware via mmap, using IPbus version 2.0", false );
92 return getClient(aId, aUri, std::vector<std::string>());
96 std::shared_ptr<ClientInterface>
ClientFactory::getClient (
const std::string& aId ,
const std::string& aUri,
const std::vector<std::string>& aUserClientActivationList )
102 grammars::URIGrammar lGrammar;
103 std::string::const_iterator lBegin ( aUri.begin() );
104 std::string::const_iterator lEnd ( aUri.end() );
105 boost::spirit::qi::phrase_parse ( lBegin , lEnd , lGrammar , boost::spirit::ascii::space , lUri );
107 catch (
const std::exception& aExc )
109 exception::FailedToParseURI lExc;
110 log ( lExc ,
"Failed to parse device URI " ,
Quote ( aUri ) );
114 log (
Info() ,
"URI " ,
Quote ( aUri ) ,
" parsed as:\n" , lUri );
119 std::stringstream lStr;
122 lStr <<
"\n > " << c.first <<
"\t: " << c.second.description;
124 exception::ProtocolDoesNotExist lExc;
125 log ( lExc ,
"Protocol " ,
Quote ( lUri.
mProtocol ) ,
" does not exists in map of creators. Options are:" , lStr.str() );
128 else if (lIt->second.userDefined)
130 std::vector<std::string>::const_iterator lIt2 = std::find(aUserClientActivationList.begin(), aUserClientActivationList.end(), lUri.
mProtocol);
132 if (lIt2 == aUserClientActivationList.end()) {
133 exception::ProtocolNotEnabled lExc;
134 log ( lExc ,
"Protocol " ,
Quote ( lUri.
mProtocol ) ,
" with user-defined client is not activated");
139 return lIt->second.creator->create ( aId , lUri );
A class to construct an IPbus client based on the protocol identifier specified NOTE!...
ClientFactory()
Default constructor This is private since only a single instance is to be created,...
static ClientFactory & getInstance()
Static method to retrieve the single instance of the class.
std::unordered_map< std::string, ClientInfo > mClientMap
Hash map associating a creator for a particular protocol with a file name.
static std::shared_ptr< ClientFactory > mInstance
The single instance of the class.
virtual ~ClientFactory()
Destructor.
std::shared_ptr< ClientInterface > getClient(const std::string &aId, const std::string &aUri)
Construct an IPbus client based on the protocol identifier specified.
Transport protocol to transfer an IPbus buffer via device file, using mmap.
Transport protocol to transfer an IPbus buffer via PCIe.
Transport protocol to transfer an IPbus buffer via TCP.
Transport protocol to transfer an IPbus buffer via UDP.
_Quote< T > Quote(const T &aT)
void log(FatalLevel &aFatal, const T0 &aArg0)
Function to add a log entry at Fatal level.
Struct to store a URI when parsed by boost spirit.
std::string mProtocol
The "protocol" part of a URI of the form "protocol://host:port/patha/pathb/blah.ext?...