| # Gaudi Framework, version v21r9 |

Home |  | Generated: 3 May 2010

# ServiceLocatorHelper.h

Go to the documentation of this file.

    00001 #ifndef GAUDIKERNEL_SERVICELOCATORHELPER_H
    00002 #define GAUDIKERNEL_SERVICELOCATORHELPER_H
    00003
    00004 #include <string>
    00005 #include <GaudiKernel/StatusCode.h>
    00006 #include <GaudiKernel/SmartIF.h>
    00007 #include <GaudiKernel/IService.h>
    00008
    00009 class ISvcLocator;
    00010 class InterfaceID;
    00011 class MsgStream;
    00012
    00018 class GAUDI_API ServiceLocatorHelper {
    00019 public:
    00020   ServiceLocatorHelper(ISvcLocator& svcLoc, const INamedInterface& requester):
    00021     m_svcLoc(svcLoc),
    00022     m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requester.name()), //use requester msg level
    00023     m_requesterName(requester.name()) {
    00024   }
    00025   ServiceLocatorHelper(ISvcLocator& svcLoc,
    00026       const std::string& loggedName,
    00027       const std::string& requesterName):
    00028     m_svcLoc(svcLoc),
    00029     m_msgLog(SmartIF<IMessageSvc>(&svcLoc), loggedName), //use requester msg level
    00030     m_requesterName(requesterName) {
    00031   }
    00032   ServiceLocatorHelper(ISvcLocator& svcLoc, const std::string& requesterName):
    00033     m_svcLoc(svcLoc),
    00034     m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requesterName), //use requester msg level
    00035     m_requesterName(requesterName) {
    00036   }
    00037 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
    00038   ServiceLocatorHelper(ISvcLocator& svcLoc,
    00039                  const MsgStream& log, //use requester msg level
    00040                  const std::string& requesterName):
    00041     m_svcLoc(svcLoc), m_msgLog(log), m_requesterName(requesterName) {}
    00042 #endif
    00043
    00044   StatusCode getService(const std::string& name,
    00045                         bool createIf,
    00046                         const InterfaceID& iid,
    00047                         void** ppSvc) const {
    00048     return (createIf ?
    00049             createService(name, iid, ppSvc) :
    00050             locateService(name, iid, ppSvc, true));
    00051   }
    00052
    00053   StatusCode locateService(const std::string& name,
    00054                            const InterfaceID& iid,
    00055                            void** ppSvc,
    00056                            bool quiet=false) const;
    00057
    00058   StatusCode createService(const std::string& name,
    00059                            const InterfaceID& iid,
    00060                            void** ppSvc) const;
    00061
    00062   StatusCode createService(const std::string& type,
    00063                            const std::string& name,
    00064                            const InterfaceID& iid,
    00065                            void** ppSvc) const;
    00066
    00067   SmartIF<IService> service(const std::string& name, const bool quiet=false, const bool createIf=true) const;
    00068
    00069 private:
    00070   std::string threadName() const;
    00071   std::string threadedName(const std::string& name) const;
    00072   bool isInThread() const;
    00073   ISvcLocator* serviceLocator() const { return &m_svcLoc; }
    00074   MsgStream& log() const { return m_msgLog; }
    00075   const std::string& requesterName() const { return m_requesterName; }
    00076   ISvcLocator& m_svcLoc;
    00077   mutable MsgStream m_msgLog;
    00078   std::string m_requesterName;
    00079 };
    00080 #endif