| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# ServiceManager Class Reference

`#include <ServiceManager.h>`

Inheritance diagram for ServiceManager:

[legend]
Collaboration diagram for ServiceManager:

[legend]
List of all members.

## Detailed Description

The ServiceManager class is in charge of the cretion of concrete instances of Services.

The ApplicationMgr delegates the creation and bookkeeping of services to the ServiceManager. In order to be able to create services from which it is not know the concrete type it requires that the services has been declared in one of 3 possible ways: an abstract static creator function, a dynamic link library or an abstract factory reference.

Author:
  Pere Mato

Definition at line 32 of file ServiceManager.h.

## Public Types
typedef std::list< IService * > | ListSvc
typedef std::list< std::pair< IService *, int > > | PListSvc
typedef std::map< std::string, std::string > | MapType
typedef std::map< std::string, ISvcFactory * > | MapFactory
## Public Member Functions
| ServiceManager (IInterface *iface)
| default creator
virtual | ~ServiceManager ()
| virtual destructor
virtual unsigned long | addRef ()
| implmentation of IInterface::addRef
virtual unsigned long | release ()
| implmentation of IInterface::release
virtual StatusCode | queryInterface (const InterfaceID &iid, void **pinterface)
| implementation of IInterface::queryInterface
virtual StatusCode | getService (const std::string &name, IService *&svc)
| implementation of ISvcLocation::getService
virtual StatusCode | getService (const std::string &name, const InterfaceID &iid, IInterface *&pinterface)
| implementation of ISvcLocation::getService
virtual StatusCode | getService (const std::string &name, IService *&svc, bool createIf)
| implementation of ISvcLocation::getService
virtual const std::list< IService * > & | getServices () const
| Return the list of Services.
virtual std::list< IService * > | getActiveServices () const
virtual bool | existsService (const std::string &name) const
| implementation of ISvcLocation::existsService
virtual StatusCode | addService (IService *svc, int prio)
| implementation of ISvcManager::addService
virtual StatusCode | addService (const std::string &typ, const std::string &nam, int prio)
| implementation of ISvcManager::addService
virtual StatusCode | removeService (IService *svc)
| implementation of ISvcManager::removeService
virtual StatusCode | removeService (const std::string &nam)
| implementation of ISvcManager::removeService
virtual StatusCode | declareSvcFactory (const ISvcFactory &factory, const std::string &svctype)
| implementation of ISvcManager::declareSvcFactory
virtual StatusCode | declareSvcType (const std::string &svcname, const std::string &svctype)
| implementation of ISvcManager::declareSvcType
virtual StatusCode | createService (const std::string &svctype, const std::string &svcname, IService *&svc)
| implementation of ISvcManager::createService
virtual StatusCode | getFactory (const std::string &svctype, const ISvcFactory *&fac) const
| implementation of IAlgManager::getFactory
virtual StatusCode | initializeServices ()
| implementation of ISvcManager::initializeServices
virtual StatusCode | startServices ()
| implementation of ISvcManager::startServices
virtual StatusCode | stopServices ()
| implementation of ISvcManager::stopServices
virtual StatusCode | finalizeServices ()
| implementation of ISvcManager::finalizeServices
virtual StatusCode | reinitializeServices ()
| implementation of ISvcManager::reinitializeServices
virtual StatusCode | restartServices ()
| implementation of ISvcManager::restartServices
virtual int | getPriority (const std::string &name) const
| manage priorties of services
virtual StatusCode | setPriority (const std::string &name, int pri)
## Private Member Functions
IMessageSvc * | msgSvc ()
| access the message service
StatusCode | makeService (const std::string &name, IService *&svc)
| create a service and initialize it
StatusCode | removeActiveService (IService *svc)
StatusCode | removeListService (IService *svc)
## Private Attributes
unsigned long | m_refcount
| Reference counter.
ListSvc | m_listsvc
| List of service maintained by ServiceManager.
PListSvc | m_activesvc
| List of "active" service maintained by ServiceManager.
MapType | m_maptype
| Map of service name and service type.
MapFactory | m_mapfactory
| Map of pairs of factory reference and service name.
IInterface * | m_pOuter
| Interface hub reference (ApplicationMgr).
ISvcLocator * | m_svclocator
| Service locator.
IMessageSvc * | m_msgsvc
| Pointer to the message service if it exists.
SmartIF< IStateful > | m_statemgr
| Pointer to the state machine.

## Member Typedef Documentation

typedef std::list<IService*> ServiceManager::ListSvc

Definition at line 36 of file ServiceManager.h.

typedef std::list<std::pair<IService*,int> > ServiceManager::PListSvc

Definition at line 37 of file ServiceManager.h.

typedef std::map<std::string, std::string > ServiceManager::MapType

Definition at line 38 of file ServiceManager.h.

typedef std::map<std::string, ISvcFactory*> ServiceManager::MapFactory

Definition at line 39 of file ServiceManager.h.

## Constructor & Destructor Documentation

ServiceManager::ServiceManager | ( | IInterface * | iface | ) |

default creator

Definition at line 17 of file ServiceManager.cpp.

