Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ServiceLocatorHelper.cpp
Go to the documentation of this file.
1 #include "GaudiKernel/IService.h"
6 
10 }
11 
14  return ( isInThread() ? name + threadName() : name );
15 }
16 
17 bool
20 }
21 
24  const InterfaceID& iid,
25  void** ppSvc,
26  bool quiet) const {
27  SmartIF<IService> theSvc = service(name, quiet, false);
28  if (!theSvc.isValid()) return StatusCode::FAILURE;
29  StatusCode sc = theSvc->queryInterface(iid, ppSvc);
30  if (!sc.isSuccess()) {
31  *ppSvc = 0;
32  if (!quiet) log() << MSG::ERROR
33  << "ServiceLocatorHelper::locateService: wrong interface id "
34  << iid << " for service " << name << endmsg;
35  }
36  return sc;
37 }
38 
41  const InterfaceID& iid,
42  void** ppSvc) const {
43  SmartIF<IService> theSvc = service(name, false, true);
44  if (!theSvc.isValid()) return StatusCode::FAILURE;
45  StatusCode sc = theSvc->queryInterface(iid, ppSvc);
46  if (!sc.isSuccess()) {
47  *ppSvc = 0;
48  log() << MSG::ERROR
49  << "ServiceLocatorHelper::createService: wrong interface id "
50  << iid << " for service " << name << endmsg;
51  }
52  return sc;
53 }
54 
57  const std::string& name,
58  const InterfaceID& iid,
59  void** ppSvc) const {
60  return createService(type + "/" + name, iid, ppSvc);
61 }
62 
63 SmartIF<IService> ServiceLocatorHelper::service(const std::string &name, const bool quiet, const bool createIf) const {
64  SmartIF<IService> theSvc;
65  if (isInThread()) {
66  //first we look for a thread-specific version of the service
67  theSvc = serviceLocator()->service(name + threadName(), createIf);
68  }
69  // if not, try to find the common, single-threaded version of the service
70  if (!theSvc.isValid()){
71  theSvc = serviceLocator()->service(name, createIf);
72  }
73 
74  if (theSvc.isValid()) {
75  if (!quiet) {
76  if (UNLIKELY(log().level() <= MSG::VERBOSE))
77  log() << MSG::VERBOSE
78  << "ServiceLocatorHelper::service: found service " << name <<endmsg;
79  }
80  } else {
81  // if not return an error
82  if (!quiet) {
83  log() << MSG::ERROR
84  << "ServiceLocatorHelper::service: can not locate service "
85  << name;
86  if (isInThread()) log() << MSG::ERROR << " or " << name + threadName();
87  log() << MSG::ERROR << endmsg;
88  }
89  }
90  return theSvc;
91 }

Generated at Wed Nov 28 2012 12:17:16 for Gaudi Framework, version v23r5 by Doxygen version 1.8.2 written by Dimitri van Heesch, © 1997-2004