Report problems to ATLAS LXR Team (with time and IP address indicated)

The LXR Cross Referencer

source navigation ]
diff markup ]
identifier search ]
general search ]
 
 
Architecture: linux ]
Version: head ] [ nightly ] [ GaudiDev ]
  Links to LXR source navigation pages for stable releases [ 12.*.* ]   [ 13.*.* ]   [ 14.*.* ] 

001 //$Id: Bootstrap.cpp,v 1.14 2007/12/12 16:02:32 marcocle Exp $
002 
003 #include <iostream>
004 
005 #include "GaudiKernel/Bootstrap.h"
006 #include "GaudiKernel/System.h"
007 
008 #include "GaudiKernel/IInterface.h"
009 #include "GaudiKernel/IAlgorithm.h"
010 #include "GaudiKernel/IService.h"
011 #include "GaudiKernel/IAppMgrUI.h"
012 #include "GaudiKernel/ISvcLocator.h"
013 #include "GaudiKernel/IClassManager.h"
014 
015 #include "Reflex/PluginService.h"
016 using ROOT::Reflex::PluginService;
017 
018 
019 namespace Gaudi 
020 {
021   
022 /** @class BootSvcLocator
023 
024     A dual-stage boostrap mechanism is used to ensure an orderly startup
025     of the ApplicationMgr. If this function is called before the singleton
026     ApplicationMgr instance exists, a BootstrapAppMgr singleton instance is
027     created. This responds to any subsequent requests for services by
028     returning StatusCode::FAILURE, unless the ApplicationMgr singleton 
029     instance has been created in the interim. In this case, the BootstrapAppMgr
030     forwards the request to the ApplicationMgr instance. The motiviation for
031     this is to handle static object instances where the constructor attempts
032     to locate services and would otherwise instantiate the ApplicationMgr
033     instance in an unorderly manner. This logic requires that the 
034     ApplicationMgr instance is created explicitly.
035     
036 */
037   class BootSvcLocator : virtual public ISvcLocator {
038   public:
039     BootSvcLocator();
040     virtual ~BootSvcLocator();
041     /// implmentation of IInterface::addRef
042     virtual unsigned long addRef();
043     /// implmentation of IInterface::release
044     virtual unsigned long release();
045     /// implementation of IInterface::queryInterface
046     virtual StatusCode queryInterface(const InterfaceID& iid, void** pinterface);
047     virtual StatusCode getService( const std::string& name, 
048                                    IService*&  svc );
049     virtual StatusCode getService( const std::string& name,
050                                    const InterfaceID& iid,
051                                    IInterface*& pinterface );
052     virtual StatusCode getService( const std::string& name,
053                                    IService*& svc,
054                                    bool createIf );
055     virtual const std::list<IService*>& getServices( ) const;
056     virtual bool existsService( const std::string& name ) const;
057   private:
058     unsigned long m_refcount;    ///< Reference counter
059   };
060 }
061 
062 
063 static ISvcLocator* s_svclocInstance = 0;
064 static IAppMgrUI*   s_appmgrInstance = 0;
065 
066 //------------------------------------------------------------------------------
067 bool Gaudi::hasApplicationMgr()
068 //------------------------------------------------------------------------------
069 {
070   //Return true if the applicationmgr has already been created
071   if ( 0 == s_appmgrInstance ) {
072     return false;
073   }
074   return true;
075 }
076 
077 //------------------------------------------------------------------------------
078 IAppMgrUI* Gaudi::createApplicationMgr(const std::string& dllname,
079                                        const std::string& factname)
080 //------------------------------------------------------------------------------
081 {
082   // Allow not for multiple AppManagers: If already instantiated then just
083   // return it
084   if ( 0 == s_appmgrInstance )    {
085     s_appmgrInstance = createApplicationMgrEx(dllname, factname);
086     StatusCode sc = s_appmgrInstance->queryInterface( IID_ISvcLocator,
087                                                       pp_cast<void>(&s_svclocInstance) );
088   }
089   return s_appmgrInstance;
090 }
091 
092 //------------------------------------------------------------------------------
093 IAppMgrUI* Gaudi::createApplicationMgrEx(const std::string& dllname,
094                                          const std::string& factname)
095 //------------------------------------------------------------------------------
096 {
097   StatusCode     status;
098   IInterface*    iif;
099   IAppMgrUI*     iappmgr;
100 
101   // Create an instance of the application Manager
102   iif = Gaudi::createInstance( "ApplicationMgr", factname, dllname );
103   if( iif == 0 ) {
104     return 0;
105   }
106   // Locate few interfaces of the Application Manager
107   status = iif->queryInterface( IID_IAppMgrUI, pp_cast<void>(&iappmgr) );
108   if( status.isFailure() ) {
109     return 0;
110   }
111   iif->release();
112   return iappmgr;
113 }
114 
115 //------------------------------------------------------------------------------
116 ISvcLocator* Gaudi::svcLocator()
117 //------------------------------------------------------------------------------
118 //
119 // A dual-stage boostrap mechanism is used to ensure an orderly startup
120 // of the ApplicationMgr. If this function is called before the singleton
121 // ApplicationMgr instance exists, a BootSvcLocator singleton instance is
122 // created. This responds to any subsequent requests for services by
123 // returning StatusCode::FAILURE, unless the ApplicationMgr singleton 
124 // instance has been created in the interim. In this case, the BootSvcLocator
125 // forwards the request to the ApplicationMgr instance. The motiviation for
126 // this is to handle static object instances where the constructor attempts
127 // to locate services and would otherwise instantiate the ApplicationMgr
128 // instance in an unorderly manner. This logic requires that the 
129 // ApplicationMgr instance is created explicitly.
130 
131 {
132   if( 0 == s_svclocInstance )   {
133     IAppMgrUI* iappmgr = createApplicationMgr();
134     if( iappmgr ) {
135       StatusCode sc = iappmgr->queryInterface( IID_ISvcLocator,
136                                                pp_cast<void>(&s_svclocInstance) );
137       if( sc.isSuccess() ) {
138         return s_svclocInstance;
139       }
140     }
141     //---Reverted change to create a Minimal SvcLocator in case is requested before AppMgr is created
142     //if( 0 == s_appmgrInstance ) {
143     //  s_svclocInstance = new BootSvcLocator();
144     //} else {
145     //  StatusCode sc = s_appmgrInstance->queryInterface( IID_ISvcLocator,
146     //                                                  pp_cast<void>(&s_svclocInstance) );
147     //  if( sc.isSuccess() ) {
148     //    return s_svclocInstance;
149     //  }
150     //}
151   }
152   return s_svclocInstance;
153 }
154 
155 //------------------------------------------------------------------------------
156 ISvcLocator* Gaudi::setInstance(ISvcLocator* newInstance)
157 //------------------------------------------------------------------------------
158 {
159   ISvcLocator* oldInstance = s_svclocInstance;
160   s_svclocInstance = newInstance;
161   if ( s_appmgrInstance )     {
162     s_appmgrInstance->release();
163     s_appmgrInstance = 0;
164   }
165   if ( s_svclocInstance )    {
166     s_svclocInstance->queryInterface (IID_IAppMgrUI, pp_cast<void>(&s_appmgrInstance));
167   }
168   return oldInstance;
169 }
170 
171 //------------------------------------------------------------------------------
172 IAppMgrUI* Gaudi::setInstance(IAppMgrUI* newInstance)
173 //------------------------------------------------------------------------------
174 {
175   IAppMgrUI* oldInstance = s_appmgrInstance;
176   s_appmgrInstance = newInstance;
177   if ( s_svclocInstance )     {
178     s_svclocInstance->release();
179     s_svclocInstance = 0;
180   }
181   if ( s_appmgrInstance )    {
182     s_appmgrInstance->queryInterface (IID_ISvcLocator,
183                                       pp_cast<void>(&s_svclocInstance));
184   }
185   return oldInstance;
186 }
187 
188 //------------------------------------------------------------------------------
189 IInterface* Gaudi::createInstance( const std::string& name, 
190                                                 const std::string& factname, 
191                                                 const std::string& dllname)
192 //------------------------------------------------------------------------------
193 {
194 
195   IInterface* ii = PluginService::Create<IInterface*>(factname,(IInterface*)0);
196   if ( ii ) return ii;
197   IService* is = PluginService::Create<IService*>(factname, name, (ISvcLocator*)0);
198   if ( is ) return is;
199   IAlgorithm* ia = PluginService::Create<IAlgorithm*>(factname, name, (ISvcLocator*)0);
200   if ( ia ) return ia;
201 
202   StatusCode status;
203   void* libHandle = 0;
204   status = System::loadDynamicLib( dllname, &libHandle);
205   if ( status.isSuccess() )   {
206     IInterface* ii = PluginService::Create<IInterface*>(factname, (IInterface*)0);
207     if ( ii ) return ii;
208     IService* is = PluginService::Create<IService*>(factname, name, (ISvcLocator*)0);
209     if ( is ) return is;
210     IAlgorithm* ia = PluginService::Create<IAlgorithm*>(factname, name, (ISvcLocator*)0);
211     if ( ia ) return ia;
212 
213     return 0;
214   }
215   else {
216     // DLL library not loaded. Try in the local module
217     std::cout << System::getLastErrorString() << std::endl;
218     std::cout << "Gaudi::Bootstrap: Not found DLL " << dllname << std::endl;
219     return 0; 
220   }
221 }
222 
223 namespace {
224   class ShadowEntry    {
225   public:
226     std::string dllName;
227     std::string facName;
228     IFactory*   fac;
229   public:
230     ShadowEntry() {
231     }
232     ShadowEntry(const std::string& d, const std::string& n, const IFactory* f) {
233       dllName = d;
234       facName = n;
235       fac     = const_cast<IFactory*>(f);
236     }
237     ShadowEntry(const ShadowEntry& copy)   {
238       dllName = copy.dllName;
239       facName = copy.facName;
240       fac     = copy.fac;
241     }
242     ShadowEntry& operator=(const ShadowEntry& copy)   {
243       dllName = copy.dllName;
244       facName = copy.facName;
245       fac     = copy.fac;
246       return *this;
247     }
248   };
249 }
250 
251 //------------------------------------------------------------------------------
252 IAppMgrUI* Gaudi::createApplicationMgr(const std::string& dllname )    {
253 //------------------------------------------------------------------------------
254   return createApplicationMgr(dllname, "ApplicationMgr");
255 }
256 
257 //------------------------------------------------------------------------------
258 IAppMgrUI* Gaudi::createApplicationMgr()    {
259 //------------------------------------------------------------------------------
260   return createApplicationMgr("GaudiSvc", "ApplicationMgr");
261 }
262 
263 //=======================================================================
264 // BootSvcLocator
265 //=======================================================================
266 
267 static std::list<IService*> s_bootServices;
268 static IService*            s_bootService   = 0;
269 static IInterface*          s_bootInterface = 0;
270 
271 using Gaudi::BootSvcLocator;
272 
273 BootSvcLocator::BootSvcLocator() {
274   m_refcount = 0;
275 }
276 BootSvcLocator::~BootSvcLocator() {
277 }
278 unsigned long BootSvcLocator::addRef() {
279   m_refcount++;
280   return m_refcount;
281 }
282 unsigned long BootSvcLocator::release() {
283   unsigned long count = --m_refcount;
284   if( count <= 0) {
285     delete this;
286   }
287   return count;
288 }
289 StatusCode Gaudi::BootSvcLocator::queryInterface(const InterfaceID& iid, void** pinterface)
290 {
291   if( iid == IID_IInterface ) {  
292     *pinterface = (IInterface*)this;
293     addRef();
294     return StatusCode::SUCCESS;
295   } 
296   else if ( iid == IID_ISvcLocator ) {
297     *pinterface = (ISvcLocator*)this;
298     addRef();
299     return StatusCode::SUCCESS;
300   } 
301   return StatusCode::FAILURE;
302 }
303 StatusCode Gaudi::BootSvcLocator::getService( const std::string& name, 
304                                        IService*&  svc ) {
305   StatusCode sc = StatusCode::FAILURE;
306   if ( 0 != s_appmgrInstance ) {
307     sc = s_svclocInstance->getService(name, svc );
308   } else {
309     svc = s_bootService;
310   }
311   return sc;
312 }
313 StatusCode Gaudi::BootSvcLocator::getService( const std::string& name,
314                                        const InterfaceID& iid,
315                                        IInterface*& pinterface ) {
316   StatusCode sc = StatusCode::FAILURE;
317   if ( 0 != s_appmgrInstance ) {
318     sc = s_svclocInstance->getService(name, iid, pinterface );
319   } else {
320     pinterface = s_bootInterface;
321   }
322   return sc;
323 }
324 StatusCode Gaudi::BootSvcLocator::getService( const std::string& name,
325                                        IService*& svc,
326                                        bool createIf ) {
327   StatusCode sc = StatusCode::FAILURE;
328   if ( 0 != s_appmgrInstance ) {
329     sc = s_svclocInstance->getService(name, svc, createIf );
330   } else {
331     svc = s_bootService;
332   }
333   return sc;
334 }
335 const std::list<IService*>& Gaudi::BootSvcLocator::getServices( ) const {
336   StatusCode sc = StatusCode::FAILURE;
337   if ( 0 != s_appmgrInstance ) {
338     return s_svclocInstance->getServices( );
339   } else {
340     return s_bootServices;
341   }
342 }
343 bool Gaudi::BootSvcLocator::existsService( const std::string& name ) const {
344   bool result = false;
345   if ( 0 != s_appmgrInstance ) {
346     result = s_svclocInstance->existsService(name );
347   }
348   return result;
349 }

source navigation ] diff markup ] identifier search ] general search ]

Due to the LXR bug, the updates fail sometimes to remove references to deleted files. The Saturday's full rebuilds fix these problems
This page was automatically generated by the LXR engine. Valid HTML 4.01!