References m_msgsvc, m_pOuter, m_refcount, and m_svclocator.

    00017                                                :
    00018   m_statemgr(iface)
    00019 {
    00020   m_refcount   = 1;
    00021   m_pOuter = iface;
    00022   m_svclocator = (ISvcLocator*)this;
    00023   m_msgsvc     = 0;
    00024 }

ServiceManager::~ServiceManager | ( |  | ) | `[virtual]`

virtual destructor

Definition at line 27 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::end(), m_listsvc, m_msgsvc, and IInterface::release().

    00027                                 {
    00028   if( m_msgsvc ) m_msgsvc->release();
    00029   //-- inform the orphan services that I am gone....
    00030   for (ListSvc::const_iterator it = m_listsvc.begin(); it != m_listsvc.end(); it++ ) {
    00031     (*it)->setServiceManager(0);
    00032   }
    00033 }

## Member Function Documentation

unsigned long ServiceManager::addRef | ( |  | ) | `[virtual]`

implmentation of IInterface::addRef

Implements IInterface.

Definition at line 36 of file ServiceManager.cpp.

References m_refcount.

Referenced by queryInterface().

    00036                                      {
    00037   m_refcount++;
    00038   return m_refcount;
    00039 }

unsigned long ServiceManager::release | ( |  | ) | `[virtual]`

implmentation of IInterface::release

Implements IInterface.

Definition at line 42 of file ServiceManager.cpp.

References count(), and m_refcount.

Referenced by ApplicationMgr::~ApplicationMgr().

    00042                                       {
    00043   unsigned long count = --m_refcount;
    00044   if( count <= 0) {
    00045     delete this;
    00046   }
    00047   return count;
    00048 }

StatusCode ServiceManager::queryInterface | ( | const InterfaceID & | iid,
|  | void ** | pinterface |
| ) |  |  | `[virtual]`

implementation of IInterface::queryInterface

Implements IInterface.

Definition at line 51 of file ServiceManager.cpp.

References addRef(), IID_IInterface, IID_ISvcLocator, IID_ISvcManager, m_pOuter, IInterface::queryInterface(), and StatusCode::SUCCESS.

    00053 {
    00054   if( iid == IID_IInterface ) {
    00055     *pinterface = (IInterface*)this;
    00056     addRef();
    00057     return StatusCode::SUCCESS;
    00058   }
    00059   else if ( iid == IID_ISvcLocator ) {
    00060     *pinterface = (ISvcLocator*)this;
    00061     addRef();
    00062     return StatusCode::SUCCESS;
    00063   }
    00064   else if ( iid == IID_ISvcManager ) {
    00065     *pinterface = (ISvcManager*)this;
    00066     addRef();
    00067     return StatusCode::SUCCESS;
    00068   }
    00069   else {
    00070     return m_pOuter->queryInterface(iid, pinterface);
    00071   }
    00072 }

StatusCode ServiceManager::getService | ( | const std::string & | name,
|  | IService *& | svc |
| ) |  |  | `[virtual]`

implementation of ISvcLocation::getService

Implements ISvcLocator.

Definition at line 75 of file ServiceManager.cpp.

References name.

Referenced by addService(), getService(), msgSvc(), and removeService().

    00077 {
    00078   return getService(name, svc, true);
    00079 }

StatusCode ServiceManager::getService | ( | const std::string & | name,
|  | const InterfaceID & | iid,
|  | IInterface *& | pinterface |
| ) |  |  | `[virtual]`

implementation of ISvcLocation::getService

Implements ISvcLocator.

Definition at line 81 of file ServiceManager.cpp.

References getService(), StatusCode::isSuccess(), name, and IInterface::queryInterface().

    00084 {
    00085   IService*  svc;
    00086   StatusCode status = getService( name, svc, false );
    00087   if( status.isSuccess() ) {
    00088     // Service found. So now get the right interface
    00089     status = svc->queryInterface( iid, (void**)&pinterface );
    00090   }
    00091   return status;
    00092 }

StatusCode ServiceManager::getService | ( | const std::string & | name,
|  | IService *& | svc,
|  | bool | createIf |
| ) |  |  | `[virtual]`

implementation of ISvcLocation::getService

Implements ISvcLocator.

Definition at line 141 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), Gaudi::StateMachine::CONFIGURED, std::list< _Tp, _Alloc >::end(), endreq(), MSG::ERROR, StatusCode::FAILURE, IService::interfaceID(), m_listsvc, m_svclocator, makeService(), msgSvc(), ListItem::name(), name, IInterface::queryInterface(), StatusCode::SUCCESS, and ListItem::type().

    00144 {
    00145   ListItem item(nam);
    00146   const std::string& name = item.name();
    00147
    00148   StatusCode sc(StatusCode::FAILURE);
    00149   ListSvc::iterator it(m_listsvc.begin());
    00150   for (; it != m_listsvc.end(); ++it ) {
    00151     if( (*it)->name() == name ) {
    00152       svc = *it;
    00153       break;
    00154     }
    00155   }
    00156
    00157   if (it !=  m_listsvc.end()) {
    00158     if (createIf && (*it)->FSMState() == Gaudi::StateMachine::CONFIGURED ) {
    00159       MsgStream log(msgSvc(), "ServiceManager");
    00160       log << MSG::ERROR
    00161           << "Initialization loop detected when creating service \"" << name
    00162           << "\""
    00163           << endreq;
    00164       sc = StatusCode::FAILURE;
    00165     } else {
    00166       sc = StatusCode::SUCCESS;
    00167     }
    00168   } else {
    00169     // Service not found. The user may be interested in one of the interfaces
    00170     // of the application manager itself
    00171     if( name == "ApplicationMgr" ||
    00172         name == "APPMGR" ||
    00173         name == "" ) {
    00174       sc = m_svclocator->queryInterface( IService::interfaceID(), (void**)&svc );
    00175       if( svc ) svc->release(); // Do not increase the reference count
    00176     } else if ( createIf ){
    00177       //last resort: we try to create the service
    00178       if ( item.name() != item.type() ) {
    00179         // if we were asked for a "ServiceType/ServiceName", we pass the string
    00180         // directly to makeService
    00181         sc = makeService(nam, svc);
    00182       } else {
    00183         // the user did not specified both type and name
    00184         sc = makeService(name, svc);
    00185       }
    00186     }
    00187   }
    00188
    00189   return sc;
    00190 }

const std::list< IService * > & ServiceManager::getServices | ( |  | ) | const`[virtual]`

Return the list of Services.

Implements ISvcLocator.

Definition at line 193 of file ServiceManager.cpp.

References m_listsvc.

    00195 {
    00196   return m_listsvc;
    00197 }

std::list< IService * > ServiceManager::getActiveServices | ( |  | ) | const`[virtual]`

Definition at line 200 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::end(), m_activesvc, and std::list< _Tp, _Alloc >::push_back().

    00202 {
    00203   std::list<IService*> asvcs;
    00204   for (PListSvc::const_iterator itr = m_activesvc.begin();
    00205        itr != m_activesvc.end(); ++itr) {
    00206     asvcs.push_back( itr->first );
    00207   }
    00208   return asvcs;
    00209 }

bool ServiceManager::existsService | ( | const std::string & | name | ) | const`[virtual]`

implementation of ISvcLocation::existsService

Implements ISvcLocator.

Definition at line 213 of file ServiceManager.cpp.

References name.

Referenced by addService(), and createService().

    00215 {
    00216   ListSvc::const_iterator it;
    00217   for (it = m_listsvc.begin(); it != m_listsvc.end(); it++ ) {
    00218     if( name == (*it)->name() ) {
    00219       return true;
    00220     }
    00221   }
    00222   return false;
    00223 }

StatusCode ServiceManager::addService | ( | IService * | svc,
|  | int | prio |
| ) |  |  | `[virtual]`

implementation of ISvcManager::addService

Implements ISvcManager.

Definition at line 226 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::end(), StatusCode::ignore(), std::list< _Tp, _Alloc >::insert(), m_activesvc, std::make_pair(), removeActiveService(), and StatusCode::SUCCESS.

Referenced by ApplicationMgr::addMultiSvc(), addService(), ApplicationMgr::configure(), ApplicationMgr::decodeCreateSvcNameList(), ApplicationMgr::decodeExtSvcNameList(), makeService(), and setPriority().

    00228 {
    00229   PListSvc::iterator it;
    00230   // remove it if already in the list
    00231   removeActiveService( svc ).ignore();
    00232   // insert in the right place in the list
    00233   for( it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00234     if( (*it).second > prio )  break;
    00235   }
    00236   m_activesvc.insert(it, std::make_pair(svc, prio));
    00237   return StatusCode::SUCCESS;
    00238 }

StatusCode ServiceManager::addService | ( | const std::string & | typ,
|  | const std::string & | nam,
|  | int | prio |
| ) |  |  | `[virtual]`

implementation of ISvcManager::addService

Implements ISvcManager.

Definition at line 241 of file ServiceManager.cpp.

References addService(), createService(), existsService(), getService(), Gaudi::StateMachine::INITIALIZED, StatusCode::isSuccess(), std::basic_string< _CharT, _Traits, _Alloc >::length(), m_maptype, m_statemgr, name, Gaudi::StateMachine::RUNNING, IService::sysInitialize(), and IService::sysStart().

    00244 {
    00245   StatusCode sc;
    00246   IService* svc;
    00247   if( existsService(name) ) {
    00248     sc = getService(name, svc);
    00249   } else {
    00250     if( type.length() == 0 ) {
    00251       // find out if name is registered with a type
    00252       MapType::iterator it = m_maptype.find( name );
    00253       if( it != m_maptype.end() ) {
    00254         sc = createService( (*it).second, name, svc );
    00255       } else {
    00256         sc = createService( name, name, svc );
    00257       }
    00258     } else {
    00259       sc = createService( type, name, svc );
    00260     }
    00261
    00262     if (sc.isSuccess() && m_statemgr->targetFSMState() >= Gaudi::StateMachine::INITIALIZED) {
    00263       sc = svc->sysInitialize();
    00264       if (sc.isSuccess() && m_statemgr->targetFSMState() >= Gaudi::StateMachine::RUNNING) {
    00265         sc = svc->sysStart();
    00266       }
    00267     }
    00268
    00269   }
    00270   if( sc.isSuccess() ) {
    00271     return addService( svc, prio );
    00272   }
    00273   else {
    00274     return sc;
    00275   }
    00276 }

