Gaudi Framework, version v23r5

Home   Generated: Wed Nov 28 2012
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Bootstrap.cpp
Go to the documentation of this file.
1 //$Id: Bootstrap.cpp,v 1.14 2007/12/12 16:02:32 marcocle Exp $
2 
3 #include <iostream>
4 
6 #include "GaudiKernel/System.h"
7 
10 #include "GaudiKernel/IService.h"
11 #include "GaudiKernel/IAppMgrUI.h"
14 
15 #include "Reflex/PluginService.h"
16 using ROOT::Reflex::PluginService;
17 
18 
19 namespace Gaudi
20 {
21 
37  class BootSvcLocator : public implements1<ISvcLocator> {
38  public:
40  virtual ~BootSvcLocator();
41 #if !defined(GAUDI_V22_API)|| defined(G22_NEW_SVCLOCATOR)
42  virtual StatusCode getService( const Gaudi::Utils::TypeNameString& typeName,
43  const InterfaceID& iid,
44  IInterface*& pinterface );
45  virtual StatusCode getService( const Gaudi::Utils::TypeNameString& typeName,
46  IService*& svc,
47  const bool createIf = true);
48 #endif
49  virtual const std::list<IService*>& getServices( ) const;
50  virtual bool existsService( const std::string& name ) const;
51 
53  virtual SmartIF<IService> &service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf = true);
54 
55  };
56 }
57 
58 
61 
62 //------------------------------------------------------------------------------
64  const std::string& factname)
65 //------------------------------------------------------------------------------
66 {
67  // Allow not for multiple AppManagers: If already instantiated then just
68  // return it
69  if ( !s_appmgrInstance.isValid() ) {
70  s_appmgrInstance = createApplicationMgrEx(dllname, factname);
71  s_svclocInstance = s_appmgrInstance;
72  }
73  return s_appmgrInstance.get();
74 }
75 
76 //------------------------------------------------------------------------------
78  const std::string& factname)
79 //------------------------------------------------------------------------------
80 {
81  StatusCode status;
82  IInterface* iif;
83  IAppMgrUI* iappmgr;
84 
85  // Create an instance of the application Manager
86  iif = Gaudi::createInstance( "ApplicationMgr", factname, dllname );
87  if( iif == 0 ) {
88  return 0;
89  }
90  // Locate few interfaces of the Application Manager
91  status = iif->queryInterface( IAppMgrUI::interfaceID(), pp_cast<void>(&iappmgr) );
92  if( status.isFailure() ) {
93  return 0;
94  }
95  iif->release();
96  return iappmgr;
97 }
98 
99 //------------------------------------------------------------------------------
101 //------------------------------------------------------------------------------
102 //
103 // A dual-stage boostrap mechanism is used to ensure an orderly startup
104 // of the ApplicationMgr. If this function is called before the singleton
105 // ApplicationMgr instance exists, a BootSvcLocator singleton instance is
106 // created. This responds to any subsequent requests for services by
107 // returning StatusCode::FAILURE, unless the ApplicationMgr singleton
108 // instance has been created in the interim. In this case, the BootSvcLocator
109 // forwards the request to the ApplicationMgr instance. The motiviation for
110 // this is to handle static object instances where the constructor attempts
111 // to locate services and would otherwise instantiate the ApplicationMgr
112 // instance in an unorderly manner. This logic requires that the
113 // ApplicationMgr instance is created explicitly.
114 
115 {
116  if( !s_svclocInstance.isValid() ) {
117  IAppMgrUI* iappmgr = createApplicationMgr();
118  if( iappmgr ) {
119  s_svclocInstance = iappmgr;
120  if( s_svclocInstance.isValid() ) {
121  return s_svclocInstance;
122  }
123  }
124  //---Reverted change to create a Minimal SvcLocator in case is requested before AppMgr is created
125  //if( 0 == s_appmgrInstance ) {
126  // s_svclocInstance = new BootSvcLocator();
127  //} else {
128  // StatusCode sc = s_appmgrInstance->queryInterface( ISvcLocator::interfaceID(),
129  // pp_cast<void>(&s_svclocInstance) );
130  // if( sc.isSuccess() ) {
131  // return s_svclocInstance;
132  // }
133  //}
134  }
135  return s_svclocInstance;
136 }
137 
138 //------------------------------------------------------------------------------
140 //------------------------------------------------------------------------------
141 {
142  ISvcLocator* oldInstance = s_svclocInstance.get();
143  s_svclocInstance = newInstance;
144  s_appmgrInstance = s_svclocInstance;
145  return oldInstance;
146 }
147 
148 //------------------------------------------------------------------------------
150 //------------------------------------------------------------------------------
151 {
152  IAppMgrUI* oldInstance = s_appmgrInstance.get();
153  s_appmgrInstance = newInstance;
154  s_svclocInstance = s_appmgrInstance;
155  return oldInstance;
156 }
157 
158 //------------------------------------------------------------------------------
160  const std::string& factname,
161  const std::string& dllname)
162 //------------------------------------------------------------------------------
163 {
164 
165  IInterface* ii = PluginService::Create<IInterface*>(factname,(IInterface*)0);
166  if ( ii ) return ii;
167  IService* is = PluginService::Create<IService*>(factname, name, (ISvcLocator*)0);
168  if ( is ) return is;
169  IAlgorithm* ia = PluginService::Create<IAlgorithm*>(factname, name, (ISvcLocator*)0);
170  if ( ia ) return ia;
171 
172  StatusCode status;
173  void* libHandle = 0;
174  status = System::loadDynamicLib( dllname, &libHandle);
175  if ( status.isSuccess() ) {
176  ii = PluginService::Create<IInterface*>(factname, (IInterface*)0);
177  if ( ii ) return ii;
178  is = PluginService::Create<IService*>(factname, name, (ISvcLocator*)0);
179  if ( is ) return is;
180  ia = PluginService::Create<IAlgorithm*>(factname, name, (ISvcLocator*)0);
181  if ( ia ) return ia;
182 
183  return 0;
184  }
185  else {
186  // DLL library not loaded. Try in the local module
188  std::cout << "Gaudi::Bootstrap: Not found DLL " << dllname << std::endl;
189  return 0;
190  }
191 }
192 
193 namespace {
194  class ShadowEntry {
195  public:
196  std::string dllName;
197  std::string facName;
198  IFactory* fac;
199  public:
200  ShadowEntry() {
201  }
202  ShadowEntry(const std::string& d, const std::string& n, const IFactory* f) {
203  dllName = d;
204  facName = n;
205  fac = const_cast<IFactory*>(f);
206  }
207  ShadowEntry(const ShadowEntry& copy) {
208  dllName = copy.dllName;
209  facName = copy.facName;
210  fac = copy.fac;
211  }
212  };
213 }
214 
215 //------------------------------------------------------------------------------
217 //------------------------------------------------------------------------------
218  return createApplicationMgr(dllname, "ApplicationMgr");
219 }
220 
221 //------------------------------------------------------------------------------
223 //------------------------------------------------------------------------------
224  return createApplicationMgr("GaudiCoreSvc", "ApplicationMgr");
225 }
226 
227 //=======================================================================
228 // BootSvcLocator
229 //=======================================================================
230 
234 
235 using Gaudi::BootSvcLocator;
236 
237 BootSvcLocator::BootSvcLocator() {
238 }
239 BootSvcLocator::~BootSvcLocator() {
240 }
241 
242 #if !defined(GAUDI_V22_API) || defined(G22_NEW_SVCLOCATOR)
243 StatusCode Gaudi::BootSvcLocator::getService( const Gaudi::Utils::TypeNameString& typeName,
244  const InterfaceID& iid,
245  IInterface*& pinterface ) {
247  if ( s_appmgrInstance.isValid() ) {
248  sc = s_svclocInstance->getService(typeName, iid, pinterface );
249  } else {
250  pinterface = s_bootInterface.get();
251  }
252  return sc;
253 }
254 StatusCode Gaudi::BootSvcLocator::getService( const Gaudi::Utils::TypeNameString& typeName,
255  IService*& svc,
256  const bool createIf ) {
258  if ( s_appmgrInstance.isValid() ) {
259  sc = s_svclocInstance->getService(typeName, svc, createIf );
260  } else {
261  svc = s_bootService.get();
262  }
263  return sc;
264 }
265 #endif
266 
269  if ( s_appmgrInstance.isValid() ) {
270  return s_svclocInstance->getServices( );
271  } else {
272  return s_bootServices;
273  }
274 }
276  bool result = false;
277  if ( s_appmgrInstance.isValid() ) {
278  result = s_svclocInstance->existsService(name);
279  }
280  return result;
281 }
282 
283 
284 SmartIF<IService>& Gaudi::BootSvcLocator::service(const Gaudi::Utils::TypeNameString &typeName, const bool createIf) {
285  if ( s_appmgrInstance.isValid() ) {
286  return s_svclocInstance->service(typeName, createIf);
287  } else {
288  return s_bootService;
289  }
290 }

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