|
6 | 6 | #include "runner.hpp" |
7 | 7 |
|
8 | 8 | #include "client.hpp" |
| 9 | +#include "ffi.hpp" |
| 10 | +#include <chrono> |
9 | 11 | #include <csignal> |
10 | | -#include <cstdio> |
11 | 12 | #include <spdlog/spdlog.h> |
12 | 13 | #include <stdexcept> |
13 | 14 | #include <sys/stat.h> |
| 15 | +#include <thread> |
14 | 16 |
|
15 | 17 | extern "C" { |
| 18 | +#include <common.h> |
16 | 19 | #include <dlfcn.h> |
17 | 20 | } |
18 | 21 |
|
19 | | -namespace { |
20 | | -struct ConfigInvariants; |
21 | | -struct Arc_Target; |
22 | | - |
23 | 22 | using in_proc_notify_fn = void (*)( |
24 | | - const ConfigInvariants *invariants, const Arc_Target *target); |
| 23 | + const ddog_ConfigInvariants *invariants, const ddog_Arc_Target *target); |
25 | 24 |
|
26 | | -void (*ddog_set_rc_notify_fn)(in_proc_notify_fn notify_fn); |
27 | | -char *(*ddog_remote_config_path)(const ConfigInvariants *, const Arc_Target *); |
28 | | -void (*ddog_remote_config_path_free)(char *); |
29 | | -} // namespace |
| 25 | +extern "C" void ddog_set_rc_notify_fn(in_proc_notify_fn notify_fn); |
| 26 | + |
| 27 | +SIDECAR_FFI_SYMBOL(ddog_set_rc_notify_fn); |
| 28 | +SIDECAR_FFI_SYMBOL(ddog_remote_config_path); |
| 29 | +SIDECAR_FFI_SYMBOL(ddog_remote_config_path_free); |
30 | 30 |
|
31 | 31 | namespace dds { |
32 | 32 |
|
@@ -109,31 +109,25 @@ void runner::register_for_rc_notifications() |
109 | 109 | SPDLOG_INFO("Register RC update callback"); |
110 | 110 | std::atomic_store(&runner::RUNNER_FOR_NOTIFICATIONS, shared_from_this()); |
111 | 111 |
|
112 | | - ddog_set_rc_notify_fn( |
113 | | - [](const ConfigInvariants *invariants, const Arc_Target *target) { |
114 | | - char *path = ddog_remote_config_path(invariants, target); |
115 | | - |
116 | | - if (path == nullptr) { |
117 | | - // NOLINTNEXTLINE(bugprone-lambda-function-name) |
118 | | - SPDLOG_ERROR("Failed to get remote config path"); |
119 | | - return; |
120 | | - } |
121 | | - |
122 | | - const std::shared_ptr<runner> runner = |
123 | | - std::atomic_load(&RUNNER_FOR_NOTIFICATIONS); |
124 | | - if (!runner) { |
125 | | - // NOLINTNEXTLINE(bugprone-lambda-function-name) |
126 | | - SPDLOG_WARN("No runner to notify of remote config updates"); |
127 | | - ddog_remote_config_path_free(path); |
128 | | - return; |
129 | | - } |
| 112 | + ffi::ddog_set_rc_notify_fn([](const ddog_ConfigInvariants *invariants, |
| 113 | + const ddog_Arc_Target *target) { |
| 114 | + char *path = ffi::ddog_remote_config_path(invariants, target); |
130 | 115 |
|
| 116 | + const std::shared_ptr<runner> runner = |
| 117 | + std::atomic_load(&RUNNER_FOR_NOTIFICATIONS); |
| 118 | + if (!runner) { |
131 | 119 | // NOLINTNEXTLINE(bugprone-lambda-function-name) |
132 | | - SPDLOG_INFO("Remote config updated notification for {}", path); |
133 | | - // TODO: move the updates to a separate thread |
134 | | - runner->service_manager_->notify_of_rc_updates(path); |
135 | | - ddog_remote_config_path_free(path); |
136 | | - }); |
| 120 | + SPDLOG_WARN("No runner to notify of remote config updates"); |
| 121 | + ffi::ddog_remote_config_path_free(path); |
| 122 | + return; |
| 123 | + } |
| 124 | + |
| 125 | + // NOLINTNEXTLINE(bugprone-lambda-function-name) |
| 126 | + SPDLOG_INFO("Remote config updated notification for {}", path); |
| 127 | + // TODO: move the updates to a separate thread |
| 128 | + runner->service_manager_->notify_of_rc_updates(path); |
| 129 | + ffi::ddog_remote_config_path_free(path); |
| 130 | + }); |
137 | 131 | } |
138 | 132 |
|
139 | 133 | void runner::unregister_for_rc_notifications() |
@@ -189,31 +183,4 @@ void runner::run() |
189 | 183 | SPDLOG_INFO("Pool stopped"); |
190 | 184 | } |
191 | 185 |
|
192 | | -void runner::resolve_symbols() |
193 | | -{ |
194 | | - // NOLINTNEXTLINE |
195 | | - ddog_set_rc_notify_fn = reinterpret_cast<decltype(ddog_set_rc_notify_fn)>( |
196 | | - dlsym(RTLD_DEFAULT, "ddog_set_rc_notify_fn")); |
197 | | - if (ddog_set_rc_notify_fn == nullptr) { |
198 | | - throw std::runtime_error{"Failed to resolve ddog_set_rc_notify_fn"}; |
199 | | - } |
200 | | - |
201 | | - ddog_remote_config_path = |
202 | | - // NOLINTNEXTLINE |
203 | | - reinterpret_cast<decltype(ddog_remote_config_path)>( |
204 | | - dlsym(RTLD_DEFAULT, "ddog_remote_config_path")); |
205 | | - if (ddog_remote_config_path == nullptr) { |
206 | | - throw std::runtime_error{"Failed to resolve ddog_remote_config_path"}; |
207 | | - } |
208 | | - |
209 | | - ddog_remote_config_path_free = |
210 | | - // NOLINTNEXTLINE |
211 | | - reinterpret_cast<decltype(ddog_remote_config_path_free)>( |
212 | | - dlsym(RTLD_DEFAULT, "ddog_remote_config_path_free")); |
213 | | - if (ddog_remote_config_path_free == nullptr) { |
214 | | - throw std::runtime_error{ |
215 | | - "Failed to resolve ddog_remote_config_path_free"}; |
216 | | - } |
217 | | -} |
218 | | - |
219 | 186 | } // namespace dds |
0 commit comments