StatusCode ServiceManager::removeService | ( | IService * | svc | ) | `[virtual]`

implementation of ISvcManager::removeService

Implements ISvcManager.

Definition at line 279 of file ServiceManager.cpp.

References StatusCode::ignore(), removeActiveService(), removeListService(), and StatusCode::SUCCESS.

Referenced by ApplicationMgr::finalize(), makeService(), and removeService().

    00281 {
    00282
    00283   removeActiveService(svc).ignore();
    00284   removeListService(svc).ignore();
    00285
    00286   return StatusCode(StatusCode::SUCCESS,true);
    00287 }

StatusCode ServiceManager::removeService | ( | const std::string & | nam | ) | `[virtual]`

implementation of ISvcManager::removeService

Implements ISvcManager.

Definition at line 322 of file ServiceManager.cpp.

References StatusCode::FAILURE, getService(), and removeService().

    00324 {
    00325   IService* svc;
    00326   if( getService(nam, svc).isSuccess() ) return removeService(svc);
    00327   else return StatusCode::FAILURE;
    00328 }

StatusCode ServiceManager::declareSvcFactory | ( | const ISvcFactory & | factory,
|  | const std::string & | svctype |
| ) |  |  | `[virtual]`

implementation of ISvcManager::declareSvcFactory

Implements ISvcManager.

Definition at line 331 of file ServiceManager.cpp.

References endreq(), StatusCode::FAILURE, std::pair< _T1, _T2 >::first, m_mapfactory, msgSvc(), std::pair< _T1, _T2 >::second, StatusCode::SUCCESS, and MSG::WARNING.

    00334 {
    00335
    00336   std::pair<MapFactory::iterator, bool> p;
    00337   p = m_mapfactory.insert(MapFactory::value_type( svctype, (ISvcFactory*)&factory) );
    00338   if( p.second == false) {
    00339     MsgStream log(msgSvc(), "ServiceManager");
    00340     log << MSG::WARNING << "Service factory for type " << svctype << " already declared" << endreq;
    00341     m_mapfactory.erase ( p.first );
    00342     p = m_mapfactory.insert(MapFactory::value_type( svctype, (ISvcFactory*)&factory) );
    00343     if( p.second == false) return StatusCode::FAILURE;
    00344   }
    00345   return StatusCode::SUCCESS;
    00346 }

StatusCode ServiceManager::declareSvcType | ( | const std::string & | svcname,
|  | const std::string & | svctype |
| ) |  |  | `[virtual]`

implementation of ISvcManager::declareSvcType

Implements ISvcManager.

Definition at line 349 of file ServiceManager.cpp.

References StatusCode::FAILURE, std::pair< _T1, _T2 >::first, m_maptype, std::make_pair(), std::pair< _T1, _T2 >::second, and StatusCode::SUCCESS.

Referenced by ApplicationMgr::declareMultiSvcType(), and ApplicationMgr::decodeExtSvcNameList().

    00352 {
    00353   std::pair<MapType::iterator, bool> p = m_maptype.insert(std::make_pair(svcname, svctype));
    00354   if( p.second == false) {
    00355     m_maptype.erase ( p.first );
    00356     p = m_maptype.insert(std::make_pair(svcname, svctype) );
    00357     if( p.second == false) return StatusCode::FAILURE;
    00358   }
    00359   return StatusCode::SUCCESS;
    00360 }

StatusCode ServiceManager::createService | ( | const std::string & | svctype,
|  | const std::string & | svcname,
|  | IService *& | svc |
| ) |  |  | `[virtual]`

implementation of ISvcManager::createService

Implements ISvcManager.

Definition at line 562 of file ServiceManager.cpp.

References endreq(), existsService(), StatusCode::FAILURE, MSG::FATAL, isValidInterface(), m_listsvc, m_svclocator, msgSvc(), std::list< _Tp, _Alloc >::push_back(), ISvcLocator::service(), StatusCode::setChecked(), and StatusCode::SUCCESS.

Referenced by addService(), ApplicationMgr::i_startup(), and makeService().

    00566 {
    00567   // Check is the service is already existing
    00568   if( existsService( svcname ) ) {
    00569     // return an error because a service with that name already exists
    00570     return StatusCode::FAILURE;
    00571   }
    00572
    00573   StatusCode rc = StatusCode::FAILURE;
    00574   rc.setChecked(); //hack to avoid going into infinite recursion on ~StatusCode
    00575
    00576   MsgStream log(msgSvc(), "ServiceManager");
    00577
    00578   service = PluginService::Create<IService*>(svctype, svcname, m_svclocator);
    00579   if ( service ) {
    00580     m_listsvc.push_back( service );
    00581     // Check the compatibility of the version of the interface obtained
    00582     if( !isValidInterface(service) ) {
    00583       log << MSG::FATAL << "Incompatible interface IService version for " << svctype << endreq;
    00584       return StatusCode::FAILURE;
    00585     }
    00586     service->setServiceManager(this);
    00587     return StatusCode(StatusCode::SUCCESS,true);
    00588   }
    00589   log << MSG::FATAL << "No Service factory for " << svctype << " available." << endreq;
    00590   return StatusCode::FAILURE;
    00591 }

