www.cemf.ir
dynamicLinkLibs.cpp
Go to the documentation of this file.
1
/*------------------------------- phasicFlow ---------------------------------
2
O C enter of
3
O O E ngineering and
4
O O M ultiscale modeling of
5
OOOOOOO F luid flow
6
------------------------------------------------------------------------------
7
Copyright (C): www.cemf.ir
8
email: hamid.r.norouzi AT gmail.com
9
------------------------------------------------------------------------------
10
Licence:
11
This file is part of phasicFlow code. It is a free software for simulating
12
granular and multiphase flows. You can redistribute it and/or modify it under
13
the terms of GNU General Public License v3 or any other later versions.
14
15
phasicFlow is distributed to help others in their research in the field of
16
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
19
-----------------------------------------------------------------------------*/
20
21
#include <dlfcn.h>
22
23
#include "
dynamicLinkLibs.hpp
"
24
#include "
List.hpp
"
25
#include "
streams.hpp
"
26
27
28
pFlow::dynamicLinkLibs::dynamicLinkLibs
(
29
const
dictionary
&dict,
30
word
libList)
31
{
32
33
wordList
libNames;
34
if
(dict.
containsDataEntry
(libList))
35
{
36
libNames = dict.
getVal
<
wordList
>(libList);
37
}
38
39
40
REPORT
(1)<<
"libs are "
<<
Green_Text
(libNames)<<
END_REPORT
;
41
42
for
(
auto
libName:libNames)
43
{
44
auto
* hndl =
open
(libName);
45
46
if
(hndl)
47
{
48
libs_
.insertIf(libName, hndl);
49
}
50
else
51
{
52
fatalExit
;
53
}
54
}
55
}
56
57
58
pFlow::dynamicLinkLibs::~dynamicLinkLibs
()
59
{
60
for
(
auto
&lib:libs_)
61
{
62
if
( lib.second && dlclose(lib.second) != 0)
63
{
64
warningInFunction
<<
"could not close lib "
<<lib.first<<
endl
;
65
}
66
}
67
}
68
69
void
*
pFlow::dynamicLinkLibs::open
(
word
libName)
70
{
71
REPORT
(2)<<
"Loading "
<<
Green_Text
(libName)<<
END_REPORT
;
72
73
void
* handle = dlopen(libName.c_str(), RTLD_LAZY|RTLD_GLOBAL);
74
75
if
(!handle)
76
{
77
warningInFunction
<<
"could not open lib "
<< libName<<
endl
;
78
return
nullptr
;
79
}
80
81
return
handle;
82
}
Green_Text
#define Green_Text(text)
Definition:
iOstream.hpp:42
pFlow::List< word >
pFlow::dynamicLinkLibs::dynamicLinkLibs
dynamicLinkLibs(const dictionary &dict, word libList="libs")
Definition:
dynamicLinkLibs.cpp:28
fatalExit
#define fatalExit
Fatal exit.
Definition:
error.hpp:98
pFlow::dynamicLinkLibs::libs_
wordHashMap< void * > libs_
Definition:
dynamicLinkLibs.hpp:36
REPORT
#define REPORT(n)
Definition:
streams.hpp:39
warningInFunction
#define warningInFunction
Report a warning.
Definition:
error.hpp:95
List.hpp
pFlow::word
std::string word
Definition:
builtinTypes.hpp:64
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition:
iOstream.hpp:341
pFlow::dictionary::containsDataEntry
bool containsDataEntry(const word &name) const
check if a data entry exist
Definition:
dictionary.cpp:761
pFlow::dynamicLinkLibs::open
void * open(word libName)
Definition:
dynamicLinkLibs.cpp:69
END_REPORT
#define END_REPORT
Definition:
streams.hpp:40
streams.hpp
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition:
dictionary.hpp:379
pFlow::dynamicLinkLibs::~dynamicLinkLibs
~dynamicLinkLibs()
Definition:
dynamicLinkLibs.cpp:58
dynamicLinkLibs.hpp
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition:
dictionary.hpp:67
src
phasicFlow
repository
systemControl
dynamicLinkLibs.cpp
Generated by
1.8.17