44 #define DLL_HANDLE HMODULE
45 #define LOAD_LIBRARY(fname) LoadLibrary(fname)
46 #define FREE_LIBRARY(lib) FreeLibrary(lib);
47 #define RESOLVE_SYMBOL(lib,symb) (void *) GetProcAddress(lib,symb)
53 #define DLL_HANDLE void*
54 #define LOAD_LIBRARY(fname) dlopen(fname,RTLD_LAZY)
55 #define FREE_LIBRARY(lib) !dlclose(lib)
56 #define RESOLVE_SYMBOL(lib,symb) dlsym(lib,symb)
69 class EGS_LOCAL EGS_PrivateLibrary {
74 EGS_PrivateLibrary(
const char *lib_name,
const char *path = 0);
75 ~EGS_PrivateLibrary();
77 void *resolve(
const char *symb);
80 static const char *lib_prefix;
81 static const char *lib_suffix;
86 char EGS_PrivateLibrary::fs =
'/';
88 char EGS_PrivateLibrary::fs =
'\\';
90 const char *EGS_PrivateLibrary::lib_prefix =
"";
91 const char *EGS_PrivateLibrary::lib_suffix =
".dll";
93 char EGS_PrivateLibrary::fs =
'/';
94 const char *EGS_PrivateLibrary::lib_prefix =
"lib";
95 const char *EGS_PrivateLibrary::lib_suffix =
".so";
99 EGS_PrivateLibrary::EGS_PrivateLibrary(
const char *lib_name,
const char *path) {
103 egsWarning(
"EGS_Library::EGS_Library: null library name?\n");
109 if (fname[fname.size()-1] != fs) {
117 egsInformation(
"EGS_Library::EGS_Library: file name is <%s>\n",fname.c_str());
121 EGS_PrivateLibrary::~EGS_PrivateLibrary() {
127 bool EGS_PrivateLibrary::load() {
131 lib = LOAD_LIBRARY(fname.c_str());
138 egsInformation(
"In EGS_PrivateLibrary::load(): name = %s lib = 0x%x\n",
145 egsWarning(
"EGS_Library::load(): failed to load library %s\n",
148 egsWarning(
" error was: %d\n",GetLastError());
156 void *EGS_PrivateLibrary::resolve(
const char *symb) {
162 void *result = RESOLVE_SYMBOL(lib,symb);
164 egsInformation(
"In EGS_PrivateLibrary::resolve: symbol = %s result = 0x%x\n",
170 bool EGS_PrivateLibrary::unload() {
174 bool result = FREE_LIBRARY(lib);
183 pl =
new EGS_PrivateLibrary(lib_name,path);
195 return pl->resolve(symb);
203 return (
bool) pl->lib;
215 return pl->name.c_str();
219 return pl->fname.c_str();
224 EGS_PrivateLibrary p(lname,path);
229 return p.resolve(func);
const char * libraryFile() const
Returns the name of the DSO, including full path and platform-specific prefix and extension...
const char * libraryName() const
Returns the name of the library object as given in the constructor.
EGS_Library(const char *lib_name, const char *path=0)
Constructs the library object and sets the DSO name to lib_name.
Global egspp functions header file.
bool unload()
Unloads the library.
void setUnload(bool u)
Set automatic unloading to u.
EGS_InfoFunction EGS_EXPORT egsInformation
Always use this function for reporting the progress of a simulation and any other type of information...
EGS_Library class header file.
~EGS_Library()
Destructs the library object.
bool load()
Loads the library.
void * resolve(const char *func)
Returns the address of the exported symbol func.
bool autoUnload() const
Returns true if the library automatically unloads when the object is destructed, false otherwise...
EGS_InfoFunction EGS_EXPORT egsWarning
Always use this function for reporting warnings.
bool isLoaded() const
Returns true if the library is loaded, false otherwise.