SharedLibrary¶
-
class
cppmicroservices::SharedLibrary¶ The SharedLibrary class loads shared libraries at runtime.
Public Functions
-
SharedLibrary()¶
-
SharedLibrary(const SharedLibrary &other)¶
-
SharedLibrary(const std::string &libPath, const std::string &name)¶ Construct a SharedLibrary object using a library search path and a library base name.
- Parameters
libPath: An absolute path containing the shared libraryname: The base name of the shared library, without prefix and suffix.
-
SharedLibrary(const std::string &absoluteFilePath)¶ Construct a SharedLibrary object using an absolute file path to the shared library.
Using this constructor effectively disables all setters except SetFilePath().
- Parameters
absoluteFilePath: The absolute path to the shared library.
-
~SharedLibrary()¶ Destroys this object but does not unload the shared library.
-
SharedLibrary &
operator=(const SharedLibrary &other)¶
-
void
Load()¶ Loads the shared library pointed to by this SharedLibrary object.
On POSIX systems dlopen() is called with the RTLD_LAZY and RTLD_LOCAL flags unless the compiler is gcc 4.4.x or older. Then the RTLD_LAZY and RTLD_GLOBAL flags are used to load the shared library to work around RTTI problems across shared library boundaries.
- Exceptions
std::logic_error: If the library is already loaded.std::system_error: If loading the library failed.
-
void
Load(int flags)¶ Loads the shared library pointed to by this SharedLibrary object, using the specified flags on POSIX systems.
- Exceptions
std::logic_error: If the library is already loaded.std::system_error: If loading the library failed.
-
void
Unload()¶ Un-loads the shared library pointed to by this SharedLibrary object.
- Exceptions
std::runtime_error: If an error occurred while un-loading the shared library.
-
void
SetName(const std::string &name)¶ Sets the base name of the shared library.
Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used.
- Parameters
name: The base name of the shared library, without prefix and suffix.
-
std::string
GetName() const¶ Gets the base name of the shared library.
- Return
- The shared libraries base name.
-
std::string
GetFilePath(const std::string &name) const¶ Gets the absolute file path for the shared library with base name
name, using the search path returned by GetLibraryPath().- Return
- The absolute file path of the shared library.
- Parameters
name: The shared library base name.
-
void
SetFilePath(const std::string &absoluteFilePath)¶ Sets the absolute file path of this SharedLibrary object.
Using this methods with a non-empty
absoluteFilePathargument effectively disables all other setters.- Parameters
absoluteFilePath: The new absolute file path of this SharedLibrary object.
-
std::string
GetFilePath() const¶ Gets the absolute file path of this SharedLibrary object.
- Return
- The absolute file path of the shared library.
-
void
SetLibraryPath(const std::string &path)¶ Sets a new library search path.
Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used.
- Parameters
path: The new shared library search path.
-
std::string
GetLibraryPath() const¶ Gets the library search path of this SharedLibrary object.
- Return
- The library search path.
-
void
SetSuffix(const std::string &suffix)¶ Sets the suffix for shared library names (e.g.
lib). Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used.
- Parameters
suffix: The shared library name suffix.
-
std::string
GetSuffix() const¶ Gets the file name suffix of this SharedLibrary object.
- Return
- The file name suffix of the shared library.
-
void
SetPrefix(const std::string &prefix)¶ Sets the file name prefix for shared library names (e.g.
.dll or .so). Does nothing if the shared library is already loaded or the SharedLibrary(const std::string&) constructor was used.
- Parameters
prefix: The shared library name prefix.
-
std::string
GetPrefix() const¶ Gets the file name prefix of this SharedLibrary object.
- Return
- The file name prefix of the shared library.
-
void *
GetHandle() const¶ Gets the internal handle of this SharedLibrary object.
- Return
nullptrif the shared library is not loaded, the operating system specific handle otherwise.
-
bool
IsLoaded() const¶ Gets the loaded/unloaded stated of this SharedLibrary object.
- Return
trueif the shared library is loaded,falseotherwise.
-