StatusCode ServiceManager::getFactory | ( | const std::string & | svctype,
|  | const ISvcFactory *& | fac |
| ) |  |  | const`[virtual]`

implementation of IAlgManager::getFactory

Implements ISvcManager.

Definition at line 595 of file ServiceManager.cpp.

References StatusCode::FAILURE, m_mapfactory, return, and StatusCode::SUCCESS.

    00596 {
    00597   MapFactory::const_iterator itf = m_mapfactory.find( svctype );
    00598   factory = (itf == m_mapfactory.end()) ? 0 : (*itf).second;
    00599   return (factory==0) ? StatusCode::FAILURE : StatusCode::SUCCESS;
    00600 }

StatusCode ServiceManager::initializeServices | ( |  | ) | `[virtual]`

implementation of ISvcManager::initializeServices

Implements ISvcManager.

Definition at line 363 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), MSG::DEBUG, std::list< _Tp, _Alloc >::end(), endreq(), MSG::ERROR, StatusCode::FAILURE, Gaudi::StateMachine::INITIALIZED, StatusCode::isSuccess(), m_activesvc, msgSvc(), name, Gaudi::StateMachine::OFFLINE, and StatusCode::SUCCESS.

Referenced by ApplicationMgr::initialize().

    00365 {
    00366   StatusCode sc;
    00367   MsgStream log(msgSvc(), "ServiceManager");
    00368
    00369   // call initialize() for all services
    00370   for (PListSvc::iterator it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00371     std::string name = (*it).first->name();
    00372     switch ((*it).first->FSMState()) {
    00373     case Gaudi::StateMachine::INITIALIZED:
    00374       log << MSG::DEBUG << "Service " << name
    00375           << " already initialized" << endreq;
    00376       break;
    00377     case Gaudi::StateMachine::OFFLINE:
    00378       log << MSG::DEBUG << "Initializing service " << name << endreq;
    00379       sc = (*it).first->sysInitialize();
    00380       if( !sc.isSuccess() ) {
    00381         log << MSG::ERROR << "Unable to initialize Service: " << (*it).first->name() << endreq;
    00382         return sc;
    00383       } break;
    00384     default:
    00385       log << MSG::ERROR << "Service " << name
    00386           << " not in the correct state to be initialized ("
    00387           << (*it).first->FSMState() << ")" << endreq;
    00388       return StatusCode::FAILURE;
    00389     }
    00390   }
    00391   return StatusCode::SUCCESS;
    00392 }

StatusCode ServiceManager::startServices | ( |  | ) | `[virtual]`

implementation of ISvcManager::startServices

Implements ISvcManager.

Definition at line 395 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), MSG::DEBUG, std::list< _Tp, _Alloc >::end(), endreq(), MSG::ERROR, StatusCode::FAILURE, Gaudi::StateMachine::INITIALIZED, StatusCode::isSuccess(), m_activesvc, msgSvc(), name, Gaudi::StateMachine::RUNNING, and StatusCode::SUCCESS.

Referenced by ApplicationMgr::start().

    00397 {
    00398   StatusCode sc = StatusCode(StatusCode::FAILURE,true);
    00399   MsgStream log(msgSvc(), "ServiceManager");
    00400
    00401   // call initialize() for all services
    00402   for (PListSvc::iterator it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00403     std::string name = (*it).first->name();
    00404     switch ((*it).first->FSMState()) {
    00405     case Gaudi::StateMachine::RUNNING:
    00406       log << MSG::DEBUG << "Service " << name
    00407           << " already started" << endreq;
    00408       break;
    00409     case Gaudi::StateMachine::INITIALIZED:
    00410       log << MSG::DEBUG << "Starting service " << name << endreq;
    00411       sc = (*it).first->sysStart();
    00412       if( !sc.isSuccess() ) {
    00413         log << MSG::ERROR << "Unable to start Service: " << (*it).first->name() << endreq;
    00414         return sc;
    00415       } break;
    00416     default:
    00417       log << MSG::ERROR << "Service " << name
    00418           << " not in the correct state to be started ("
    00419           << (*it).first->FSMState() << ")" << endreq;
    00420       return StatusCode::FAILURE;
    00421     }
    00422   }
    00423   return StatusCode::SUCCESS;
    00424 }

StatusCode ServiceManager::stopServices | ( |  | ) | `[virtual]`

implementation of ISvcManager::stopServices

Implements ISvcManager.

Definition at line 428 of file ServiceManager.cpp.

References MSG::DEBUG, endreq(), MSG::ERROR, StatusCode::FAILURE, Gaudi::StateMachine::INITIALIZED, StatusCode::isSuccess(), m_activesvc, msgSvc(), name, std::list< _Tp, _Alloc >::rbegin(), std::list< _Tp, _Alloc >::rend(), Gaudi::StateMachine::RUNNING, and StatusCode::SUCCESS.

Referenced by ApplicationMgr::stop().

    00430 {
    00431   StatusCode sc;
    00432   MsgStream log(msgSvc(), "ServiceManager");
    00433
    00434   PListSvc::reverse_iterator it;
    00435   // call stop() for all services
    00436   for ( it = m_activesvc.rbegin(); it != m_activesvc.rend(); it++ ) {
    00437     std::string name = (*it).first->name();
    00438     switch ((*it).first->FSMState()) {
    00439     case Gaudi::StateMachine::INITIALIZED:
    00440       log << MSG::DEBUG << "Service " << name
    00441           << " already stopped" << endreq;
    00442       break;
    00443     case Gaudi::StateMachine::RUNNING:
    00444       log << MSG::DEBUG << "Stopping service " << name << endreq;
    00445       sc = (*it).first->sysStop();
    00446       if( !sc.isSuccess() ) {
    00447         log << MSG::ERROR << "Unable to stop Service: " << (*it).first->name() << endreq;
    00448         return sc;
    00449       } break;
    00450     default:
    00451       log << MSG::ERROR << "Service " << name
    00452           << " not in the correct state to be stopped ("
    00453           << (*it).first->FSMState() << ")" << endreq;
    00454       return StatusCode::FAILURE;
    00455     }
    00456   }
    00457   return StatusCode::SUCCESS;
    00458 }

StatusCode ServiceManager::finalizeServices | ( |  | ) | `[virtual]`

implementation of ISvcManager::finalizeServices

Implements ISvcManager.

Definition at line 499 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), MSG::DEBUG, std::list< _Tp, _Alloc >::end(), endreq(), std::list< _Tp, _Alloc >::erase(), StatusCode::FAILURE, getPriority(), StatusCode::ignore(), m_activesvc, m_listsvc, msgSvc(), std::list< _Tp, _Alloc >::rbegin(), std::list< _Tp, _Alloc >::rend(), setPriority(), std::list< _Tp, _Alloc >::size(), StatusCode::SUCCESS, and MSG::WARNING.

Referenced by ApplicationMgr::finalize().

    00501 {
    00502   MsgStream log(msgSvc(), "ServiceManager");
    00503
    00504   PListSvc::reverse_iterator its;
    00505
    00506   StatusCode sc(StatusCode::SUCCESS);
    00507
    00508   // make sure that HistogramDataSvc and THistSvc get finalized after the
    00509   // ToolSvc, and StatusCodeSvc after that
    00510   int pri_tool = getPriority("ToolSvc");
    00511   if (pri_tool != 0) {
    00512     setPriority("THistSvc",pri_tool-1).ignore();
    00513     setPriority("ChronoStatSvc",pri_tool-2).ignore();
    00514     setPriority("AuditorSvc",pri_tool-3).ignore();
    00515     setPriority("HistogramDataSvc",pri_tool-1).ignore();
    00516     // Preserve the relative ordering between HistogramDataSvc and HistogramPersistencySvc
    00517     setPriority("HistogramPersistencySvc",pri_tool-2).ignore();
    00518   }
    00519
    00520   // make sure the StatusCodeSvc gets finalized really late:
    00521   setPriority("StatusCodeSvc",-9999).ignore();
    00522
    00523   // call finalize() for all services in reverse order
    00524   for ( its = m_activesvc.rbegin(); its != m_activesvc.rend(); its++ ) {
    00525     // ignore the current state for the moment
    00526     // if( Gaudi::StateMachine::INITIALIZED == (*it).first->state() ) {
    00527     log << MSG::DEBUG << "Finalizing service " << (*its).first->name() << endreq;
    00528     if ( !((*its).first->sysFinalize()).isSuccess() ) {
    00529       log << MSG::WARNING << "Finalization of service " << (*its).first->name()
    00530       << " failed" << endreq;
    00531       sc = StatusCode::FAILURE;
    00532     }
    00533   }
    00534
    00535   // loop over all Active Services, removing them one by one.
    00536   while (m_activesvc.size() != 0) {
    00537     PListSvc::iterator its = m_activesvc.end();
    00538     its --;
    00539
    00541     //   for ( its = m_activesvc.rbegin(); its != m_activesvc.rend(); its++ ) {
    00542     // erase from m_listsvc before releasing
    00543     for ( ListSvc::iterator ll = m_listsvc.begin(); ll != m_listsvc.end(); ++ll ) {
    00544       if ( (*ll)->name() == its->first->name() ) {
    00545         m_listsvc.erase( ll );
    00546         break;
    00547       }
    00548     }
    00549
    00550     // this may destroy the service
    00551     (*its).first->release();
    00552   }
    00553
    00554   // clear the list of active services
    00555   m_activesvc.erase(m_activesvc.begin(), m_activesvc.end() );
    00556
    00557   return sc ;
    00558 }

