rcutils  master
C API providing common utilities and data structures.
shared_library.h
Go to the documentation of this file.
1 // Copyright 2020 Open Source Robotics Foundation, Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef RCUTILS__SHARED_LIBRARY_H_
16 #define RCUTILS__SHARED_LIBRARY_H_
17 
18 #ifdef __cplusplus
19 extern "C"
20 {
21 #endif
22 
23 #include <string.h>
24 
25 #include "rcutils/allocator.h"
27 #include "rcutils/macros.h"
29 
32 {
34  void * lib_pointer;
36  char * library_path;
40 
42 /*
43  * This function returns an empty and zero initialized shared library struct.
44  *
45  * Example:
46  *
47  * ```c
48  * // Do not do this:
49  * // rcutils_shared_library_t foo;
50  * // rcutils_ret_t ret = rcutils_load_shared_library(
51  * // &foo,
52  * // "library_name",
53  * // rcutils_get_default_allocator()); // undefined behavior!
54  * // or
55  * // rcutils_ret_t ret = rcutils_unload_shared_library(&foo); // undefined behavior!
56  *
57  * // Do this instead:
58  * rcutils_shared_library_t bar = rcutils_get_zero_initialized_shared_library();
59  * rcutils_load_shared_library(&bar, "library_name", rcutils_get_default_allocator()); // ok
60  * void * symbol = rcutils_get_symbol(&bar, "bazinga"); // ok
61  * bool is_bazinga_symbol = rcutils_has_symbol(&bar, "bazinga"); // ok
62  * rcutils_ret_t ret = rcutils_unload_shared_library(&bar); // ok
63  * if (ret != RCUTILS_RET_ERROR) {
64  * // error handling
65  * }
66  * ```
67  * */
72 
74 
88  const char * library_path,
89  rcutils_allocator_t allocator);
90 
92 
99 void *
100 rcutils_get_symbol(const rcutils_shared_library_t * lib, const char * symbol_name);
101 
103 
110 bool
111 rcutils_has_symbol(const rcutils_shared_library_t * lib, const char * symbol_name);
112 
114 
124 
126 
135 bool
137 
139 
152  const char * library_name,
153  char * library_name_platform,
154  unsigned int buffer_size,
155  bool debug);
156 
157 #ifdef __cplusplus
158 }
159 #endif
160 
161 #endif // RCUTILS__SHARED_LIBRARY_H_
rcutils_shared_library_t
struct rcutils_shared_library_t rcutils_shared_library_t
Handle to a loaded shared library.
rcutils_has_symbol
bool rcutils_has_symbol(const rcutils_shared_library_t *lib, const char *symbol_name)
Return true if the shared library contains a specific symbol name otherwise returns false.
rcutils_unload_shared_library
rcutils_ret_t rcutils_unload_shared_library(rcutils_shared_library_t *lib)
Unload the shared library.
macros.h
rcutils_shared_library_t
Handle to a loaded shared library.
Definition: shared_library.h:31
rcutils_shared_library_t::lib_pointer
void * lib_pointer
The platform-specific pointer to the shared library.
Definition: shared_library.h:34
rcutils_shared_library_t::library_path
char * library_path
The path of the shared_library.
Definition: shared_library.h:36
rcutils_get_zero_initialized_shared_library
rcutils_shared_library_t rcutils_get_zero_initialized_shared_library(void)
Return an empty shared library struct.
RCUTILS_PUBLIC_TYPE
#define RCUTILS_PUBLIC_TYPE
Definition: visibility_control.h:29
rcutils_shared_library_t::allocator
rcutils_allocator_t allocator
allocator
Definition: shared_library.h:38
rcutils_ret_t
int rcutils_ret_t
Definition: rcutils_ret.h:23
RCUTILS_WARN_UNUSED
#define RCUTILS_WARN_UNUSED
Definition: macros.h:24
rcutils_ret.h
visibility_control.h
rcutils_get_platform_library_name
rcutils_ret_t rcutils_get_platform_library_name(const char *library_name, char *library_name_platform, unsigned int buffer_size, bool debug)
Get the library name for the compiled platform.
rcutils_allocator_t
Encapsulation of an allocator.
Definition: allocator.h:45
allocator.h
RCUTILS_PUBLIC
#define RCUTILS_PUBLIC
Definition: visibility_control.h:23
rcutils_load_shared_library
rcutils_ret_t rcutils_load_shared_library(rcutils_shared_library_t *lib, const char *library_path, rcutils_allocator_t allocator)
Return shared library pointer.
rcutils_is_shared_library_loaded
bool rcutils_is_shared_library_loaded(rcutils_shared_library_t *lib)
Check if the library is loaded.
rcutils_get_symbol
void * rcutils_get_symbol(const rcutils_shared_library_t *lib, const char *symbol_name)
Return shared library symbol pointer.