The Gaudi Framework
master (bdbe7744)
Toggle main menu visibility
Loading...
Searching...
No Matches
DLLClassManager.cpp
Go to the documentation of this file.
1
/***********************************************************************************\
2
* (c) Copyright 1998-2025 CERN for the benefit of the LHCb and ATLAS collaborations *
3
* *
4
* This software is distributed under the terms of the Apache version 2 licence, *
5
* copied verbatim in the file "LICENSE". *
6
* *
7
* In applying this licence, CERN does not waive the privileges and immunities *
8
* granted to it by virtue of its status as an Intergovernmental Organization *
9
* or submit itself to any jurisdiction. *
10
\***********************************************************************************/
11
#include "
DLLClassManager.h
"
12
#include <
GaudiKernel/GaudiException.h
>
13
#include <
GaudiKernel/IAlgManager.h
>
14
#include <
GaudiKernel/IAlgorithm.h
>
15
#include <
GaudiKernel/IIncidentSvc.h
>
16
#include <
GaudiKernel/IMessageSvc.h
>
17
#include <
GaudiKernel/IService.h
>
18
#include <
GaudiKernel/ISvcLocator.h
>
19
#include <
GaudiKernel/ISvcManager.h
>
20
#include <
GaudiKernel/ModuleIncident.h
>
21
#include <
GaudiKernel/MsgStream.h
>
22
#include <
GaudiKernel/System.h
>
23
#include <cassert>
24
25
DLLClassManager::DLLClassManager
(
IInterface
* iface ) :
m_svclocator
( iface ),
m_pOuter
( iface ) {
26
assert(
m_svclocator
.isValid() );
27
addRef
();
// Initial count set to 1
28
}
29
30
StatusCode
DLLClassManager::loadModule
(
const
std::string& module,
bool
fireIncident ) {
31
// Access the message service if not yet done
32
if
( !
m_msgsvc
)
m_msgsvc
=
m_svclocator
;
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
;
39
StatusCode
status =
StatusCode::FAILURE
;
40
try
{
41
status =
System::loadDynamicLib
( module, &libHandle ) ?
StatusCode::SUCCESS
:
StatusCode::FAILURE
;
42
}
catch
(
const
std::exception& excpt ) {
43
if
(
m_msgsvc
) { log <<
MSG::ERROR
<<
"Exception whilst loading "
<< module <<
" : "
<< excpt.what() <<
endmsg
; }
44
status =
StatusCode::FAILURE
;
45
}
46
47
if
( status.
isFailure
() ) {
48
// DLL library not loaded
49
log <<
MSG::ERROR
<<
"Could not load module "
<< module <<
endmsg
;
50
log <<
MSG::ERROR
<<
"System Error: "
<<
System::getLastErrorString
() <<
endmsg
;
51
return
StatusCode::FAILURE
;
52
}
53
// FIXME this is a hack to avoid a very early call to moduleLoad from
54
// FIXME AppMgr::i_startup
55
if
( fireIncident && !module.empty() ) {
56
// now fire ModuleLoadedIncident
57
const
bool
CREATEIF(
true
);
58
auto
pIncidentSvc =
m_svclocator
->service<
IIncidentSvc
>(
"IncidentSvc"
, CREATEIF );
59
if
( !pIncidentSvc ) {
60
log <<
MSG::FATAL
<<
"Can not locate IncidentSvc"
<<
endmsg
;
61
throw
GaudiException
(
"Error retrieving IncidentSvc"
,
"DLLClassManager::DLLClassManager"
,
StatusCode::FAILURE
);
62
}
63
pIncidentSvc->
fireIncident
(
ModuleLoadedIncident
(
"DLLClassManager"
, module ) );
64
}
65
66
return
StatusCode::SUCCESS
;
67
}
68
69
void
const
*
DLLClassManager::i_cast
(
const
InterfaceID
& iid )
const
{
70
if
(
auto
output =
base_class::i_cast
( iid ) )
return
output;
71
// fall back on the owner
72
return
m_pOuter
->i_cast( iid );
73
}
DLLClassManager.h
GaudiException.h
IAlgManager.h
IAlgorithm.h
IIncidentSvc.h
IMessageSvc.h
IService.h
ISvcLocator.h
ISvcManager.h
ModuleIncident.h
MsgStream.h
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition
MsgStream.h:198
System.h
DLLClassManager::m_svclocator
SmartIF< ISvcLocator > m_svclocator
Definition
DLLClassManager.h:49
DLLClassManager::i_cast
void const * i_cast(const InterfaceID &iid) const override
Definition
DLLClassManager.cpp:69
DLLClassManager::loadModule
StatusCode loadModule(const std::string &module, bool fireIncident=true) override
Definition
DLLClassManager.cpp:30
DLLClassManager::DLLClassManager
DLLClassManager(IInterface *iface)
Definition
DLLClassManager.cpp:25
DLLClassManager::m_pOuter
SmartIF< IInterface > m_pOuter
Definition
DLLClassManager.h:51
DLLClassManager::m_msgsvc
SmartIF< IMessageSvc > m_msgsvc
Definition
DLLClassManager.h:50
GaudiException
Define general base for Gaudi exception.
Definition
GaudiException.h:29
IIncidentSvc
The interface implemented by the IncidentSvc service.
Definition
IIncidentSvc.h:30
IIncidentSvc::fireIncident
virtual void fireIncident(const Incident &incident)=0
Fire an Incident.
IInterface
Definition of the basic interface.
Definition
IInterface.h:225
InterfaceID
Interface ID class.
Definition
IInterface.h:38
ModuleLoadedIncident
fired when a module (DLL) is loaded
Definition
ModuleIncident.h:50
MsgStream
Definition of the MsgStream class used to transmit messages.
Definition
MsgStream.h:29
StatusCode
This class is used for returning status codes from appropriate routines.
Definition
StatusCode.h:64
StatusCode::isFailure
bool isFailure() const
Definition
StatusCode.h:118
StatusCode::SUCCESS
constexpr static const auto SUCCESS
Definition
StatusCode.h:99
StatusCode::FAILURE
constexpr static const auto FAILURE
Definition
StatusCode.h:100
MSG::FATAL
@ FATAL
Definition
IMessageSvc.h:22
MSG::ERROR
@ ERROR
Definition
IMessageSvc.h:22
System::loadDynamicLib
GAUDI_API unsigned long loadDynamicLib(const std::string &name, ImageHandle *handle)
Load dynamic link library.
Definition
System.cpp:109
System::getLastErrorString
GAUDI_API const std::string getLastErrorString()
Get last system error as string.
Definition
System.cpp:228
implements< IClassManager >::addRef
unsigned long addRef() const override
Definition
implements.h:50
implements< Interfaces... >::i_cast
void const * i_cast(const InterfaceID &tid) const override
Definition
implements.h:30
GaudiCoreSvc
src
ApplicationMgr
DLLClassManager.cpp
Generated on
for The Gaudi Framework by
1.17.0