StatusCode ServiceManager::reinitializeServices | ( |  | ) | `[virtual]`

implementation of ISvcManager::reinitializeServices

Implements ISvcManager.

Definition at line 461 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::end(), endreq(), MSG::ERROR, StatusCode::FAILURE, StatusCode::isSuccess(), m_activesvc, msgSvc(), and StatusCode::SUCCESS.

Referenced by ApplicationMgr::reinitialize().

    00463 {
    00464   StatusCode sc;
    00465
    00466   PListSvc::iterator it;
    00467   // Re-Initialize all services
    00468   for ( it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00469     sc = (*it).first->sysReinitialize();
    00470     if( !sc.isSuccess() ) {
    00471       MsgStream log(msgSvc(), "ServiceManager");
    00472       log << MSG::ERROR << "Unable to re-initialize Service: " << (*it).first->name() << endreq;
    00473       return StatusCode::FAILURE;
    00474     }
    00475   }
    00476   return StatusCode::SUCCESS;
    00477 }

StatusCode ServiceManager::restartServices | ( |  | ) | `[virtual]`

implementation of ISvcManager::restartServices

Implements ISvcManager.

Definition at line 480 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::end(), endreq(), MSG::ERROR, StatusCode::FAILURE, StatusCode::isSuccess(), m_activesvc, msgSvc(), and StatusCode::SUCCESS.

Referenced by ApplicationMgr::restart().

    00482 {
    00483   StatusCode sc;
    00484
    00485   PListSvc::iterator it;
    00486   // Re-Start all services
    00487   for ( it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00488     sc = (*it).first->sysRestart();
    00489     if( !sc.isSuccess() ) {
    00490       MsgStream log(msgSvc(), "ServiceManager");
    00491       log << MSG::ERROR << "Unable to re-start Service: " << (*it).first->name() << endreq;
    00492       return StatusCode::FAILURE;
    00493     }
    00494   }
    00495   return StatusCode::SUCCESS;
    00496 }

int ServiceManager::getPriority | ( | const std::string & | name | ) | const`[virtual]`

manage priorties of services

Implements ISvcManager.

Definition at line 616 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::end(), m_activesvc, and name.

Referenced by finalizeServices().

    00616                                                        {
    00617 //------------------------------------------------------------------------------
    00618
    00619   PListSvc::const_iterator it;
    00620   for (it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00621     if ((*it).first->name() == name) {
    00622       return (*it).second;
    00623     }
    00624   }
    00625
    00626   return 0;
    00627
    00628 }

StatusCode ServiceManager::setPriority | ( | const std::string & | name,
|  | int | pri |
| ) |  |  | `[virtual]`

Implements ISvcManager.

Definition at line 632 of file ServiceManager.cpp.

References addService(), std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::end(), StatusCode::FAILURE, StatusCode::ignore(), m_activesvc, name, and removeActiveService().

Referenced by finalizeServices().

    00632                                                            {
    00633 //------------------------------------------------------------------------------
    00634
    00635   PListSvc::const_iterator it;
    00636   for (it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00637     if ((*it).first->name() == name) {
    00638       IService *svc = (*it).first;
    00639       removeActiveService( svc ).ignore();
    00640       return addService(svc,prio);
    00641     }
    00642   }
    00643
    00644   return StatusCode::FAILURE;
    00645
    00646 }

IMessageSvc * ServiceManager::msgSvc | ( |  | ) | `[private]`

access the message service

Definition at line 603 of file ServiceManager.cpp.

References getService(), and m_msgsvc.

Referenced by createService(), declareSvcFactory(), finalizeServices(), getService(), initializeServices(), makeService(), reinitializeServices(), restartServices(), startServices(), and stopServices().

    00605 {
    00606   if( m_msgsvc == 0 ) {
    00607     IService* iSvc(0);
    00608     if ( (getService( "MessageSvc", iSvc, false)).isSuccess() )
    00609       m_msgsvc = dynamic_cast<IMessageSvc*>(iSvc);
    00610   }
    00611   return m_msgsvc;
    00612 }

StatusCode ServiceManager::makeService | ( | const std::string & | name,
|  | IService *& | svc |
| ) |  |  | `[private]`

create a service and initialize it

Definition at line 94 of file ServiceManager.cpp.

References addService(), createService(), endreq(), std::basic_string< _CharT, _Traits, _Alloc >::erase(), MSG::ERROR, std::basic_string< _CharT, _Traits, _Alloc >::find(), StatusCode::ignore(), Gaudi::StateMachine::INITIALIZED, StatusCode::isSuccess(), std::basic_string< _CharT, _Traits, _Alloc >::length(), m_maptype, m_statemgr, msgSvc(), ListItem::name(), name, std::basic_string< _CharT, _Traits, _Alloc >::npos, removeService(), Gaudi::StateMachine::RUNNING, IService::setServiceManager(), IService::sysInitialize(), IService::sysStart(), and ListItem::type().

