| The Gaudi Framework v29r0 (ff2e7097)

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

DLLClassManager.cpp
Go to the documentation of this file.
1 // Include files
2 #include "DLLClassManager.h"
3 #include "GaudiKernel/GaudiException.h"
4 #include "GaudiKernel/IAlgManager.h"
5 #include "GaudiKernel/IIncidentSvc.h"
6 #include "GaudiKernel/IService.h"
7 #include "GaudiKernel/ISvcLocator.h"
8 #include "GaudiKernel/ISvcManager.h"
9 #include "GaudiKernel/ModuleIncident.h"
10 #include "GaudiKernel/MsgStream.h"
11 #include "GaudiKernel/System.h"
12
13 #include "GaudiKernel/IAlgorithm.h"
14
15 #include <cassert>
16 #include <iostream>
17
18 // default creator
19 DLLClassManager::DLLClassManager( IInterface* iface )
20 {
21 m_pOuter = iface;
22 m_svclocator = m_pOuter;
23
24 assert( m_svclocator.isValid() );
25
26 addRef(); // Initial count set to 1
27 }
28
29 // implementation of IClassManager::loadModule
30 StatusCode DLLClassManager::loadModule( const std::string& module, bool fireIncident )
31 {
32 // Access the message service if not yet done already
33 if ( !m_msgsvc ) m_msgsvc = m_svclocator;
34 MsgStream log( m_msgsvc, "DllClassManager" );
35
36 std::string mod = module == "" ? System::moduleNameFull() : module;
37 if ( module == "NONE" ) return StatusCode::SUCCESS;
38
39 void* libHandle = nullptr;
40 StatusCode status = StatusCode::FAILURE;
41 try {
42 status = System::loadDynamicLib( module, &libHandle );
43 } catch ( const std::exception& excpt ) {
44 if ( m_msgsvc ) {
45 log << MSG::ERROR << "Exception whilst loading " << module << " : " << excpt.what() << endmsg;
46 }
47 status = StatusCode::FAILURE;
48 }
49
50 if ( status.isFailure() ) {
51 // DLL library not loaded
52 log << MSG::ERROR << "Could not load module " << module << endmsg;
53 log << MSG::ERROR << "System Error: " << System::getLastErrorString() << endmsg;
54 return StatusCode::FAILURE;
55 }
56 // FIXME this is a hack to avoid a very early call to moduleLoad from
57 // FIXME AppMgr::i_startup
58 if ( fireIncident && !module.empty() ) {
59 // now fire ModuleLoadedIncident
60 const bool CREATEIF( true );
61 auto pIncidentSvc = m_svclocator->service<IIncidentSvc>( "IncidentSvc", CREATEIF );
62 if ( !pIncidentSvc ) {
63 log << MSG::FATAL << "Can not locate IncidentSvc" << endmsg;
64 throw GaudiException( "Error retrieving IncidentSvc", "DLLClassManager::DLLClassManager", StatusCode::FAILURE );
65 }
66 pIncidentSvc->fireIncident( ModuleLoadedIncident( "DLLClassManager", module ) );
67 }
68
69 return StatusCode::SUCCESS;
70 }
71
72 // implementation of IInterface::queryInterface
73 StatusCode DLLClassManager::queryInterface( const InterfaceID& iid, void** pinterface )
74 {
75 // try local interfaces
76 StatusCode sc = base_class::queryInterface( iid, pinterface );
77 if ( sc.isSuccess() ) return sc;
78 // fall back on the owner
79 return m_pOuter->queryInterface( iid, pinterface );
80 }
System.h
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
StatusCode::SUCCESS
Definition: StatusCode.h:31
std::string::empty
T empty(T...args)
GaudiException
Define general base for Gaudi exception.
Definition: GaudiException.h:22
DLLClassManager::loadModule
StatusCode loadModule(const std::string &module, bool fireIncident=true) override
Definition: DLLClassManager.cpp:30
StatusCode::FAILURE
Definition: StatusCode.h:31
MsgStream.h
IAlgorithm.h
StatusCode::isSuccess
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
System::moduleNameFull
GAUDI_API const std::string & moduleNameFull()
Get the full name of the (executable/DLL) file.
Definition: ModuleInfo.cpp:78
Gaudi.CommonGaudiConfigurables.mod
mod
Definition: CommonGaudiConfigurables.py:22
StatusCode::isFailure
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:86
ISvcManager.h
std::string
STL class.
MSG::FATAL
Definition: IMessageSvc.h:16
ISvcLocator::service
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
InterfaceID
Interface ID class.
Definition: IInterface.h:29
std::exception::what
T what(T...args)
IIncidentSvc.h
DLLClassManager::m_msgsvc
SmartIF< IMessageSvc > m_msgsvc
Definition: DLLClassManager.h:43
implements< IClassManager >::addRef
unsigned long addRef() override
Reference Interface instance.
Definition: implements.h:41
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
GaudiException.h
IInterface
Definition of the basic interface.
Definition: IInterface.h:277
ModuleLoadedIncident
fired when a module (DLL) is loaded
Definition: ModuleIncident.h:46
std::exception
STL class.
IService.h
DLLClassManager::queryInterface
StatusCode queryInterface(const InterfaceID &iid, void **pinterface) override
implementation of IInterface::queryInterface
Definition: DLLClassManager.cpp:73
SmartIF::isValid
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
DLLClassManager.h
MSG::ERROR
Definition: IMessageSvc.h:16
IAlgManager.h
DLLClassManager::DLLClassManager
DLLClassManager(IInterface *iface)
Definition: DLLClassManager.cpp:19
ModuleIncident.h
DLLClassManager::m_svclocator
SmartIF< ISvcLocator > m_svclocator
Definition: DLLClassManager.h:42
System::getLastErrorString
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:291
implements::queryInterface
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:20
DLLClassManager::m_pOuter
SmartIF< IInterface > m_pOuter
Definition: DLLClassManager.h:44
ISvcLocator.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
Gaudi.Configuration.log
log
Definition: Configuration.py:13
System::loadDynamicLib
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:147
IInterface::queryInterface
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.