The Gaudi Framework  v30r3 (a5ef0a68)
DLLClassManager Class Reference

#include <src/ApplicationMgr/DLLClassManager.h>

Inheritance diagram for DLLClassManager:
Collaboration diagram for DLLClassManager:

Public Member Functions

 DLLClassManager (IInterface *iface)
 
StatusCode loadModule (const std::string &module, bool fireIncident=true) override
 
StatusCode queryInterface (const InterfaceID &iid, void **pinterface) override
 implementation of IInterface::queryInterface More...
 
- Public Member Functions inherited from implements< IClassManager >
void * i_cast (const InterfaceID &tid) const override
 Implementation of IInterface::i_cast. More...
 
StatusCode queryInterface (const InterfaceID &ti, void **pp) override
 Implementation of IInterface::queryInterface. More...
 
std::vector< std::stringgetInterfaceNames () const override
 Implementation of IInterface::getInterfaceNames. More...
 
 implements ()=default
 Default constructor. More...
 
 implements (const implements &)
 Copy constructor (zero the reference count) More...
 
implementsoperator= (const implements &)
 Assignment operator (do not touch the reference count). More...
 
unsigned long addRef () override
 Reference Interface instance. More...
 
unsigned long release () override
 Release Interface instance. More...
 
unsigned long refCount () const override
 Current reference count. More...
 

Private Attributes

SmartIF< ISvcLocatorm_svclocator
 
SmartIF< IMessageSvcm_msgsvc
 
SmartIF< IInterfacem_pOuter
 

Additional Inherited Members

- Public Types inherited from implements< IClassManager >
using base_class = implements< Interfaces... >
 Typedef to this class. More...
 
using extend_interfaces_base = extend_interfaces< Interfaces... >
 Typedef to the base of this class. More...
 
using iids = typename extend_interfaces_base::ext_iids
 
- Public Types inherited from extend_interfaces< Interfaces... >
using ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
 take union of the ext_iids of all Interfaces... More...
 
- Protected Attributes inherited from implements< IClassManager >
std::atomic_ulong m_refCount
 Reference counter. More...
 

Detailed Description

Definition at line 28 of file DLLClassManager.h.

Constructor & Destructor Documentation

DLLClassManager::DLLClassManager ( IInterface iface)

Definition at line 20 of file DLLClassManager.cpp.

21 {
22  m_pOuter = iface;
24 
25  assert( m_svclocator.isValid() );
26 
27  addRef(); // Initial count set to 1
28 }
unsigned long addRef() override
Reference Interface instance.
Definition: implements.h:39
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:68
SmartIF< ISvcLocator > m_svclocator
SmartIF< IInterface > m_pOuter

Member Function Documentation

StatusCode DLLClassManager::loadModule ( const std::string module,
bool  fireIncident = true 
)
override

Definition at line 31 of file DLLClassManager.cpp.

32 {
33  // Access the message service if not yet done already
34  if ( !m_msgsvc ) m_msgsvc = m_svclocator;
35  MsgStream log( m_msgsvc, "DllClassManager" );
36 
37  std::string mod = module == "" ? System::moduleNameFull() : module;
38  if ( module == "NONE" ) return StatusCode::SUCCESS;
39 
40  void* libHandle = nullptr;
42  try {
43  status = System::loadDynamicLib( module, &libHandle ) ? StatusCode::SUCCESS : StatusCode::FAILURE;
44  } catch ( const std::exception& excpt ) {
45  if ( m_msgsvc ) {
46  log << MSG::ERROR << "Exception whilst loading " << module << " : " << excpt.what() << endmsg;
47  }
48  status = StatusCode::FAILURE;
49  }
50 
51  if ( status.isFailure() ) {
52  // DLL library not loaded
53  log << MSG::ERROR << "Could not load module " << module << endmsg;
54  log << MSG::ERROR << "System Error: " << System::getLastErrorString() << endmsg;
55  return StatusCode::FAILURE;
56  }
57  // FIXME this is a hack to avoid a very early call to moduleLoad from
58  // FIXME AppMgr::i_startup
59  if ( fireIncident && !module.empty() ) {
60  // now fire ModuleLoadedIncident
61  const bool CREATEIF( true );
62  auto pIncidentSvc = m_svclocator->service<IIncidentSvc>( "IncidentSvc", CREATEIF );
63  if ( !pIncidentSvc ) {
64  log << MSG::FATAL << "Can not locate IncidentSvc" << endmsg;
65  throw GaudiException( "Error retrieving IncidentSvc", "DLLClassManager::DLLClassManager", StatusCode::FAILURE );
66  }
67  pIncidentSvc->fireIncident( ModuleLoadedIncident( "DLLClassManager", module ) );
68  }
69 
70  return StatusCode::SUCCESS;
71 }
constexpr static const auto FAILURE
Definition: StatusCode.h:88
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
T empty(T...args)
Define general base for Gaudi exception.
GAUDI_API const std::string & moduleNameFull()
Get the full name of the (executable/DLL) file.
Definition: ModuleInfo.cpp:78
bool isFailure() const
Definition: StatusCode.h:139
STL class.
StatusCode service(const Gaudi::Utils::TypeNameString &name, T *&svc, bool createIf=true)
Templated method to access a service by name.
Definition: ISvcLocator.h:79
T what(T...args)
SmartIF< IMessageSvc > m_msgsvc
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
fired when a module (DLL) is loaded
STL class.
constexpr static const auto SUCCESS
Definition: StatusCode.h:87
SmartIF< ISvcLocator > m_svclocator
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:294
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209
The interface implemented by the IncidentSvc service.
Definition: IIncidentSvc.h:23
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:154
StatusCode DLLClassManager::queryInterface ( const InterfaceID iid,
void **  pinterface 
)
override

implementation of IInterface::queryInterface

Definition at line 74 of file DLLClassManager.cpp.

75 {
76  // try local interfaces
77  StatusCode sc = base_class::queryInterface( iid, pinterface );
78  if ( sc.isSuccess() ) return sc;
79  // fall back on the owner
80  return m_pOuter->queryInterface( iid, pinterface );
81 }
bool isSuccess() const
Definition: StatusCode.h:287
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
StatusCode queryInterface(const InterfaceID &ti, void **pp) override
Implementation of IInterface::queryInterface.
Definition: implements.h:20
SmartIF< IInterface > m_pOuter
virtual StatusCode queryInterface(const InterfaceID &ti, void **pp)=0
Set the void** to the pointer to the requested interface of the instance.

Member Data Documentation

SmartIF<IMessageSvc> DLLClassManager::m_msgsvc
private

Definition at line 42 of file DLLClassManager.h.

SmartIF<IInterface> DLLClassManager::m_pOuter
private

Definition at line 43 of file DLLClassManager.h.

SmartIF<ISvcLocator> DLLClassManager::m_svclocator
private

Definition at line 41 of file DLLClassManager.h.


The documentation for this class was generated from the following files: