| # Gaudi Framework, version v20r4
Generated: 8 Jan 2009

# 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 33 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 ()
| implementation of IInterface::addRef
virtual unsigned long | release ()
| implementation 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 priorities of services
virtual StatusCode | setPriority (const std::string &name, int pri)
virtual bool | loopCheckEnabled () const
| Get the value of the initialization loop check flag.
virtual void | setLoopCheckEnabled (bool en)
| Set the value of the initialization loop check flag.
## 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.
bool | m_loopCheck
| Check for service initialization loops.

## Member Typedef Documentation

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

Definition at line 37 of file ServiceManager.h.

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

Definition at line 38 of file ServiceManager.h.

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

Definition at line 39 of file ServiceManager.h.

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

Definition at line 40 of file ServiceManager.h.

## Constructor & Destructor Documentation

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

default creator

Definition at line 17 of file ServiceManager.cpp.

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

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

virtual destructor

Definition at line 28 of file ServiceManager.cpp.

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

## Member Function Documentation

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

implementation of IInterface::addRef

Implements IInterface.

Definition at line 37 of file ServiceManager.cpp.

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

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

implementation of IInterface::release

Implements IInterface.

Definition at line 43 of file ServiceManager.cpp.

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

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

implementation of IInterface::queryInterface

Implements IInterface.

Definition at line 52 of file ServiceManager.cpp.

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

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

implementation of ISvcLocation::getService

Implements ISvcLocator.

Definition at line 76 of file ServiceManager.cpp.

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

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

implementation of ISvcLocation::getService

Implements ISvcLocator.

Definition at line 82 of file ServiceManager.cpp.

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

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

implementation of ISvcLocation::getService

Implements ISvcLocator.

Definition at line 142 of file ServiceManager.cpp.

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

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

Return the list of Services.

Implements ISvcLocator.

Definition at line 195 of file ServiceManager.cpp.

    00197 {
    00198   return m_listsvc;
    00199 }

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

Definition at line 202 of file ServiceManager.cpp.

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

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

implementation of ISvcLocation::existsService

Implements ISvcLocator.

Definition at line 215 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::addService

Implements ISvcManager.

Definition at line 228 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::addService

Implements ISvcManager.

Definition at line 243 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::removeService

Implements ISvcManager.

Definition at line 281 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::removeService

Implements ISvcManager.

Definition at line 324 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::declareSvcFactory

Implements ISvcManager.

Definition at line 333 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::declareSvcType

Implements ISvcManager.

Definition at line 351 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::createService

Implements ISvcManager.

Definition at line 564 of file ServiceManager.cpp.

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

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

implementation of IAlgManager::getFactory

Access to factory by name.

Implements ISvcManager.

Definition at line 601 of file ServiceManager.cpp.

    00602 {
    00603   MapFactory::const_iterator itf = m_mapfactory.find( svctype );
    00604   factory = (itf == m_mapfactory.end()) ? 0 : (*itf).second;
    00605   return (factory==0) ? StatusCode::FAILURE : StatusCode::SUCCESS;
    00606 }

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

implementation of ISvcManager::initializeServices

Implements ISvcManager.

Definition at line 365 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::startServices

Implements ISvcManager.

Definition at line 397 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::stopServices

Implements ISvcManager.

Definition at line 430 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::finalizeServices

Implements ISvcManager.

Definition at line 501 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::reinitializeServices

Implements ISvcManager.

Definition at line 463 of file ServiceManager.cpp.

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

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

implementation of ISvcManager::restartServices

Implements ISvcManager.

Definition at line 482 of file ServiceManager.cpp.

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

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

manage priorities of services

Implements ISvcManager.

Definition at line 622 of file ServiceManager.cpp.

    00622                                                        {
    00623 //------------------------------------------------------------------------------
    00624
    00625   PListSvc::const_iterator it;
    00626   for (it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00627     if ((*it).first->name() == name) {
    00628       return (*it).second;
    00629     }
    00630   }
    00631
    00632   return 0;
    00633
    00634 }

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

Implements ISvcManager.

Definition at line 638 of file ServiceManager.cpp.

    00638                                                            {
    00639 //------------------------------------------------------------------------------
    00640
    00641   PListSvc::const_iterator it;
    00642   for (it = m_activesvc.begin(); it != m_activesvc.end(); it++ ) {
    00643     if ((*it).first->name() == name) {
    00644       IService *svc = (*it).first;
    00645       removeActiveService( svc ).ignore();
    00646       return addService(svc,prio);
    00647     }
    00648   }
    00649
    00650   return StatusCode::FAILURE;
    00651
    00652 }

bool ServiceManager::loopCheckEnabled | ( |  | ) | const`[virtual]`

Get the value of the initialization loop check flag.

Implements ISvcManager.

Definition at line 657 of file ServiceManager.cpp.

    00657                                             {
    00658   return m_loopCheck;
    00659 }

void ServiceManager::setLoopCheckEnabled | ( | bool | en | ) | `[virtual]`

Set the value of the initialization loop check flag.

Implements ISvcManager.

Definition at line 663 of file ServiceManager.cpp.

    00663                                                 {
    00664   m_loopCheck = en;
    00665 }

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

access the message service

Definition at line 609 of file ServiceManager.cpp.

    00611 {
    00612   if( m_msgsvc == 0 ) {
    00613     IService* iSvc(0);
    00614     if ( (getService( "MessageSvc", iSvc, false)).isSuccess() )
    00615       m_msgsvc = dynamic_cast<IMessageSvc*>(iSvc);
    00616   }
    00617   return m_msgsvc;
    00618 }

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

create a service and initialize it

Definition at line 95 of file ServiceManager.cpp.

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

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

Definition at line 292 of file ServiceManager.cpp.

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

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

Definition at line 307 of file ServiceManager.cpp.

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

## Member Data Documentation

unsigned long ServiceManager::m_refcount`[private]`

Reference counter.

Definition at line 113 of file ServiceManager.h.

ListSvc ServiceManager::m_listsvc`[private]`

List of service maintained by ServiceManager.

Definition at line 114 of file ServiceManager.h.

PListSvc ServiceManager::m_activesvc`[private]`

List of "active" service maintained by ServiceManager.

Definition at line 115 of file ServiceManager.h.

MapType ServiceManager::m_maptype`[private]`

Map of service name and service type.

Definition at line 116 of file ServiceManager.h.

MapFactory ServiceManager::m_mapfactory`[private]`

Map of pairs of factory reference and service name.

Definition at line 117 of file ServiceManager.h.

IInterface* ServiceManager::m_pOuter`[private]`

Interface hub reference (ApplicationMgr).

Definition at line 118 of file ServiceManager.h.

ISvcLocator* ServiceManager::m_svclocator`[private]`

Service locator.

Definition at line 119 of file ServiceManager.h.

IMessageSvc* ServiceManager::m_msgsvc`[private]`

Pointer to the message service if it exists.

Definition at line 120 of file ServiceManager.h.

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

Pointer to the state machine.

Definition at line 121 of file ServiceManager.h.

bool ServiceManager::m_loopCheck`[private]`

Check for service initialization loops.

Definition at line 122 of file ServiceManager.h.

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

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