Gaudi Framework, version v23r4

Home   Generated: Mon Sep 17 2012

ServiceManager.h

Go to the documentation of this file.
00001 // $Id: ServiceManager.h,v 1.9 2008/11/10 15:29:09 marcocle Exp $
00002 #ifndef GAUDISVC_ServiceManager_H
00003 #define GAUDISVC_ServiceManager_H
00004 
00005 // Include files
00006 #include "GaudiKernel/Kernel.h"
00007 #include "GaudiKernel/ISvcManager.h"
00008 #include "GaudiKernel/ISvcLocator.h"
00009 #include "GaudiKernel/IStateful.h"
00010 #include "GaudiKernel/SmartIF.h"
00011 #include "GaudiKernel/ComponentManager.h"
00012 #include "GaudiKernel/Map.h"
00013 #include <string>
00014 #include <list>
00015 #include <map>
00016 #include <algorithm>
00017 #include "boost/thread.hpp"
00018 
00019 // Forward declarations
00020 class IService;
00021 class ISvcFactory;
00022 class IMessageSvc;
00023 class Property;
00024 
00037 class ServiceManager : public extends2<ComponentManager, ISvcManager, ISvcLocator>{
00038 public:
00039 
00040   struct ServiceItem {
00041     ServiceItem(IService *s, long p = 0, bool act = false):
00042       service(s), priority(p), active(act) {}
00043     SmartIF<IService> service;
00044     long priority;
00045     bool active;
00046     inline bool operator==(const std::string &name) const {
00047       return service->name() == name;
00048     }
00049     inline bool operator==(const IService *ptr) const {
00050       return service.get() == ptr;
00051     }
00052     inline bool operator<(const ServiceItem& rhs) const {
00053       return priority < rhs.priority;
00054     }
00055   };
00056 
00057   // typedefs and classes
00058   typedef std::list<ServiceItem> ListSvc;
00059   typedef GaudiUtils::Map<std::string, std::string> MapType;
00060 
00062   ServiceManager(IInterface* application);
00063 
00065   inline SmartIF<ISvcLocator>& serviceLocator() const {
00066     return m_svcLocator;
00067   }
00068 
00070   virtual ~ServiceManager();
00071 
00073   virtual const std::list<IService*>& getServices() const;
00074 
00076   virtual bool existsService(const std::string& name) const;
00077 
00079   virtual StatusCode addService(IService* svc, int prio = 10);
00081   virtual StatusCode addService(const Gaudi::Utils::TypeNameString& typeName, int prio = 10);
00083   virtual StatusCode removeService(IService* svc);
00085   virtual StatusCode removeService(const std::string& name);
00086 
00088   virtual StatusCode declareSvcType(const std::string& svcname, const std::string& svctype);
00089 
00091   virtual SmartIF<IService>& createService(const Gaudi::Utils::TypeNameString& nametype);
00092 
00094   virtual StatusCode initialize();
00096   virtual StatusCode start();
00098   virtual StatusCode stop();
00100   virtual StatusCode finalize();
00101 
00103   virtual StatusCode reinitialize();
00105   virtual StatusCode restart();
00106 
00108   virtual int getPriority(const std::string& name) const;
00109   virtual StatusCode setPriority(const std::string& name, int pri);
00110 
00112   virtual bool loopCheckEnabled() const;
00114   virtual void setLoopCheckEnabled(bool en);
00115 
00117   const std::string &name() const {
00118     static std::string _name = "ServiceManager";
00119     return _name;
00120   }
00121 
00123   virtual SmartIF<IService> &service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true);
00124 
00125 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
00126   using ISvcManager::createService;
00127   using ISvcManager::addService;
00128 #endif
00129 
00130 private:
00131 
00132   inline ListSvc::iterator find(const std::string &name) {
00133     return std::find(m_listsvc.begin(), m_listsvc.end(), name);
00134   }
00135   inline ListSvc::const_iterator find(const std::string &name) const {
00136     return std::find(m_listsvc.begin(), m_listsvc.end(), name);
00137   }
00138   inline ListSvc::iterator find(const IService *ptr) {
00139     return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
00140   }
00141   inline ListSvc::const_iterator find(const IService *ptr) const {
00142     return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
00143   }
00144 
00145 private:
00146   ListSvc       m_listsvc;     
00147   MapType       m_maptype;     
00148   bool          m_loopCheck;   
00149 
00151   SmartIF<IService> m_appSvc;
00152 
00154   mutable std::list<IService*> m_listOfPtrs;
00155 
00156   GaudiUtils::Map<InterfaceID, SmartIF<IInterface> > m_defaultImplementations;
00157 
00159   boost::recursive_mutex  m_svcinitmutex;
00160 };
00161 #endif  // GAUDISVC_ServiceManager_H
00162 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Sep 17 2012 13:49:28 for Gaudi Framework, version v23r4 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004