17 #define ON_DEBUG if (msgLevel(MSG::DEBUG))
18 #define ON_VERBOSE if (msgLevel(MSG::VERBOSE))
20 #define DEBMSG ON_DEBUG debug()
21 #define VERMSG ON_VERBOSE verbose()
42 it->service->setServiceManager(0);
61 const std::string &
name = typeName.
name();
72 std::string::size_type ip;
73 if ( (ip = type.find(
"__")) != std::string::npos) {
74 type.erase(ip,type.length());
77 IService*
service = Service::Factory::create(type, name, static_cast<ISvcLocator*>(
this));
83 fatal() <<
"Incompatible interface IService version for " << type <<
endmsg;
89 fatal() <<
"No Service factory for " << type <<
" available." <<
endmsg;
98 ListSvc::iterator it =
find(svc);
113 ListSvc::iterator it =
find(typeName.
name());
122 sc = svc->sysInitialize();
124 sc = svc->sysStart();
128 error() <<
"Unable to initialize service \"" << typeName.
name() <<
"\""
157 const std::string &
name = typeName.
name();
162 ListSvc::iterator it =
find(name);
168 <<
"Initialization loop detected when creating service \"" << name
177 if( name ==
"ApplicationMgr" ||
181 }
else if ( createIf ){
184 return find(name)->service;
197 m_listOfPtrs.push_back(const_cast<IService*>(it->service.get()));
206 return find(name) != m_listsvc.end();
213 ListSvc::iterator it =
find(svc);
225 ListSvc::iterator it =
find(name);
235 const std::string& svctype )
238 std::pair<MapType::iterator, bool> p =
m_maptype.
insert(std::make_pair(svcname, svctype));
239 if( p.second ==
false) {
258 for (ListSvc::iterator it = tmpList.begin(); it != tmpList.end(); ++it ) {
259 if (!it->active)
continue;
260 const std::string&
name = it->service->name();
261 switch (it->service->FSMState()) {
263 DEBMSG <<
"Service " << name <<
" already initialized" <<
endmsg;
267 sc = it->service->sysInitialize();
269 error() <<
"Unable to initialize Service: " << name <<
endmsg;
273 error() <<
"Service " << name
274 <<
" not in the correct state to be initialized ("
275 << it->service->FSMState() <<
")" <<
endmsg;
293 for (ListSvc::iterator it = tmpList.begin(); it != tmpList.end(); ++it ) {
294 if (!it->active)
continue;
295 const std::string&
name = it->service->name();
296 switch (it->service->FSMState()) {
298 DEBMSG <<
"Service " << name
299 <<
" already started" <<
endmsg;
303 sc = it->service->sysStart();
305 error() <<
"Unable to start Service: " << name <<
endmsg;
309 error() <<
"Service " << name
310 <<
" not in the correct state to be started ("
311 << it->service->FSMState() <<
")" <<
endmsg;
329 ListSvc::reverse_iterator it;
331 for (it = tmpList.rbegin(); it != tmpList.rend(); ++it ) {
332 if (!it->active)
continue;
333 const std::string&
name = it->service->name();
334 switch (it->service->FSMState()) {
336 DEBMSG <<
"Service " << name <<
" already stopped" <<
endmsg;
340 sc = it->service->sysStop();
342 error() <<
"Unable to stop Service: " << name <<
endmsg;
346 DEBMSG <<
"Service " << name
347 <<
" not in the correct state to be stopped ("
348 << it->service->FSMState() <<
")" <<
endmsg;
365 ListSvc::iterator it;
367 for ( it = tmpList.begin(); it != tmpList.end(); ++it ) {
368 if (!it->active)
continue;
369 sc = it->service->sysReinitialize();
371 error() <<
"Unable to re-initialize Service: " << it->service->name() <<
endmsg;
388 ListSvc::iterator it;
390 for ( it = tmpList.begin(); it != tmpList.end(); ++it ) {
391 if (!it->active)
continue;
392 sc = it->service->sysRestart();
394 error() <<
"Unable to re-start Service: " << it->service->name() <<
endmsg;
422 std::vector<IIncidentListener*> postFinList;
443 ListSvc::reverse_iterator rit;
444 for (rit = tmpList.rbegin(); rit != tmpList.rend(); ++rit ) {
445 if (!rit->active)
continue;
446 const std::string&
name = rit->service->name();
450 if ( !(rit->service->sysFinalize()).isSuccess() ) {
451 warning() <<
"Finalization of service " << name <<
" failed" <<
endmsg;
458 if (!postFinList.empty()) {
459 DEBMSG <<
"Will call SvcPostFinalize for " << postFinList.size() <<
" clients"
462 std::vector<IIncidentListener*>::iterator itr;
463 for (itr = postFinList.begin(); itr != postFinList.end(); ++itr) {
470 DEBMSG <<
"Looping over all active services..." <<
endmsg;
471 ListSvc::iterator it =
m_listsvc.begin();
473 DEBMSG <<
"---- " << it->service->name()
474 <<
" (refCount = " << it->service->refCount() <<
")"
476 if (it->service->refCount() < 1) {
477 warning() <<
"Too low reference count for " << it->service->name()
478 <<
" (should not go below 1 at this point)" <<
endmsg;
479 it->service->addRef();
496 ListSvc::const_iterator it =
find(name);
497 return (it !=
m_listsvc.end()) ? it->priority: 0;
504 ListSvc::iterator it =
find(name);
534 <<
"===================== listing all services ===================\n"
535 <<
" prior ref name active\n";
537 ListSvc::const_iterator it;
541 log.
flags(std::ios_base::right);
542 log << it->priority <<
" ";
544 log << it->service->refCount() <<
" ";
546 log.
flags(std::ios_base::left);
547 log << it->service->name() <<
" ";
549 log << it->active << std::endl;
553 log <<
"=================================================================\n";
The ServiceManager class is in charge of the creation of concrete instances of Services.
std::list< IService * > m_listOfPtrs
List of pointers to the know services used to implement getServices()
Definition of the MsgStream class used to transmit messages.
SmartIF< IService > m_appSvc
Pointer to the application IService interface.
virtual Gaudi::StateMachine::State targetFSMState() const
When we are in the middle of a transition, get the state where the transition is leading us...
virtual StatusCode stop()
Stop (from RUNNING to INITIALIZED).
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
const std::string & name() const
Return the name of the manager (implementation of INamedInterface)
SmartIF< IMessageSvc > & msgSvc() const
The standard message service.
bool isSuccess() const
Test for a status code of SUCCESS.
SmartIF< ISvcLocator > m_svcLocator
Service locator (needed to access the MessageSvc)
bool m_loopCheck
Check for service initialization loops.
virtual int getPriority(const std::string &name) const
manage priorities of services
ServiceManager(IInterface *application)
default creator
virtual const std::list< IService * > & getServices() const
Return the list of Services.
MsgStream & warning() const
shortcut for the method msgStream(MSG::WARNING)
virtual StatusCode reinitialize()
Initialization (from INITIALIZED or RUNNING to INITIALIZED, via CONFIGURED).
bool isValidInterface(I *i)
Templated function that throws an exception if the version if the interface implemented by the object...
const std::string SvcPostFinalize
ONLY For Services that need something after they've been finalized.
bool isFailure() const
Test for a status code of FAILURE.
MapType m_maptype
Map of service name and service type.
std::pair< iterator, bool > insert(const value_type &val)
Helper class to parse a string of format "type/name".
bool isValid() const
Allow for check if smart pointer is valid.
virtual SmartIF< IService > & createService(const Gaudi::Utils::TypeNameString &nametype)
implementation of ISvcManager::createService
General service interface definition.
virtual StatusCode addService(IService *svc, int prio=DEFAULT_SVC_PRIORITY)
implementation of ISvcManager::addService
This class is used for returning status codes from appropriate routines.
Definition of the basic interface.
virtual StatusCode initialize()
Initialization (from CONFIGURED to INITIALIZED).
virtual StatusCode setPriority(const std::string &name, int pri)
virtual void setLoopCheckEnabled(bool en)
Set the value of the initialization loop check flag.
#define DECLARE_OBJECT_FACTORY(x)
iterator find(const key_type &key)
TYPE * get() const
Get interface pointer.
virtual StatusCode finalize()
Finalize (from INITIALIZED to CONFIGURED).
virtual bool existsService(const std::string &name) const
implementation of ISvcLocation::existsService
virtual StatusCode declareSvcType(const std::string &svcname, const std::string &svctype)
implementation of ISvcManager::declareSvcType
map_type::iterator iterator
virtual StatusCode removeService(IService *svc)
implementation of ISvcManager::removeService
long flags() const
IOS emulation.
virtual ~ServiceManager()
virtual destructor
const std::string & type() const
Base class for all Incidents (computing events).
Templated class to add the standard messaging functionalities.
MsgStream & fatal() const
shortcut for the method msgStream(MSG::FATAL)
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
ListSvc::iterator find(const std::string &name)
virtual SmartIF< IService > & service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf=true)
Returns a smart pointer to a service.
const std::string & name() const
virtual bool loopCheckEnabled() const
Get the value of the initialization loop check flag.
boost::recursive_mutex m_svcinitmutex
Mutex to synchronize shared service initialization between threads.
virtual StatusCode restart()
Initialization (from RUNNING to RUNNING, via INITIALIZED).
std::string typeName(const std::type_info &typ)
std::list< ServiceItem > ListSvc
ListSvc m_listsvc
List of service maintained by ServiceManager.
virtual void setServiceManager(ISvcManager *)=0
MsgStream & error() const
shortcut for the method msgStream(MSG::ERROR)
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
virtual StatusCode start()
Start (from INITIALIZED to RUNNING).
void setChecked() const
Ignore the checking code;.