| # Gaudi Framework, version v20r2
Generated: 18 Jul 2008

- Main Page
- Namespaces
- Classes
- Files
- Directories
- Related Pages

- Search for |

- Alphabetical List
- Class List
- Class Hierarchy
- Class Members

# ServiceLocatorHelper Class Reference

`#include <ServiceLocatorHelper.h>`

Collaboration diagram for ServiceLocatorHelper:

[legend]
List of all members.

## Detailed Description

an helper to share the implementation of service() among the various kernel base classes $Id:

Definition at line 15 of file ServiceLocatorHelper.h.

## Public Member Functions
| ServiceLocatorHelper (ISvcLocator &svcLoc, MsgStream &log, const std::string &requestorName)
StatusCode | getService (const std::string &name, bool createIf, const InterfaceID &iid, void **ppSvc) const
StatusCode | locateService (const std::string &name, const InterfaceID &iid, void **ppSvc, bool quiet=false) const
StatusCode | createService (const std::string &name, const InterfaceID &iid, void **ppSvc) const
StatusCode | createService (const std::string &type, const std::string &name, const InterfaceID &iid, void **ppSvc) const
## Private Member Functions
std::string | threadName () const
std::string | threadedName (const std::string &name) const
bool | isInThread () const
ISvcLocator * | serviceLocator () const
MsgStream & | log () const
const std::string & | requestorName () const
## Private Attributes
ISvcLocator & | m_svcLoc
MsgStream & | m_msgLog
std::string | m_requestorName

## Constructor & Destructor Documentation

ServiceLocatorHelper::ServiceLocatorHelper | ( | ISvcLocator & | svcLoc,
|  | MsgStream & | log,
|  | const std::string & | requestorName |
| ) |  |  | `[inline]`

Definition at line 17 of file ServiceLocatorHelper.h.

    00019                                                 :
    00020     m_svcLoc(svcLoc), m_msgLog(log), m_requestorName(requestorName) {}

## Member Function Documentation

StatusCode ServiceLocatorHelper::getService | ( | const std::string & | name,
|  | bool | createIf,
|  | const InterfaceID & | iid,
|  | void ** | ppSvc |
| ) |  |  | const`[inline]`

Definition at line 22 of file ServiceLocatorHelper.h.

References createService(), locateService(), and name.

Referenced by HbookCnv::HFileCnv::initialize(), Service::service_i(), AlgTool::service_i(), and Algorithm::service_i().

    00025                                             {
    00026     return (createIf ?
    00027             createService(name, iid, ppSvc) :
    00028             locateService(name, iid, ppSvc, true));
    00029   }

StatusCode ServiceLocatorHelper::locateService | ( | const std::string & | name,
|  | const InterfaceID & | iid,
|  | void ** | ppSvc,
|  | bool | quiet = `false` |
| ) |  |  | const

Definition at line 23 of file ServiceLocatorHelper.cpp.

References endreq(), MSG::ERROR, StatusCode::FAILURE, ISvcLocator::getService(), isInThread(), StatusCode::isSuccess(), log(), name, IInterface::queryInterface(), serviceLocator(), threadName(), and MSG::VERBOSE.

Referenced by getService().

    00026                                                       {
    00027   IService* theSvc(0);
    00028   StatusCode sc(StatusCode::FAILURE);
    00029   if (isInThread()) {
    00030     //first we look for  a thread-specific version of the service
    00031     sc=serviceLocator()->getService(name + threadName(), theSvc, false);
    00032   };
    00033   // if not, try to find the common, single-threaded version of the service
    00034   if (!sc.isSuccess()) sc=serviceLocator()->getService(name, theSvc,false);
    00035
    00036   if ( sc.isSuccess() ) {
    00037     if (!quiet) log() << MSG::VERBOSE
    00038           << "ServiceLocatorHelper::locateService: found service "
    00039           << name <<endreq;
    00040     sc = theSvc->queryInterface(iid, ppSvc);
    00041     if (!sc.isSuccess()) {
    00042       *ppSvc=0;
    00043       if (!quiet) log() << MSG::ERROR
    00044             << "ServiceLocatorHelper::locateService: wrong interface id "
    00045             << iid << " for service " << name << endreq;
    00046     }
    00047   } else {
    00048     // if not return an error
    00049     if (!quiet) {
    00050       log() << MSG::ERROR
    00051             << "ServiceLocatorHelper::locateService: can not locate service "
    00052             << name;
    00053       if (isInThread()) log() << MSG::ERROR << " or " << name + threadName();
    00054       log() << MSG::ERROR << endreq;
    00055     }
    00056     *ppSvc = 0;
    00057   }
    00058   return sc;
    00059 }

StatusCode ServiceLocatorHelper::createService | ( | const std::string & | name,
|  | const InterfaceID & | iid,
|  | void ** | ppSvc |
| ) |  |  | const

Definition at line 62 of file ServiceLocatorHelper.cpp.

References endreq(), MSG::ERROR, StatusCode::FAILURE, ISvcLocator::getService(), isInThread(), StatusCode::isSuccess(), log(), name, IInterface::queryInterface(), serviceLocator(), threadedName(), and MSG::VERBOSE.

