24 #include <utils/system/dynamic_module/module.h>
25 #include <utils/system/file.h>
57 const char *Module::FILE_EXTENSION = SOEXT;
92 std::string full_filename =
"";
93 full_filename = filename_;
95 if (full_filename.find(
"." SOEXT, 0) != (full_filename.length() - 1 - strlen(FILE_EXTENSION))) {
97 full_filename +=
"." SOEXT;
110 if (full_filename ==
"") {
111 handle_ = dlopen(NULL, tflags);
120 handle_ = dlopen(full_filename.c_str(), tflags);
122 if (NULL == handle_) {
123 const char *err = dlerror();
128 e.
append(
"dlerror: %s", err);
132 is_resident_ =
false;
137 e.
append(
"File '%s' does not exist", full_filename.c_str());
155 if ((ref_count_ == 0) && !is_resident_) {
156 if (dlclose(handle_) != 0) {
177 if (ref_count_ > 0) {
189 return (ref_count_ == 0);
209 return (filename_ == cmod.filename_);
224 if (symbol_name == NULL) {
227 if (handle_ == NULL) {
231 return (dlsym(handle_, symbol_name) != NULL);
246 if (symbol_name == NULL)
251 return dlsym(handle_, symbol_name);
262 return FILE_EXTENSION;
281 if (filename_.find(
"/", 0) != std::string::npos) {
283 filename_.substr(filename_.rfind(
"/", filename_.length()) + 1, filename_.length());
286 return filename_.c_str();
Base class for exceptions in Fawkes.
void append(const char *format,...) noexcept
Append messages to the message list.
static bool is_regular(const char *filename)
Check if a file is a regular file.
ModuleOpenException(const char *msg)
Constructor.
Dynamic module loader for Linux, FreeBSD, and MacOS X.
virtual std::string get_filename()
Get the full file name of the module.
virtual std::string get_base_filename()
Get the base file name of the module.
ModuleFlags
Flags for the loading process.
@ MODULE_BIND_NOW
Resolve all symbols immediately when loading the library.
@ MODULE_BIND_LAZY
Perform lazy binding.
@ MODULE_NODELETE
Do not unload the library during dlclose().
@ MODULE_BIND_LOCAL
Symbols defined in this library are not made available to resolve references in subsequently loaded l...
@ MODULE_BIND_DEEP
Place the lookup scope of the symbols in this library ahead of the global scope.
@ MODULE_BIND_GLOBAL
Symbols defined in this library are not made available to resolve references in subsequently loaded l...
virtual void * get_symbol(const char *symbol_name)
Get a symbol from the module.
virtual void unref()
Decrease the reference count of this module.
virtual ~Module()
Destructor.
virtual unsigned int get_ref_count()
Get the reference count of this module.
virtual void ref()
Increment the reference count of this module.
virtual bool operator==(const Module &cmod)
Compare to another Module instance.
virtual void open()
Open the module.
virtual bool has_symbol(const char *symbol_name)
Check if the module has the given symbol.
virtual bool close()
Close the module.
static const char * get_file_extension()
Get file extension for dl modules.
virtual bool notref()
Check if there are no reference to this module.
Module(std::string filename, ModuleFlags flags=MODULE_FLAGS_DEFAULT)
Constructor.
Fawkes library namespace.