cumbia-qtcontrols 1.x
Qt widgets on top of the cumbia C++ library
Public Types | Public Member Functions | List of all members
CuControlsFactoryPool Class Reference

this class, used in conjunction with CumbiaPool allows to connect to different control system frameworks within the same application. More...

#include <cucontrolsfactorypool.h>

Public Types

enum  Type { Reader = 0 , Writer }
 

Public Member Functions

 CuControlsFactoryPool ()
 
void registerImpl (const std::string &domain, const CuControlsReaderFactoryI &rf)
 register a reader factory for a domain: More...
 
void registerImpl (const std::string &domain, const CuControlsWriterFactoryI &wf)
 register a writer factory for a domain: More...
 
void setSrcPatterns (const std::string &domain, const std::vector< std::string > &regexps)
 set or change the source patterns (regular expressions) for the domain More...
 
void clearSrcPatterns (const std::string &domain)
 remove patterns for the given domain More...
 
CuControlsReaderFactoryIgetReadFactory (const std::string &domain) const
 returns the reader factory that was registered with the given domain More...
 
CuControlsWriterFactoryIgetWriteFactory (const std::string &domain) const
 returns the writer factory that was registered with the given domain More...
 
CuControlsReaderFactoryIgetRFactoryBySrc (const std::string &src) const
 uses the registered patterns to match the given source and return a CuControlsReaderFactoryI if a correspondence is found. More...
 
CuControlsWriterFactoryIgetWFactoryBySrc (const std::string &src) const
 uses the registered patterns to match the given source and return a CuControlsWriterFactoryI if a correspondence is found. More...
 
std::string guessDomainBySrc (const std::string &src) const
 given the source string, , tries to match it with the registered patterns in order to return the associated domain name More...
 
bool isEmpty () const
 returns true if both the reader factory map and the writer factory map are empty. More...
 
std::vector< std::string > getSrcPatternDomains () const
 
std::vector< std::string > getSrcPatterns (const std::string &domain) const
 

Detailed Description

this class, used in conjunction with CumbiaPool allows to connect to different control system frameworks within the same application.

Reader and writer factories can be registered with registerImpl, providing a name for the domain they refer to. The following code registers reader and writer factories for epics and tango, making it possible to connect to sources belonging to these two different systems within the same application:

ctrl_factory_pool.registerImpl("tango", CuTWriterFactory());
ctrl_factory_pool.registerImpl("tango", CuTReaderFactory());
m_ctrl_factory_pool.registerImpl("epics", CuEpReaderFactory());
m_ctrl_factory_pool.registerImpl("epics", CuEpWriterFactory());

The setSrcPatterns method can be used to insert rules so that CuControlsFactoryPool can distribute sources among the registered engine implementations according to their syntax pattern:

std::vector<std::string> epics_patterns, tango_patterns;
epics_patterns.push_back(".+:.+"); // e.g. control:ai1 (epics PV)
tango_patterns.push_back(".+/.+"); // e.g. test/device/1/double_scalar
tango_patterns.push_back(".+->.+"); // e.g. test/device/1->DevLong
// associate a domain ("tango" or "epics") to a specific pattern.
ctrl_factory_pool.setSrcPatterns("epics", epics_patterns);
ctrl_factory_pool.setSrcPatterns("tango", tango_patterns);

Member Enumeration Documentation

◆ Type

Enumerator
Reader 
Writer 

Constructor & Destructor Documentation

◆ CuControlsFactoryPool()

CuControlsFactoryPool::CuControlsFactoryPool ( )

the class constructor

example
Header file
class GenericClient : public QWidget
{
Q_OBJECT
public:
// ...
private:
CumbiaPool *cu_pool; // to use in combination with CuControlsFactoryPool
CuControlsFactoryPool m_ctrl_factory_pool;
this class, used in conjunction with CumbiaPool allows to connect to different control system framewo...
Definition: cucontrolsfactorypool.h:44

Member Function Documentation

◆ clearSrcPatterns()

void CuControlsFactoryPool::clearSrcPatterns ( const std::string &  domain)

remove patterns for the given domain

Parameters
domaina string with the domain name whose patterns are to be removed

◆ getReadFactory()

CuControlsReaderFactoryI * CuControlsFactoryPool::getReadFactory ( const std::string &  domain) const

returns the reader factory that was registered with the given domain

Parameters
domainthe name of the domain registered with registerImpl
Returns
the CuControlsReaderFactoryI implementation corresponding to the given domain, or NULL if the domain wasn't registered.

Referenced by getRFactoryBySrc().

◆ getRFactoryBySrc()

CuControlsReaderFactoryI * CuControlsFactoryPool::getRFactoryBySrc ( const std::string &  src) const

uses the registered patterns to match the given source and return a CuControlsReaderFactoryI if a correspondence is found.

Parameters
srcthe name of the source
Returns
a CuControlsReaderFactoryI implementation matching the source.
Domain matching.
If the source src contains the "://" substring, the domain is matched with the string preceding the substring, and the corresponding factory implementation is returned. Otherwise, the domain is guessed matching src against the regular expression patterns registered with setSrcPatterns.
Note
If no match is found, a random CuControlsReaderFactoryI implementation may be returned (the first stored in the std::map).

References getReadFactory(), and guessDomainBySrc().

◆ getSrcPatternDomains()

std::vector< std::string > CuControlsFactoryPool::getSrcPatternDomains ( ) const

◆ getSrcPatterns()

std::vector< std::string > CuControlsFactoryPool::getSrcPatterns ( const std::string &  domain) const

◆ getWFactoryBySrc()

CuControlsWriterFactoryI * CuControlsFactoryPool::getWFactoryBySrc ( const std::string &  src) const

uses the registered patterns to match the given source and return a CuControlsWriterFactoryI if a correspondence is found.

Parameters
srcthe name of the source
Returns
a CuControlsWriterFactoryI implementation matching the source.
Domain matching.
If the source src contains the "://" substring, the domain is matched with the string preceding the substring, and the corresponding factory implementation is returned. Otherwise, the domain is guessed matching src against the regular expression patterns registered with setSrcPatterns.
Note
If no match is found, a random CuControlsReaderFactoryI implementation may be returned (the first stored in the std::map).

References getWriteFactory(), and guessDomainBySrc().

◆ getWriteFactory()

CuControlsWriterFactoryI * CuControlsFactoryPool::getWriteFactory ( const std::string &  domain) const

returns the writer factory that was registered with the given domain

Parameters
domainthe name of the domain registered with registerImpl
Returns
the CuControlsWriterFactoryI implementation corresponding to the given domain, or NULL if the domain wasn't registered.

Referenced by getWFactoryBySrc().

◆ guessDomainBySrc()

std::string CuControlsFactoryPool::guessDomainBySrc ( const std::string &  src) const

given the source string, , tries to match it with the registered patterns in order to return the associated domain name

Parameters
srcthe source name
Returns
a string with the guessed domain or an empty string if no regexp match has been found.

Referenced by getRFactoryBySrc(), and getWFactoryBySrc().

◆ isEmpty()

bool CuControlsFactoryPool::isEmpty ( ) const

returns true if both the reader factory map and the writer factory map are empty.

Returns
true if both the reader factory map and the writer factory map are empty, false otherwise.

Referenced by QmlReaderBackend::init().

◆ registerImpl() [1/2]

void CuControlsFactoryPool::registerImpl ( const std::string &  domain,
const CuControlsReaderFactoryI rf 
)

register a reader factory for a domain:

Parameters
domaina string identifying a domain, e.g. "tango" or "epics"
rfan instance of an object implementing CuControlsReaderFactoryI, such as CuTReaderFactory or CuEpReaderFactory

References CuControlsReaderFactoryI::clone().

Referenced by main().

◆ registerImpl() [2/2]

void CuControlsFactoryPool::registerImpl ( const std::string &  domain,
const CuControlsWriterFactoryI wf 
)

register a writer factory for a domain:

Parameters
domaina string identifying a domain, e.g. "tango" or "epics"
wfan instance of an object implementing CuControlsWriterFactoryI, such as CuTWriterFactory or CuEpWriterFactory

References CuControlsWriterFactoryI::clone().

◆ setSrcPatterns()

void CuControlsFactoryPool::setSrcPatterns ( const std::string &  domain,
const std::vector< std::string > &  regex_patt 
)

set or change the source patterns (regular expressions) for the domain

Parameters
domaina string identifying a domain, e.g. "tango" or "epics"
regex_patta vector of string with the set of regular expressions that are used to match and assign sources to engines.

Referenced by main().


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