Referenced by getService().

    00097 {
    00098   // find out if name is registered with a type
    00099   std::string name = nam;
    00100   std::string type;
    00101   MapType::iterator it = m_maptype.find( nam );
    00102   if( it != m_maptype.end() ) {
    00103     type = (*it).second;
    00104   } else {
    00105     // otherwise parse the name to see if it is of the format "type/name"
    00106     ListItem item(name);
    00107     type = item.type();
    00108     name = item.name();
    00109   }
    00110   std::string::size_type ip;
    00111   if ( (ip = type.find("__")) != std::string::npos) {
    00112     type.erase(ip,type.length());
    00113   }
    00114   StatusCode sc = createService( type, name, svc );
    00115   if( sc.isSuccess() ) {
    00116     // Bring the created service to the same state in which the ApplicationMgr
    00117     // will be.
    00118     if (m_statemgr->targetFSMState() >= Gaudi::StateMachine::INITIALIZED) {
    00119       sc = svc->sysInitialize();
    00120       if (sc.isSuccess() && m_statemgr->targetFSMState() >= Gaudi::StateMachine::RUNNING) {
    00121         sc = svc->sysStart();
    00122       }
    00123     }
    00124
    00125     if( sc.isSuccess() ) {
    00126       sc = addService( svc, 10);
    00127     } else {
    00128       MsgStream log(msgSvc(), "ServiceManager");
    00129       log << MSG::ERROR << "Unable to initialize service \"" << name << "\""
    00130           << endreq;
    00131       removeService(svc).ignore(); //if init fails remove it from the list
    00132       delete svc;
    00133       svc = 0;
    00134     }
    00135     if (svc!= 0) svc->setServiceManager( this );
    00136   }
    00137   return sc;
    00138 }

StatusCode ServiceManager::removeActiveService | ( | IService * | svc | ) | `[private]`

Definition at line 290 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::end(), std::list< _Tp, _Alloc >::erase(), m_activesvc, and StatusCode::SUCCESS.

Referenced by addService(), removeService(), and setPriority().

    00292 {
    00293   PListSvc::iterator it;
    00294   for (it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00295     if( (*it).first == svc ) {
    00296       m_activesvc.erase(it);
    00297       break;
    00298     }
    00299   }
    00300
    00301   return StatusCode::SUCCESS;
    00302 }

StatusCode ServiceManager::removeListService | ( | IService * | svc | ) | `[private]`

Definition at line 305 of file ServiceManager.cpp.

References std::list< _Tp, _Alloc >::begin(), std::list< _Tp, _Alloc >::end(), std::list< _Tp, _Alloc >::erase(), m_listsvc, and StatusCode::SUCCESS.

Referenced by removeService().

    00307 {
    00308
    00309   ListSvc::iterator ll;
    00310   for ( ll = m_listsvc.begin(); ll != m_listsvc.end(); ++ll ) {
    00311     if ( (*ll) == svc  ) {
    00312       m_listsvc.erase( ll );
    00313       break;
    00314     }
    00315   }
    00316
    00317   return StatusCode::SUCCESS;
    00318 }

## Member Data Documentation

unsigned long ServiceManager::m_refcount`[private]`

Reference counter.

Definition at line 107 of file ServiceManager.h.

Referenced by addRef(), release(), and ServiceManager().

ListSvc ServiceManager::m_listsvc`[private]`

List of service maintained by ServiceManager.

Definition at line 108 of file ServiceManager.h.

Referenced by createService(), finalizeServices(), getService(), getServices(), removeListService(), and ~ServiceManager().

PListSvc ServiceManager::m_activesvc`[private]`

List of "active" service maintained by ServiceManager.

Definition at line 109 of file ServiceManager.h.

Referenced by addService(), finalizeServices(), getActiveServices(), getPriority(), initializeServices(), reinitializeServices(), removeActiveService(), restartServices(), setPriority(), startServices(), and stopServices().

MapType ServiceManager::m_maptype`[private]`

Map of service name and service type.

Definition at line 110 of file ServiceManager.h.

Referenced by addService(), declareSvcType(), and makeService().

MapFactory ServiceManager::m_mapfactory`[private]`

Map of pairs of factory reference and service name.

Definition at line 111 of file ServiceManager.h.

Referenced by declareSvcFactory(), and getFactory().

IInterface* ServiceManager::m_pOuter`[private]`

Interface hub reference (ApplicationMgr).

Definition at line 112 of file ServiceManager.h.

Referenced by queryInterface(), and ServiceManager().

ISvcLocator* ServiceManager::m_svclocator`[private]`

Service locator.

Definition at line 113 of file ServiceManager.h.

Referenced by createService(), getService(), and ServiceManager().

IMessageSvc* ServiceManager::m_msgsvc`[private]`

Pointer to the message service if it exists.

Definition at line 114 of file ServiceManager.h.

Referenced by msgSvc(), ServiceManager(), and ~ServiceManager().

SmartIF<IStateful> ServiceManager::m_statemgr`[private]`

Pointer to the state machine.

Definition at line 115 of file ServiceManager.h.

Referenced by addService(), and makeService().

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiSvc/v17r1/src/ApplicationMgr/ServiceManager.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiSvc/v17r1/src/ApplicationMgr/ServiceManager.cpp