Gaudi Framework, version v23r0

Home   Generated: Mon Jan 30 2012
Public Member Functions | Private Member Functions | Private Attributes

ServiceLocatorHelper Class Reference

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

#include <ServiceLocatorHelper.h>

Collaboration diagram for ServiceLocatorHelper:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 ServiceLocatorHelper (ISvcLocator &svcLoc, const INamedInterface &requester)
 ServiceLocatorHelper (ISvcLocator &svcLoc, const std::string &loggedName, const std::string &requesterName)
 ServiceLocatorHelper (ISvcLocator &svcLoc, const std::string &requesterName)
 ServiceLocatorHelper (ISvcLocator &svcLoc, const MsgStream &log, const std::string &requesterName)
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
SmartIF< IServiceservice (const std::string &name, const bool quiet=false, const bool createIf=true) const

Private Member Functions

std::string threadName () const
std::string threadedName (const std::string &name) const
bool isInThread () const
ISvcLocatorserviceLocator () const
MsgStreamlog () const
const std::stringrequesterName () const

Private Attributes

ISvcLocatorm_svcLoc
MsgStream m_msgLog
std::string m_requesterName

Detailed Description

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

Definition at line 18 of file ServiceLocatorHelper.h.


Constructor & Destructor Documentation

ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const INamedInterface requester 
) [inline]

Definition at line 20 of file ServiceLocatorHelper.h.

                                                                             :
    m_svcLoc(svcLoc),
    m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requester.name()), //use requester msg level
    m_requesterName(requester.name()) {
  }
ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const std::string loggedName,
const std::string requesterName 
) [inline]

Definition at line 25 of file ServiceLocatorHelper.h.

                                     :
    m_svcLoc(svcLoc),
    m_msgLog(SmartIF<IMessageSvc>(&svcLoc), loggedName), //use requester msg level
    m_requesterName(requesterName) {
  }
ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const std::string requesterName 
) [inline]

Definition at line 32 of file ServiceLocatorHelper.h.

                                                                           :
    m_svcLoc(svcLoc),
    m_msgLog(SmartIF<IMessageSvc>(&svcLoc), requesterName), //use requester msg level
    m_requesterName(requesterName) {
  }
ServiceLocatorHelper::ServiceLocatorHelper ( ISvcLocator svcLoc,
const MsgStream log,
const std::string requesterName 
) [inline]

Definition at line 38 of file ServiceLocatorHelper.h.


Member Function Documentation

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

Definition at line 40 of file ServiceLocatorHelper.cpp.

                                                        {
  SmartIF<IService> theSvc = service(name, false, true);
  if (!theSvc.isValid()) return StatusCode::FAILURE;
  StatusCode sc = theSvc->queryInterface(iid, ppSvc);
  if (!sc.isSuccess()) {
    *ppSvc = 0;
    log() << MSG::ERROR
      << "ServiceLocatorHelper::createService: wrong interface id "
      << iid << " for service " << name << endmsg;
  }
  return sc;
}
StatusCode ServiceLocatorHelper::createService ( const std::string type,
const std::string name,
const InterfaceID iid,
void **  ppSvc 
) const

Definition at line 56 of file ServiceLocatorHelper.cpp.

                                                        {
  return createService(type + "/" + name, iid, ppSvc);
}
StatusCode ServiceLocatorHelper::getService ( const std::string name,
bool  createIf,
const InterfaceID iid,
void **  ppSvc 
) const [inline]

Definition at line 44 of file ServiceLocatorHelper.h.

                                            {
    return (createIf ?
            createService(name, iid, ppSvc) :
            locateService(name, iid, ppSvc, true));
  }
bool ServiceLocatorHelper::isInThread (  ) const [private]

Definition at line 18 of file ServiceLocatorHelper.cpp.

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

Definition at line 23 of file ServiceLocatorHelper.cpp.

                                                      {
  SmartIF<IService> theSvc = service(name, quiet, false);
  if (!theSvc.isValid()) return StatusCode::FAILURE;
  StatusCode sc = theSvc->queryInterface(iid, ppSvc);
  if (!sc.isSuccess()) {
    *ppSvc = 0;
    if (!quiet) log() << MSG::ERROR
      << "ServiceLocatorHelper::locateService: wrong interface id "
      << iid << " for service " << name << endmsg;
  }
  return sc;
}
MsgStream& ServiceLocatorHelper::log (  ) const [inline, private]

Definition at line 74 of file ServiceLocatorHelper.h.

{ return m_msgLog; }
const std::string& ServiceLocatorHelper::requesterName (  ) const [inline, private]

Definition at line 75 of file ServiceLocatorHelper.h.

{ return m_requesterName; }
SmartIF< IService > ServiceLocatorHelper::service ( const std::string name,
const bool  quiet = false,
const bool  createIf = true 
) const

Definition at line 63 of file ServiceLocatorHelper.cpp.

                                                                                                                  {
  SmartIF<IService> theSvc;
  if (isInThread()) {
    //first we look for  a thread-specific version of the service
    theSvc = serviceLocator()->service(name + threadName(), createIf);
  }
  // if not, try to find the common, single-threaded version of the service
  if (!theSvc.isValid()){
    theSvc = serviceLocator()->service(name, createIf);
  }

  if (theSvc.isValid()) {
    if (!quiet) {
      if (UNLIKELY(log().level() <= MSG::VERBOSE))
        log() << MSG::VERBOSE
              << "ServiceLocatorHelper::service: found service " << name <<endmsg;
    }
  } else {
    // if not return an error
    if (!quiet) {
      log() << MSG::ERROR
            << "ServiceLocatorHelper::service: can not locate service "
            << name;
      if (isInThread()) log() << MSG::ERROR << " or " << name + threadName();
      log() << MSG::ERROR << endmsg;
    }
  }
  return theSvc;
}
ISvcLocator* ServiceLocatorHelper::serviceLocator (  ) const [inline, private]

Definition at line 73 of file ServiceLocatorHelper.h.

{ return &m_svcLoc; }
std::string ServiceLocatorHelper::threadedName ( const std::string name ) const [private]

Definition at line 13 of file ServiceLocatorHelper.cpp.

                                                              {
  return ( isInThread() ? name + threadName() : name );
}
std::string ServiceLocatorHelper::threadName (  ) const [private]

Definition at line 8 of file ServiceLocatorHelper.cpp.


Member Data Documentation

Definition at line 77 of file ServiceLocatorHelper.h.

Definition at line 78 of file ServiceLocatorHelper.h.

Definition at line 76 of file ServiceLocatorHelper.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines

Generated at Mon Jan 30 2012 13:53:21 for Gaudi Framework, version v23r0 by Doxygen version 1.7.2 written by Dimitri van Heesch, © 1997-2004