MCPcopy Create free account
hub / github.com/CppMicroServices/CppMicroServices / Load

Method Load

framework/src/util/SharedLibrary.cpp:86–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84 SharedLibrary& SharedLibrary::operator=(SharedLibrary const& other) = default;
85
86 void
87 SharedLibrary::Load(int flags)
88 {
89 if (d->m_Handle)
90 throw std::logic_error(std::string("Library already loaded: ") + GetFilePath());
91 std::string libPath = GetFilePath();
92#ifdef US_PLATFORM_POSIX
93 d->m_Handle = dlopen(libPath.c_str(), flags);
94 if (!d->m_Handle)
95 {
96 std::error_code err_code(errno, std::generic_category());
97 std::string err_msg = "Error loading " + libPath + ".";
98 char const* err = dlerror();
99 if (err)
100 {
101 err_msg += " " + std::string(err);
102 }
103
104 d->m_Handle = nullptr;
105
106 // Bundle of origin information is not available here. It will be
107 // BundlePrivate::Start0() will catch this system_error and create
108 // a SharedLibraryException.
109 throw std::system_error(err_code, err_msg);
110 }
111#else
112 US_UNUSED(flags);
113 std::wstring wpath(cppmicroservices::util::ToWString(libPath));
114 d->m_Handle = LoadLibraryW(wpath.c_str());
115
116 if (!d->m_Handle)
117 {
118 std::error_code err_code(GetLastError(), std::generic_category());
119 std::string errMsg = "Loading ";
120 errMsg.append(libPath).append("failed with error: ").append(util::GetLastWin32ErrorStr());
121
122 d->m_Handle = nullptr;
123
124 // Bundle of origin information is not available here. Use try/catch
125 // around SharedLibrary::Load(), and throw a SharedLibraryException
126 // inside the catch statement, with the available bundle of origin.
127 throw std::system_error(err_code, errMsg);
128 }
129#endif
130 }
131
132 void
133 SharedLibrary::Load()

Callers 15

TEST_FFunction · 0.45
TESTFunction · 0.45
TEST_FFunction · 0.45
destroySingletonMethod · 0.45
destroyPrototypeMethod · 0.45
ServiceReferenceBaseMethod · 0.45
SetInterfaceIdMethod · 0.45
GetPropertyMethod · 0.45
GetPropertyKeysMethod · 0.45
GetBundleMethod · 0.45
GetUsingBundlesMethod · 0.45

Calls 4

dlopenFunction · 0.85
dlerrorFunction · 0.85
ToWStringFunction · 0.85
GetLastWin32ErrorStrFunction · 0.85

Tested by 3

TEST_FFunction · 0.36
TESTFunction · 0.36
TEST_FFunction · 0.36