![]() |
|
|
Generated: 24 Nov 2008 |
00001 // $Id: DLLClassManager.cpp,v 1.17 2007/12/12 16:03:19 marcocle Exp $ 00002 00003 // Include files 00004 #include "GaudiKernel/GaudiException.h" 00005 #include "GaudiKernel/ISvcLocator.h" 00006 #include "GaudiKernel/IAlgManager.h" 00007 #include "GaudiKernel/ISvcManager.h" 00008 #include "GaudiKernel/IIncidentSvc.h" 00009 #include "GaudiKernel/ModuleIncident.h" 00010 #include "GaudiKernel/MsgStream.h" 00011 #include "DLLClassManager.h" 00012 #include "GaudiKernel/System.h" 00013 00014 #include <iostream> 00015 #include <cassert> 00016 00017 // default creator 00018 DLLClassManager::DLLClassManager( IInterface* iface ) { 00019 m_pOuter = iface; 00020 m_pOuter->queryInterface(IID_ISvcLocator, pp_cast<void>(&m_svclocator)).ignore(); 00021 assert( 0 != m_svclocator ); 00022 m_msgsvc = 0; 00023 // m_algmanager = 0; 00024 // m_svcmanager = 0; 00025 // m_cnvmanager = 0; 00026 // m_objmanager = 0; 00027 m_refcount = 1; 00028 } 00029 00030 // virtual destructor 00031 DLLClassManager::~DLLClassManager() { 00032 if( m_msgsvc ) m_msgsvc->release(); 00033 //if( m_algmanager ) m_algmanager->release(); 00034 //if( m_svcmanager ) m_svcmanager->release(); 00035 //if( m_cnvmanager ) m_cnvmanager->release(); 00036 //if( m_objmanager ) m_objmanager->release(); 00037 if( m_svclocator ) m_svclocator->release(); 00038 } 00039 00040 // implementation of IClassManager::loadModule 00041 StatusCode DLLClassManager::loadModule( const std::string& module, 00042 bool fireIncident ) { 00043 // Access the message service if not yet done already 00044 if( m_msgsvc == 0 ) { 00045 m_svclocator->getService( "MessageSvc", IID_IMessageSvc, *pp_cast<IInterface>(&m_msgsvc) ).ignore(); 00046 } 00047 MsgStream log(m_msgsvc, "DllClassManager"); 00048 00049 std::string mod = module=="" ? System::moduleNameFull() : module; 00050 if( module == "NONE" ) return StatusCode::SUCCESS; 00051 00052 void* libHandle = 0; 00053 StatusCode status = StatusCode::FAILURE; 00054 try 00055 { 00056 status = System::loadDynamicLib( module, &libHandle); 00057 } 00058 catch ( const std::exception & excpt ) 00059 { 00060 if ( m_msgsvc ) 00061 { 00062 log << MSG::ERROR << "Exception whilst loading " << module << " : " << excpt.what() << endmsg; 00063 } 00064 status = StatusCode::FAILURE; 00065 } 00066 00067 if( status.isFailure() ) { 00068 // DLL library not loaded 00069 log << MSG::ERROR << "Could not load module " << module << endmsg; 00070 log << MSG::ERROR << "System Error: " << System::getLastErrorString() << endmsg; 00071 return StatusCode::FAILURE; 00072 } 00073 //FIXME this is a hack to avoid a very early call to moduleLoad from 00074 //FIXME AppMgr::i_startup 00075 if (fireIncident && module != "") { 00076 //now fire ModuleLoadedIncident 00077 IIncidentSvc* pIncidentSvc(0); 00078 const bool CREATEIF(true); 00079 StatusCode sc(m_svclocator->service("IncidentSvc", pIncidentSvc, CREATEIF)); 00080 if( !sc.isSuccess() ) { 00081 log << MSG::FATAL << "Can not locate IncidentSvc" << endreq; 00082 throw GaudiException("Error retrieving IncidentSvc", 00083 "DLLClassManager::DLLClassManager", sc); 00084 } 00085 pIncidentSvc->fireIncident(ModuleLoadedIncident("DLLClassManager", 00086 module) ); 00087 pIncidentSvc->release(); 00088 } 00089 00090 return StatusCode::SUCCESS; 00091 } 00092 00093 // implmentation of IInterface::addRef 00094 unsigned long DLLClassManager::addRef() { 00095 m_refcount++; 00096 return m_refcount; 00097 } 00098 00099 // implmentation of IInterface::release 00100 unsigned long DLLClassManager::release() { 00101 unsigned long count = --m_refcount; 00102 if( count <= 0) { 00103 delete this; 00104 } 00105 return count; 00106 } 00107 00108 // implementation of IInterface::queryInterface 00109 StatusCode DLLClassManager::queryInterface(const InterfaceID& iid, void** pinterface) { 00110 if( iid == IID_IInterface ) { 00111 *pinterface = (IInterface*)this; 00112 addRef(); 00113 return StatusCode::SUCCESS; 00114 } 00115 else if ( iid == IID_IClassManager ) { 00116 *pinterface = (IClassManager*)this; 00117 addRef(); 00118 return StatusCode::SUCCESS; 00119 } 00120 else { 00121 return m_pOuter->queryInterface(iid, pinterface); 00122 } 00123 return StatusCode::SUCCESS; 00124 } 00125 00126 00127 00128