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