All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DLLClassManager.cpp
Go to the documentation of this file.
1 // $Id: DLLClassManager.cpp,v 1.17 2007/12/12 16:03:19 marcocle Exp $
2 
3 // Include files
5 #include "GaudiKernel/IService.h"
11 #include "GaudiKernel/MsgStream.h"
12 #include "DLLClassManager.h"
13 #include "GaudiKernel/System.h"
14 
15 #include "GaudiKernel/IAlgorithm.h"
16 
17 #include <iostream>
18 #include <cassert>
19 
20 // default creator
22  m_pOuter = iface;
24 
25  assert(m_svclocator.isValid());
26 
27  addRef(); // Initial count set to 1
28 }
29 
30 // virtual destructor
32 }
33 
34 // implementation of IClassManager::loadModule
35 StatusCode DLLClassManager::loadModule( const std::string& module,
36  bool fireIncident ) {
37  // Access the message service if not yet done already
38  if (!m_msgsvc.isValid()) {
40  }
41  MsgStream log(m_msgsvc, "DllClassManager");
42 
43  std::string mod = module=="" ? System::moduleNameFull() : module;
44  if( module == "NONE" ) return StatusCode::SUCCESS;
45 
46  void* libHandle = 0;
48  try
49  {
50  status = System::loadDynamicLib( module, &libHandle);
51  }
52  catch ( const std::exception & excpt )
53  {
54  if ( m_msgsvc )
55  {
56  log << MSG::ERROR << "Exception whilst loading " << module << " : " << excpt.what() << endmsg;
57  }
58  status = StatusCode::FAILURE;
59  }
60 
61  if( status.isFailure() ) {
62  // DLL library not loaded
63  log << MSG::ERROR << "Could not load module " << module << endmsg;
64  log << MSG::ERROR << "System Error: " << System::getLastErrorString() << endmsg;
65  return StatusCode::FAILURE;
66  }
67  //FIXME this is a hack to avoid a very early call to moduleLoad from
68  //FIXME AppMgr::i_startup
69  if (fireIncident && module != "") {
70  //now fire ModuleLoadedIncident
71  const bool CREATEIF(true);
72  SmartIF<IIncidentSvc> pIncidentSvc(m_svclocator->service("IncidentSvc", CREATEIF));
73  if( !pIncidentSvc.isValid() ) {
74  log << MSG::FATAL << "Can not locate IncidentSvc" << endmsg;
75  throw GaudiException("Error retrieving IncidentSvc",
76  "DLLClassManager::DLLClassManager", StatusCode::FAILURE);
77  }
78  pIncidentSvc->fireIncident(ModuleLoadedIncident("DLLClassManager",
79  module) );
80  }
81 
82  return StatusCode::SUCCESS;
83 }
84 
85 // implementation of IInterface::queryInterface
87  // try local interfaces
88  StatusCode sc = base_class::queryInterface(iid, pinterface);
89  if (sc.isSuccess()) return sc;
90  // fall back on the owner
91  return m_pOuter->queryInterface(iid, pinterface);
92 }
Definition of the MsgStream class used to transmit messages.
Definition: MsgStream.h:24
Define general base for Gaudi exception.
virtual ~DLLClassManager()
bool isSuccess() const
Test for a status code of SUCCESS.
Definition: StatusCode.h:75
GAUDI_API const std::string & moduleNameFull()
Get the full name of the (executable/DLL) file.
Definition: ModuleInfo.cpp:78
virtual StatusCode queryInterface(const InterfaceID &iid, void **pinterface)
implementation of IInterface::queryInterface
bool isFailure() const
Test for a status code of FAILURE.
Definition: StatusCode.h:85
Gaudi::InterfaceId< IInterface, 0, 0 > iid
Interface ID.
Definition: IInterface.h:164
Interface ID class.
Definition: IInterface.h:55
bool isValid() const
Allow for check if smart pointer is valid.
Definition: SmartIF.h:51
SmartIF< IMessageSvc > m_msgsvc
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:30
Definition of the basic interface.
Definition: IInterface.h:160
fired when a module (DLL) is loaded
virtual unsigned long addRef()=0
Increment the reference count of Interface instance.
DLLClassManager(IInterface *iface)
SmartIF< ISvcLocator > m_svclocator
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition: System.cpp:253
SmartIF< IInterface > m_pOuter
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244
virtual StatusCode loadModule(const std::string &module, bool fireIncident=true)
Declare a sharable library to be used for creating instances of a given algorithm type...
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition: System.cpp:123