18 #define DATASVC_MULTISTORESVC_CPP 50 struct Partition final {
85 enum { no_type = 0, address_type = 1, object_type = 2 };
101 template <
typename... Args,
typename... UArgs>
104 return m_current.dataProvider ? ( m_current.dataProvider->*pmf )( std::forward<UArgs>(
args )... )
107 template <
typename... Args,
typename... UArgs>
110 return m_current.dataManager ? ( m_current.dataManager->*pmf )( std::forward<UArgs>(
args )... )
174 for (
auto& i : m_partitions ) {
175 i.second.dataManager->clearStore().
ignore();
177 if ( m_root.root.object ) {
178 switch ( m_root.type ) {
180 m_root.root.address->release();
183 m_root.root.object->release();
186 m_root.root.object =
nullptr;
189 m_root.type = no_type;
208 if ( m_root.root.object ) {
209 switch ( m_root.type ) {
211 m_root.root.address->release();
214 m_root.root.object->release();
219 m_root.type = object_type;
220 m_root.root.object = pObj;
222 return activate( m_defaultPartition );
229 if ( m_root.root.object ) {
230 switch ( m_root.type ) {
232 m_root.root.address->release();
235 m_root.root.object->release();
240 m_root.type = address_type;
241 m_root.root.address = pAddr;
242 if ( m_root.root.address ) {
243 m_root.root.address->
addRef();
245 return activate( m_defaultPartition );
252 m_dataLoader = pDataLoader;
253 if ( m_dataLoader ) m_dataLoader->
setDataProvider( dpsvc ? dpsvc :
this );
254 for (
auto& i : m_partitions ) {
255 i.second.dataManager->setDataLoader( m_dataLoader.
get() ).ignore();
447 return create( nam, typ, pPartition );
452 if (
get( nam, pPartition ).isSuccess() )
return PARTITION_EXISTS;
454 auto isvc = serviceLocator()->service<
IService>( typ );
455 if ( !isvc )
return NO_INTERFACE;
458 if ( !dataMgr || !dataProv )
return NO_INTERFACE;
459 m_partitions.
emplace( nam, Partition{dataProv, dataMgr, nam} );
466 auto i = m_partitions.
find( nam );
467 if ( i == m_partitions.
end() )
return PARTITION_NOT_PRESENT;
468 if ( i->second.dataManager == m_current.dataManager ) {
469 m_current = Partition();
471 i->second.dataManager->clearStore().ignore();
472 m_partitions.
erase( i );
480 if ( !provider )
return NO_INTERFACE;
482 [&]( Partitions::const_reference p ) {
return p.second.dataProvider == provider; } );
483 if ( i ==
std::end( m_partitions ) )
return PARTITION_NOT_PRESENT;
484 i->second.dataManager->clearStore().ignore();
485 m_partitions.
erase( i );
492 auto i = m_partitions.
find( nam );
493 if ( i != m_partitions.
end() ) {
494 m_current = i->second;
497 m_current = Partition();
498 return PARTITION_NOT_PRESENT;
505 m_current = Partition();
506 if ( !provider )
return NO_INTERFACE;
508 [&]( Partitions::const_reference p ) {
return p.second.dataProvider == provider; } );
509 if ( i ==
std::end( m_partitions ) )
return PARTITION_NOT_PRESENT;
510 m_current = i->second;
517 auto i = m_partitions.
find( nam );
518 if ( i != m_partitions.
end() ) {
519 pPartition = i->second.dataProvider;
522 pPartition =
nullptr;
523 return PARTITION_NOT_PRESENT;
529 if ( m_current.dataProvider ) {
530 nam = m_current.name;
531 pPartition = m_current.dataProvider;
535 pPartition =
nullptr;
536 return NO_ACTIVE_PARTITION;
542 m_addrCreator = service( m_loader,
true );
543 if ( !m_addrCreator ) {
544 error() <<
"Failed to retrieve data loader " 545 <<
"\"" << m_loader <<
"\"" <<
endmsg;
549 auto dataLoader = service<IConversionSvc>( m_loader, true );
551 error() <<
"Failed to retrieve data loader " 552 <<
"\"" << m_loader <<
"\"" <<
endmsg;
555 auto sc = setDataLoader( dataLoader.get() );
556 if ( !sc.isSuccess() ) {
557 error() <<
"Failed to set data loader " 558 <<
"\"" << m_loader <<
"\"" <<
endmsg;
565 m_addrCreator.
reset();
566 m_dataLoader.
reset();
576 sc = makePartitions();
578 error() <<
"Failed to connect to all store partitions." <<
endmsg;
581 return attachServices();
589 error() <<
"Enable to reinitialize base class" <<
endmsg;
593 sc = attachServices();
595 error() <<
"Failed to attach necessary services." <<
endmsg;
598 sc = makePartitions();
600 error() <<
"Failed to connect to store partitions." <<
endmsg;
610 setDataLoader(
nullptr ).
ignore();
611 clearStore().ignore();
612 clearPartitions().ignore();
613 m_current = Partition();
621 using extends::extends;
626 setDataLoader(
nullptr ).ignore();
627 resetPreLoad().ignore();
628 clearStore().ignore();
629 clearPartitions().ignore();
636 for (
auto& i : m_partitions ) {
638 switch ( m_root.type ) {
640 if ( m_root.root.address ) {
642 ADDRESS* p = m_root.root.address;
645 sc = i.second.dataManager->setRoot( m_root.path, pAdd );
650 if ( m_root.root.object ) {
651 if ( m_root.root.object->clID() == CLID_DataObject ) {
652 sc = i.second.dataManager->setRoot( m_root.path,
new DataObject() );
668 for (
auto& i : m_partitions ) i.second.dataManager->clearStore().
ignore();
669 m_partitions.clear();
678 clearPartitions().ignore();
679 for (
auto part : m_partitionDefs ) {
680 for (
auto attrib : Parser(
std::move( part ) ) ) {
681 switch (::
toupper( attrib.tag[0] ) ) {
690 STATUS sc = create( nam, typ );
692 if ( m_defaultPartition.empty() ) m_defaultPartition = nam;
virtual StatusCode objectParent(const DataObject *pObject, IRegistry *&refpParent)=0
IDataManagerSvc: Explore the object store: retrieve the object's parent.
Parse attribute strings allowing iteration over the various attributes.
STATUS objectLeaves(const IRegistry *pObject, std::vector< IRegistry * > &leaves) override
Explore the object store: retrieve all leaves attached to the object.
StatusCode initialize() override
STATUS clearSubTree(CSTR &path) override
Remove all data objects below the sub tree identified.
STATUS unregisterObject(CSTR &path) override
Unregister object from the data store.
STATUS removePreLoadItem(CSTR &item) override
Add an item to the preload list.
STATUS preLoad() override
load all preload items of the list
Partitions m_partitions
Datastore partitions.
virtual const CLID & clID() const =0
Retrieve class information from link.
STATUS unlinkObject(CSTR &path) override
Remove a link to another object.
STATUS finalize() override
Service initialisation.
STATUS registerAddress(CSTR &path, ADDRESS *pAddr) override
IDataManagerSvc: Register object address with the data store.
StatusCode finalize() override
Implementation of property with value of concrete type.
virtual StatusCode addPreLoadItem(const DataStoreItem &item)=0
Add an item to the preload list.
const std::string & rootName() const override
Name for root Event.
CLID rootCLID() const override
IDataManagerSvc: Accessor for root event CLID.
STATUS updateObject(OBJECT *pObj) override
Update object.
virtual StatusCode createAddress(long svc_type, const CLID &clid, const std::string *par, const unsigned long *ipar, IOpaqueAddress *&refpAddress)=0
Create a Generic address using explicit arguments to identify a single object.
virtual StatusCode clearSubTree(const std::string &sub_path)=0
Remove all data objects below the sub tree identified by its full path name.
Invalid root path object cannot be retrieved or stored.
STATUS objectParent(const OBJECT *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
STATUS findObject(OBJECT *parent, int item, OBJECT *&pObject) override
Find object in the data store.
bool isSuccess() const
Test for a status code of SUCCESS.
virtual StatusCode setDataProvider(IDataProviderSvc *pService)=0
Set Data provider service.
virtual StatusCode preLoad()=0
Load all preload items of the list.
STATUS registerObject(CSTR &parent, CSTR &obj, OBJECT *pObj) override
Register object with the data store.
virtual StatusCode resetPreLoad()=0
Clear the preload list.
STATUS unregisterAddress(OBJECT *pParent, CSTR &path) override
IDataManagerSvc: Unregister object address from the data store.
STATUS unregisterObject(CSTR &parent, CSTR &obj) override
Unregister object from the data store.
STATUS unlinkObject(OBJECT *from, CSTR &objPath) override
Remove a link to another object.
STATUS create(CSTR &nam, CSTR &typ, IInterface *&pPartition) override
Create a partition object. The name identifies the partition uniquely.
virtual StatusCode unregisterAddress(const std::string &fullPath)=0
Unregister object address from the data store.
STATUS findObject(CSTR &parent, int item, OBJECT *&pObject) override
Find object in the data store.
STATUS reinitialize() override
Service initialisation.
Data provider interface definition.
STATUS removePreLoadItem(const DataStoreItem &item) override
Remove an item from the preload list.
virtual const std::string * par() const =0
Retrieve String parameters.
Description of the DataStoreItem class.
STATUS linkObject(OBJECT *from, CSTR &objPath, OBJECT *to) override
Add a link to another object.
SmartIF< IConversionSvc > m_dataLoader
Pointer to data loader service.
STATUS traverseSubTree(CSTR &path, AGENT *pAgent) override
Analyze by traversing all data objects below the sub tree.
#define DECLARE_COMPONENT(type)
STATUS create(CSTR &nam, CSTR &typ) override
Create a partition object. The name identifies the partition uniquely.
STATUS linkObject(CSTR &from, CSTR &objPath, OBJECT *to) override
Add a link to another object.
STATUS setDataLoader(IConversionSvc *pDataLoader, IDataProviderSvc *dpsvc=nullptr) override
IDataManagerSvc: Pass a default data loader to the service.
STATUS updateObject(CSTR &parent, CSTR &updatePath) override
Update object.
std::vector< std::string > PartitionDefs
virtual StatusCode removePreLoadItem(const DataStoreItem &item)=0
Remove an item from the preload list.
TYPE * get() const
Get interface pointer.
STATUS updateObject(OBJECT *parent, CSTR &updatePath) override
Update object.
STATUS makePartitions()
Create all partitions according to job options.
STATUS retrieveObject(CSTR &path, OBJECT *&pObj) override
Retrieve object identified by its full path from the data store.
STATUS unlinkObject(IRegistry *from, CSTR &objPath) override
Remove a link to another object.
STATUS unregisterAddress(IRegistry *pParent, CSTR &path) override
IDataManagerSvc: Unregister object address from the data store.
virtual StatusCode findObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Find object identified by its directory entry.
STATUS setRoot(std::string path, OBJECT *pObj) override
Initialize data store for new event by giving new event path and root object.
virtual const unsigned long * ipar() const =0
Access to generic link parameters.
virtual StatusCode traverseTree(IDataStoreAgent *pAgent)=0
Analyse by traversing all data objects in the data store.
STATUS addPreLoadItem(const DataStoreItem &item) override
Add an item to the preload list.
STATUS findObject(IRegistry *parent, CSTR &path, OBJECT *&pObj) override
Find object identified by its full path in the data store.
virtual StatusCode unregisterObject(const std::string &fullPath)=0
Unregister object from the data store.
STATUS retrieveObject(IRegistry *parent, CSTR &path, OBJECT *&pObj) override
Retrieve object from data store.
virtual StatusCode linkObject(IRegistry *from, const std::string &objPath, DataObject *toObj)=0
Add a link to another object.
General service interface definition.
STATUS clearSubTree(OBJECT *pObject) override
Remove all data objects below the sub tree identified.
This class is used for returning status codes from appropriate routines.
virtual StatusCode updateObject(IRegistry *pDirectory)=0
Update object identified by its directory entry.
STATUS activate(CSTR &nam) override
Activate a partition object. The name identifies the partition uniquely.
Definition of the basic interface.
STATUS registerObject(CSTR &path, OBJECT *pObj) override
Register object with the data store.
The IRegistry represents the entry door to the environment any data object residing in a transient da...
STATUS findObject(CSTR &parent, CSTR &path, OBJECT *&pObj) override
Find object in the data store.
virtual long svcType() const =0
Retrieve service type.
StatusCode reinitialize() override
STATUS retrieveObject(CSTR &parent, int item, OBJECT *&pObj) override
Retrieve object from data store.
STATUS unregisterObject(OBJECT *pObj, CSTR &path) override
Unregister object from the data store.
STATUS linkObject(CSTR &fullPath, OBJECT *to) override
Add a link to another object.
STATUS clearPartitions()
Clear all partitions.
unsigned int CLID
Class ID definition.
STATUS call_(STATUS(IDataProviderSvc::*pmf)(Args...), UArgs &&...args)
Partition m_current
Current partition.
STATUS unregisterAddress(CSTR &path) override
IDataManagerSvc: Unregister object address from the data store.
STATUS retrieveObject(OBJECT *parent, CSTR &path, OBJECT *&pObj) override
Retrieve object from data store.
STATUS preparePartitions()
Prepare partition for usage.
STATUS objectLeaves(const OBJECT *pObject, std::vector< IRegistry * > &leaves) override
Explore the object store: retrieve all leaves attached to the object.
STATUS unregisterObject(OBJECT *pObj) override
Unregister object from the data store.
STATUS setRoot(std::string path, ADDRESS *pAddr) override
Initialize data store for new event by giving new event path and address of root object.
virtual StatusCode objectLeaves(const DataObject *pObject, std::vector< IRegistry * > &refLeaves)=0
Explore the object store: retrieve all leaves attached to the object The object is identified by its ...
STATUS resetPreLoad() override
Clear the preload list.
STATUS unregisterObject(OBJECT *pObj, int item) override
Unregister object from the data store.
STATUS initialize() override
Service initialisation.
Generic data agent interface.
STATUS drop(CSTR &nam) override
Drop a partition object. The name identifies the partition uniquely.
Base class used to extend a class implementing other interfaces.
virtual StatusCode unlinkObject(IRegistry *from, const std::string &objPath)=0
Remove a link to another object.
STATUS activate(IInterface *pPartition) override
Activate a partition object.
STATUS addPreLoadItem(CSTR &item) override
Add an item to the preload list.
SmartIF< IAddressCreator > m_addrCreator
Reference to address creator.
STATUS registerObject(OBJECT *parent, CSTR &obj, OBJECT *pObj) override
Register object with the data store.
StatusCode activePartition(std::string &nam, IInterface *&pPartition) const override
Access the active partition object.
STATUS retrieveObject(OBJECT *parent, int item, OBJECT *&pObj) override
Retrieve object from data store.
STATUS findObject(CSTR &path, OBJECT *&pObj) override
Find object identified by its full path in the data store.
STATUS retrieveObject(CSTR &parent, CSTR &path, OBJECT *&pObj) override
Retrieve object from data store.
STATUS linkObject(IRegistry *from, CSTR &objPath, OBJECT *to) override
Add a link to another object.
STATUS updateObject(CSTR &path) override
Update object.
void reset(TYPE *ptr=nullptr)
Set the internal pointer to the passed one disposing of the old one.
virtual StatusCode registerAddress(const std::string &fullPath, IOpaqueAddress *pAddress)=0
Register object address with the data store.
Opaque address interface definition.
STATUS unregisterObject(CSTR &parent, int obj) override
Unregister object from the data store.
virtual StatusCode registerObject(const std::string &fullPath, DataObject *pObject)=0
Register object with the data store.
STATUS traverseSubTree(OBJECT *pObject, AGENT *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects below the sub tree.
virtual StatusCode traverseSubTree(const std::string &sub_path, IDataStoreAgent *pAgent)=0
Analyse by traversing all data objects below the sub tree identified by its full path name...
STATUS call_(STATUS(IDataManagerSvc::*pmf)(Args...), UArgs &&...args)
std::map< std::string, Partition > Partitions
A DataObject is the base class of any identifiable object on any data store.
STATUS clearStore() override
IDataManagerSvc: Remove all data objects in the data store.
STATUS registerObject(CSTR &parent, int item, OBJECT *pObj) override
Register object with the data store.
STATUS registerAddress(OBJECT *parent, CSTR &path, ADDRESS *pAddr) override
IDataManagerSvc: Register object address with the data store.
STATUS registerAddress(IRegistry *parent, CSTR &path, ADDRESS *pAdd) override
IDataManagerSvc: Register object address with the data store.
STATUS updateObject(IRegistry *pDirectory) override
Update object identified by its directory entry.
STATUS unlinkObject(CSTR &from, CSTR &objPath) override
Remove a link to another object.
STATUS findObject(OBJECT *parent, CSTR &path, OBJECT *&pObject) override
Find object in the data store.
void toupper(std::string &s)
STATUS drop(IInterface *pPartition) override
Drop a partition object. The name identifies the partition uniquely.
STATUS traverseTree(AGENT *pAgent) override
IDataManagerSvc: Analyze by traversing all data objects in the data store.
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
STATUS objectParent(const IRegistry *pObject, IRegistry *&refpParent) override
IDataManagerSvc: Explore the object store: retrieve the object's parent.
STATUS registerObject(OBJECT *parent, int obj, OBJECT *pObj) override
Register object with the data store.
~MultiStoreSvc() override
Standard Destructor.
virtual unsigned long addRef()=0
Add reference to object.
virtual StatusCode retrieveObject(IRegistry *pDirectory, const std::string &path, DataObject *&pObject)=0
Retrieve object identified by its directory entry.