Apollo 10.0
自动驾驶开放平台
apollo::cyber::class_loader::SharedLibrary类 参考

#include <shared_library.h>

apollo::cyber::class_loader::SharedLibrary 的协作图:

Public 类型

enum  Flags { SHLIB_GLOBAL = 1 , SHLIB_LOCAL = 2 }
 

Public 成员函数

 SharedLibrary ()=default
 
virtual ~SharedLibrary ()
 
 SharedLibrary (const std::string &path)
 
 SharedLibrary (const std::string &path, int flags)
 
void Load (const std::string &path)
 
void Load (const std::string &path, int flags)
 
void Unload ()
 
bool IsLoaded ()
 
bool HasSymbol (const std::string &name)
 
void * GetSymbol (const std::string &name)
 
const std::string & GetPath () const
 
 SharedLibrary (const SharedLibrary &)=delete
 
SharedLibraryoperator= (const SharedLibrary &)=delete
 

详细描述

在文件 shared_library.h40 行定义.

成员枚举类型说明

◆ Flags

枚举值
SHLIB_GLOBAL 
SHLIB_LOCAL 

在文件 shared_library.h42 行定义.

42 {
43 // On platforms that use dlopen(), use RTLD_GLOBAL. This is the default
44 // if no flags are given.
45 SHLIB_GLOBAL = 1,
46
47 // On platforms that use dlopen(), use RTLD_LOCAL instead of RTLD_GLOBAL.
48 //
49 // Note that if this flag is specified, RTTI (including dynamic_cast and
50 // throw) will not work for types defined in the shared library with GCC
51 // and possibly other compilers as well. See
52 // http://gcc.gnu.org/faq.html#dso for more information.
53 SHLIB_LOCAL = 2,
54 };

构造及析构函数说明

◆ SharedLibrary() [1/4]

apollo::cyber::class_loader::SharedLibrary::SharedLibrary ( )
default

◆ ~SharedLibrary()

apollo::cyber::class_loader::SharedLibrary::~SharedLibrary ( )
virtual

在文件 shared_library.cc90 行定义.

90{}

◆ SharedLibrary() [2/4]

apollo::cyber::class_loader::SharedLibrary::SharedLibrary ( const std::string &  path)
explicit

在文件 shared_library.cc34 行定义.

34{ Load(path, 0); }

◆ SharedLibrary() [3/4]

apollo::cyber::class_loader::SharedLibrary::SharedLibrary ( const std::string &  path,
int  flags 
)

在文件 shared_library.cc36 行定义.

36 {
37 Load(path, flags);
38}

◆ SharedLibrary() [4/4]

apollo::cyber::class_loader::SharedLibrary::SharedLibrary ( const SharedLibrary )
delete

成员函数说明

◆ GetPath()

const std::string & apollo::cyber::class_loader::SharedLibrary::GetPath ( ) const
inline

在文件 shared_library.h108 行定义.

108{ return path_; }

◆ GetSymbol()

void * apollo::cyber::class_loader::SharedLibrary::GetSymbol ( const std::string &  name)

在文件 shared_library.cc78 行定义.

78 {
79 std::lock_guard<std::mutex> lock(mutex_);
80 if (!handle_) return nullptr;
81
82 void* result = dlsym(handle_, name.c_str());
83 if (!result) {
84 throw SymbolNotFoundException(name);
85 }
86
87 return result;
88}

◆ HasSymbol()

bool apollo::cyber::class_loader::SharedLibrary::HasSymbol ( const std::string &  name)

在文件 shared_library.cc74 行定义.

74 {
75 return GetSymbol(name) != nullptr;
76}
void * GetSymbol(const std::string &name)

◆ IsLoaded()

bool apollo::cyber::class_loader::SharedLibrary::IsLoaded ( )

在文件 shared_library.cc69 行定义.

69 {
70 std::lock_guard<std::mutex> lock(mutex_);
71 return handle_ != nullptr;
72}

◆ Load() [1/2]

void apollo::cyber::class_loader::SharedLibrary::Load ( const std::string &  path)

在文件 shared_library.cc40 行定义.

40{ Load(path, 0); }

◆ Load() [2/2]

void apollo::cyber::class_loader::SharedLibrary::Load ( const std::string &  path,
int  flags 
)

在文件 shared_library.cc42 行定义.

42 {
43 std::lock_guard<std::mutex> lock(mutex_);
44 if (handle_) throw LibraryAlreadyLoadedException(path);
45
46 int real_flag = RTLD_LAZY;
47 if (flags & SHLIB_LOCAL) {
48 real_flag |= RTLD_LOCAL;
49 } else {
50 real_flag |= RTLD_GLOBAL;
51 }
52 handle_ = dlopen(path.c_str(), real_flag);
53 if (!handle_) {
54 const char* err = dlerror();
55 throw LibraryLoadException(err ? std::string(err) : path);
56 }
57
58 path_ = path;
59}

◆ operator=()

SharedLibrary & apollo::cyber::class_loader::SharedLibrary::operator= ( const SharedLibrary )
delete

◆ Unload()

void apollo::cyber::class_loader::SharedLibrary::Unload ( )

在文件 shared_library.cc61 行定义.

61 {
62 std::lock_guard<std::mutex> lock(mutex_);
63 if (handle_) {
64 dlclose(handle_);
65 handle_ = nullptr;
66 }
67}

该类的文档由以下文件生成: