DART 6.12.2
Loading...
Searching...
No Matches
SharedLibrary.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2021, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_COMMON_SHAREDLIBRARY_HPP_
34#define DART_COMMON_SHAREDLIBRARY_HPP_
35
36#include <memory>
37#include <string>
38
39#include <boost/filesystem.hpp>
40
43
44#if DART_OS_LINUX
45
46 #define DYNLIB_HANDLE void*
47
48#elif DART_OS_MACOS
49
50 #define DYNLIB_HANDLE void*
51
52#elif DART_OS_WINDOWS
53
55using hInstance = HINSTANCE__*;
56 #define DYNLIB_HANDLE hInstance
57
58#endif
59
60#if DART_OS_LINUX
61static constexpr const char* DART_SHARED_LIB_EXTENSION = "so";
62#elif DART_OS_MACOS
63static constexpr const char* DART_SHARED_LIB_EXTENSION = "dylib";
64#elif DART_OS_WINDOWS
65static constexpr const char* DART_SHARED_LIB_EXTENSION = "dll";
66#else
67 #error Unhandled platform
68#endif
69
70#if DART_OS_LINUX
71static constexpr const char* DART_SHARED_LIB_PREFIX = "lib";
72#elif DART_OS_MACOS
73static constexpr const char* DART_SHARED_LIB_PREFIX = "lib";
74#elif DART_OS_WINDOWS
75static constexpr const char* DART_SHARED_LIB_PREFIX = "";
76#else
77 #error Unhandled platform
78#endif
79
80namespace dart {
81namespace common {
82
83namespace detail {
84class SharedLibraryManager;
85} // namespace detail
86
89{
90protected:
95
96public:
110 DART_DEPRECATED(6.10)
111 static std::shared_ptr<SharedLibrary> create(
112 const boost::filesystem::path& path);
113
125 static std::shared_ptr<SharedLibrary> create(const std::string& path);
126
140 DART_DEPRECATED(6.10)
141 explicit SharedLibrary(
142 ProtectedConstructionTag, const boost::filesystem::path& path);
143
155 explicit SharedLibrary(ProtectedConstructionTag, const std::string& path);
156
158 virtual ~SharedLibrary();
159
161 const boost::filesystem::path& getCanonicalPath() const;
162
164 const std::string& path() const;
165
167 bool isValid() const;
168
174 void* getSymbol(const std::string& symbolName) const;
175
176protected:
177 friend class detail::SharedLibraryManager;
178
182 boost::filesystem::path mCanonicalPath;
183 // TODO(JS): Remove in DART 7.
184
188 std::string mPath;
189
191 DYNLIB_HANDLE mInstance;
192
193private:
195 std::string getLastError() const;
196};
197
198} // namespace common
199} // namespace dart
200
201#endif // DART_COMMON_SHAREDLIBRARY_HPP_
#define DART_DEPRECATED(version)
Definition Deprecated.hpp:51
SharedLibrary is a RAII object wrapping a shared library.
Definition SharedLibrary.hpp:89
boost::filesystem::path mCanonicalPath
Canonical path to the shared library where a canonical path is an absolute path that has no elements ...
Definition SharedLibrary.hpp:182
ProtectedConstructionTag
Definition SharedLibrary.hpp:92
@ ProtectedConstruction
Definition SharedLibrary.hpp:93
bool isValid() const
Returns true if the shared library loading was successful.
Definition SharedLibrary.cpp:119
const boost::filesystem::path & getCanonicalPath() const
Returns the path to the shared library file.
Definition SharedLibrary.cpp:107
const std::string & path() const
Returns the path to the shared library file.
Definition SharedLibrary.cpp:113
std::string mPath
Canonical path to the shared library where a canonical path is an absolute path that has no elements ...
Definition SharedLibrary.hpp:188
static std::shared_ptr< SharedLibrary > create(const boost::filesystem::path &path)
Creates a SharedLibrary from a path to the shared library.
Definition SharedLibrary.cpp:59
void * getSymbol(const std::string &symbolName) const
Returns a symbol from the shared library if it exists.
Definition SharedLibrary.cpp:125
friend class detail::SharedLibraryManager
Definition SharedLibrary.hpp:177
std::string getLastError() const
Returns the last loading error.
Definition SharedLibrary.cpp:143
DYNLIB_HANDLE mInstance
Handle to the loaded library.
Definition SharedLibrary.hpp:191
Definition BulletCollisionDetector.cpp:60
Definition SharedLibraryManager.hpp:46