LCOV - code coverage report
Current view: top level - source/common/init - watcher_impl.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 19 20 95.0 %
Date: 2024-01-05 06:35:25 Functions: 7 8 87.5 %

          Line data    Source code
       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         863 :     : handle_name_(handle_name), name_(name), fn_(std::move(fn)) {}
       9             : 
      10         845 : bool WatcherHandleImpl::ready() const {
      11         845 :   auto locked_fn(fn_.lock());
      12         845 :   if (locked_fn) {
      13             :     // If we can "lock" a shared pointer to the watcher's callback function, call it.
      14         823 :     ENVOY_LOG(debug, "{} initialized, notifying {}", handle_name_, name_);
      15         823 :     (*locked_fn)(handle_name_);
      16         823 :     return true;
      17         823 :   } else {
      18             :     // If not, the watcher was already destroyed.
      19          22 :     ENVOY_LOG(debug, "{} initialized, but can't notify {}", handle_name_, name_);
      20          22 :     return false;
      21          22 :   }
      22         845 : }
      23             : 
      24             : WatcherImpl::WatcherImpl(absl::string_view name, ReadyFn fn)
      25             :     : name_(name), fn_(std::make_shared<TargetAwareReadyFn>(
      26        1922 :                        [callback = std::move(fn)](absl::string_view) { callback(); })) {}
      27             : 
      28             : WatcherImpl::WatcherImpl(absl::string_view name, TargetAwareReadyFn fn)
      29        1962 :     : name_(name), fn_(std::make_shared<TargetAwareReadyFn>(std::move(fn))) {}
      30             : 
      31        3884 : WatcherImpl::~WatcherImpl() { ENVOY_LOG(debug, "{} destroyed", name_); }
      32             : 
      33           0 : absl::string_view WatcherImpl::name() const { return name_; }
      34             : 
      35         863 : WatcherHandlePtr WatcherImpl::createHandle(absl::string_view handle_name) const {
      36             :   // Note: can't use std::make_unique because WatcherHandleImpl ctor is private.
      37         863 :   return std::unique_ptr<WatcherHandle>(
      38         863 :       new WatcherHandleImpl(handle_name, name_, std::weak_ptr<TargetAwareReadyFn>(fn_)));
      39         863 : }
      40             : 
      41             : } // namespace Init
      42             : } // namespace Envoy

Generated by: LCOV version 1.15