Referenced by getService(), Service::service_i(), AlgTool::service_i(), and Algorithm::service_i().

    00064                                                        {
    00065
    00066   IService* theSvc(0);
    00067   StatusCode sc(StatusCode::FAILURE);
    00068   if (isInThread()) {
    00069     //first we look for  a thread-specific version of the service
    00070     sc=serviceLocator()->getService(threadedName(name), theSvc, true);
    00071   };
    00072   // if not, try to find the common, single-threaded version of the service
    00073   if (!sc.isSuccess()) sc=serviceLocator()->getService(name, theSvc, true);
    00074
    00075   if ( sc.isSuccess() ) {
    00076     sc = theSvc->queryInterface(iid, ppSvc);
    00077     if (!sc.isSuccess()) {
    00078       *ppSvc=0;
    00079     }
    00080   } else {
    00081     *ppSvc = 0;
    00082   }
    00083
    00084   if (sc.isSuccess()) {
    00085 #ifndef NDEBUG
    00086     log() << MSG::VERBOSE
    00087           << "ServiceLocatorHelper::createService: found service "
    00088           << threadedName(name) <<endreq;
    00089 #endif
    00090   } else {
    00091     log() << MSG::ERROR
    00092           << "ServiceLocatorHelper::createService: can not create service "
    00093           << threadedName(name) << endreq;
    00094   }
    00095   return sc;
    00096 }

StatusCode ServiceLocatorHelper::createService | ( | const std::string & | type,
|  | const std::string & | name,
|  | const InterfaceID & | iid,
|  | void ** | ppSvc |
| ) |  |  | const

Definition at line 99 of file ServiceLocatorHelper.cpp.

References endreq(), MSG::ERROR, StatusCode::FAILURE, ISvcLocator::getService(), isInThread(), StatusCode::isSuccess(), log(), name, IInterface::queryInterface(), serviceLocator(), threadedName(), and MSG::VERBOSE.

    00102                                                         {
    00103
    00104
    00105   IService* theSvc(0);
    00106   StatusCode sc(StatusCode::FAILURE);
    00107
    00108   //first we need to declare it
    00109   try {
    00110     dynamic_cast<ISvcManager&>(*serviceLocator()).declareSvcType(threadedName(name),type).ignore();
    00111   }
    00112   catch(...) {
    00113     log() << MSG::ERROR
    00114           << "ServiceLocatorHelper::createService: can not declare service "
    00115           << threadedName(name) << " of type " << type << endreq;
    00116     return StatusCode::FAILURE;
    00117   }
    00118
    00119   if (isInThread()) {
    00120     //first we look for  a thread-specific version of the service
    00121     sc=serviceLocator()->getService(threadedName(name), theSvc, true);
    00122   };
    00123   // if not, try to find the common, single-threaded version of the service
    00124   if (!sc.isSuccess()) sc=serviceLocator()->getService(name, theSvc, true);
    00125
    00126
    00127   if ( sc.isSuccess() ) {
    00128     sc = theSvc->queryInterface(iid, ppSvc);
    00129     if (!sc.isSuccess()) {
    00130       *ppSvc=0;
    00131     }
    00132   } else {
    00133     *ppSvc = 0;
    00134   }
    00135
    00136   if (sc.isSuccess()) {
    00137 #ifndef NDEBUG
    00138     log() << MSG::VERBOSE
    00139           << "ServiceLocatorHelper::createService: found service "
    00140           << threadedName(name) <<endreq;
    00141 #endif
    00142   } else {
    00143     log() << MSG::ERROR
    00144           << "ServiceLocatorHelper::createService: can not create service "
    00145           << threadedName(name) << " of type " << type << endreq;
    00146   }
    00147   return sc;
    00148
    00149 }

std::string ServiceLocatorHelper::threadName | ( |  | ) | const`[private]`

Definition at line 8 of file ServiceLocatorHelper.cpp.

References getGaudiThreadIDfromName(), and requestorName().

Referenced by locateService(), and threadedName().

    00008                                        {
    00009   return getGaudiThreadIDfromName(requestorName());
    00010 }

std::string ServiceLocatorHelper::threadedName | ( | const std::string & | name | ) | const`[private]`

Definition at line 13 of file ServiceLocatorHelper.cpp.

References isInThread(), name, and threadName().

Referenced by createService().

    00013                                                               {
    00014   return ( isInThread() ? name + threadName() : name );
    00015 }

bool ServiceLocatorHelper::isInThread | ( |  | ) | const`[private]`

Definition at line 18 of file ServiceLocatorHelper.cpp.

References isGaudiThreaded(), and requestorName().

Referenced by createService(), locateService(), and threadedName().

    00018                                        {
    00019   return isGaudiThreaded(requestorName());
    00020 }

ISvcLocator* ServiceLocatorHelper::serviceLocator | ( |  | ) | const`[inline, private]`

Definition at line 48 of file ServiceLocatorHelper.h.

References m_svcLoc.

Referenced by createService(), and locateService().

    00048 { return &m_svcLoc; }

MsgStream& ServiceLocatorHelper::log | ( |  | ) | const`[inline, private]`

Definition at line 49 of file ServiceLocatorHelper.h.

References m_msgLog.

Referenced by createService(), and locateService().

    00049 { return m_msgLog; }

const std::string& ServiceLocatorHelper::requestorName | ( |  | ) | const`[inline, private]`

Definition at line 50 of file ServiceLocatorHelper.h.

References m_requestorName.

Referenced by isInThread(), and threadName().

    00050 { return m_requestorName; }

## Member Data Documentation

ISvcLocator& ServiceLocatorHelper::m_svcLoc`[private]`

Definition at line 51 of file ServiceLocatorHelper.h.

Referenced by serviceLocator().

MsgStream& ServiceLocatorHelper::m_msgLog`[private]`

Definition at line 52 of file ServiceLocatorHelper.h.

Referenced by log().

std::string ServiceLocatorHelper::m_requestorName`[private]`

Definition at line 53 of file ServiceLocatorHelper.h.

Referenced by requestorName().

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

- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiKernel/v25r2/GaudiKernel/ServiceLocatorHelper.h
- /afs/cern.ch/sw/Gaudi/releases/GAUDI/GAUDI_v20r2/GaudiKernel/v25r2/src/Lib/ServiceLocatorHelper.cpp