| # Gaudi Framework, version v22r4 |

Home |  | Generated: Fri Sep 2 2011

# 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
    00018 // Forward declarations
    00019 class IService;
    00020 class ISvcFactory;
    00021 class IMessageSvc;
    00022 class Property;
    00023
    00036 class ServiceManager : public extends2<ComponentManager, ISvcManager, ISvcLocator>{
    00037 public:
    00038
    00039   struct ServiceItem {
    00040     ServiceItem(IService *s, long p = 0, bool act = false):
    00041       service(s), priority(p), active(act) {}
    00042     SmartIF<IService> service;
    00043     long priority;
    00044     bool active;
    00045     inline bool operator==(const std::string &name) const {
    00046       return service->name() == name;
    00047     }
    00048     inline bool operator==(const IService *ptr) const {
    00049       return service.get() == ptr;
    00050     }
    00051     inline bool operator<(const ServiceItem& rhs) const {
    00052       return priority < rhs.priority;
    00053     }
    00054   };
    00055
    00056   // typedefs and classes
    00057   typedef std::list<ServiceItem> ListSvc;
    00058   typedef GaudiUtils::Map<std::string, std::string> MapType;
    00059
    00061   ServiceManager(IInterface* application);
    00062
    00064   inline SmartIF<ISvcLocator>& serviceLocator() const {
    00065     return m_svcLocator;
    00066   }
    00067
    00069   virtual ~ServiceManager();
    00070
    00072   virtual const std::list<IService*>& getServices() const;
    00073
    00075   virtual bool existsService(const std::string& name) const;
    00076
    00078   virtual StatusCode addService(IService* svc, int prio = 10);
    00080   virtual StatusCode addService(const Gaudi::Utils::TypeNameString& typeName, int prio = 10);
    00082   virtual StatusCode removeService(IService* svc);
    00084   virtual StatusCode removeService(const std::string& name);
    00085
    00087   virtual StatusCode declareSvcType(const std::string& svcname, const std::string& svctype);
    00088
    00090   virtual SmartIF<IService>& createService(const Gaudi::Utils::TypeNameString& nametype);
    00091
    00093   virtual StatusCode initialize();
    00095   virtual StatusCode start();
    00097   virtual StatusCode stop();
    00099   virtual StatusCode finalize();
    00100
    00102   virtual StatusCode reinitialize();
    00104   virtual StatusCode restart();
    00105
    00107   virtual int getPriority(const std::string& name) const;
    00108   virtual StatusCode setPriority(const std::string& name, int pri);
    00109
    00111   virtual bool loopCheckEnabled() const;
    00113   virtual void setLoopCheckEnabled(bool en);
    00114
    00116   const std::string &name() const {
    00117     static std::string _name = "ServiceManager";
    00118     return _name;
    00119   }
    00120
    00122   virtual SmartIF<IService> &service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true);
    00123
    00124 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
    00125   using ISvcManager::createService;
    00126   using ISvcManager::addService;
    00127 #endif
    00128
    00129 private:
    00130
    00131   inline ListSvc::iterator find(const std::string &name) {
    00132     return std::find(m_listsvc.begin(), m_listsvc.end(), name);
    00133   }
    00134   inline ListSvc::const_iterator find(const std::string &name) const {
    00135     return std::find(m_listsvc.begin(), m_listsvc.end(), name);
    00136   }
    00137   inline ListSvc::iterator find(const IService *ptr) {
    00138     return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
    00139   }
    00140   inline ListSvc::const_iterator find(const IService *ptr) const {
    00141     return std::find(m_listsvc.begin(), m_listsvc.end(), ptr);
    00142   }
    00143
    00144 private:
    00145   ListSvc       m_listsvc;
    00146   MapType       m_maptype;
    00147   bool          m_loopCheck;
    00148
    00150   SmartIF<IService> m_appSvc;
    00151
    00153   mutable std::list<IService*> m_listOfPtrs;
    00154
    00155   GaudiUtils::Map<InterfaceID, SmartIF<IInterface> > m_defaultImplementations;
    00156 };
    00157 #endif  // GAUDISVC_ServiceManager_H
    00158

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines