/proc/self/cwd/source/common/init/watcher_impl.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "source/common/init/watcher_impl.h" |
2 | | |
3 | | namespace Envoy { |
4 | | namespace Init { |
5 | | |
6 | | WatcherHandleImpl::WatcherHandleImpl(absl::string_view handle_name, absl::string_view name, |
7 | | std::weak_ptr<TargetAwareReadyFn> fn) |
8 | 15.0k | : handle_name_(handle_name), name_(name), fn_(std::move(fn)) {} |
9 | | |
10 | 13.3k | bool WatcherHandleImpl::ready() const { |
11 | 13.3k | auto locked_fn(fn_.lock()); |
12 | 13.3k | if (locked_fn) { |
13 | | // If we can "lock" a shared pointer to the watcher's callback function, call it. |
14 | 13.3k | ENVOY_LOG(debug, "{} initialized, notifying {}", handle_name_, name_); |
15 | 13.3k | (*locked_fn)(handle_name_); |
16 | 13.3k | return true; |
17 | 13.3k | } else { |
18 | | // If not, the watcher was already destroyed. |
19 | 50 | ENVOY_LOG(debug, "{} initialized, but can't notify {}", handle_name_, name_); |
20 | 50 | return false; |
21 | 50 | } |
22 | 13.3k | } |
23 | | |
24 | | WatcherImpl::WatcherImpl(absl::string_view name, ReadyFn fn) |
25 | | : name_(name), fn_(std::make_shared<TargetAwareReadyFn>( |
26 | 69.5k | [callback = std::move(fn)](absl::string_view) { callback(); })) {} |
27 | | |
28 | | WatcherImpl::WatcherImpl(absl::string_view name, TargetAwareReadyFn fn) |
29 | 72.5k | : name_(name), fn_(std::make_shared<TargetAwareReadyFn>(std::move(fn))) {} |
30 | | |
31 | 142k | WatcherImpl::~WatcherImpl() { ENVOY_LOG(debug, "{} destroyed", name_); } |
32 | | |
33 | 0 | absl::string_view WatcherImpl::name() const { return name_; } |
34 | | |
35 | 15.0k | WatcherHandlePtr WatcherImpl::createHandle(absl::string_view handle_name) const { |
36 | | // Note: can't use std::make_unique because WatcherHandleImpl ctor is private. |
37 | 15.0k | return std::unique_ptr<WatcherHandle>( |
38 | 15.0k | new WatcherHandleImpl(handle_name, name_, std::weak_ptr<TargetAwareReadyFn>(fn_))); |
39 | 15.0k | } |
40 | | |
41 | | } // namespace Init |
42 | | } // namespace Envoy |