24 #include <utils/system/dynamic_module/module.h> 25 #include <utils/system/file.h> 57 const char *Module::FILE_EXTENSION = SOEXT;
93 std::string full_filename =
"";
94 full_filename = filename_;
96 if (full_filename.find(
"." SOEXT, 0) != (full_filename.length() - 1 - strlen(FILE_EXTENSION))) {
98 full_filename +=
"." SOEXT;
111 if (full_filename ==
"") {
112 handle_ = dlopen(NULL, tflags);
121 handle_ = dlopen(full_filename.c_str(), tflags);
123 if (NULL == handle_) {
124 const char *err = dlerror();
129 e.
append(
"dlerror: %s", err);
133 is_resident_ =
false;
138 e.
append(
"File '%s' does not exist", full_filename.c_str());
156 if ((ref_count_ == 0) && !is_resident_) {
157 if (dlclose(handle_) != 0) {
178 if (ref_count_ > 0) {
190 return (ref_count_ == 0);
210 return (filename_ == cmod.filename_);
225 if (symbol_name == NULL) {
228 if (handle_ == NULL) {
232 return (dlsym(handle_, symbol_name) != NULL);
247 if (symbol_name == NULL)
252 return dlsym(handle_, symbol_name);
263 return FILE_EXTENSION;
282 if (filename_.find(
"/", 0) != std::string::npos) {
284 filename_.substr(filename_.rfind(
"/", filename_.length()) + 1, filename_.length());
287 return filename_.c_str();
virtual void unref()
Decrease the reference count of this module.
virtual bool close()
Close the module.
ModuleOpenException(const char *msg)
Constructor.
virtual void open()
Open the module.
Fawkes library namespace.
virtual void ref()
Increment the reference count of this module.
virtual ~Module()
Destructor.
virtual unsigned int get_ref_count()
Get the reference count of this module.
ModuleFlags
Flags for the loading process.
virtual bool notref()
Check if there are no reference to this module.
Symbols defined in this library are not made available to resolve references in subsequently loaded l...
Dynamic module loader for Linux, FreeBSD, and MacOS X.
Base class for exceptions in Fawkes.
Do not unload the library during dlclose().
Symbols defined in this library are not made available to resolve references in subsequently loaded l...
Place the lookup scope of the symbols in this library ahead of the global scope.
virtual std::string get_base_filename()
Get the base file name of the module.
virtual void * get_symbol(const char *symbol_name)
Get a symbol from the module.
virtual bool operator==(const Module &cmod)
Compare to another Module instance.
static bool is_regular(const char *filename)
Check if a file is a regular file.
Module(std::string filename, ModuleFlags flags=MODULE_FLAGS_DEFAULT)
Constructor.
Resolve all symbols immediately when loading the library.
static const char * get_file_extension()
Get file extension for dl modules.
void append(const char *format,...)
Append messages to the message list.
virtual std::string get_filename()
Get the full file name of the module.
virtual bool has_symbol(const char *symbol_name)
Check if the module has the given symbol.