Coverage Report

Created: 2024-09-19 09:45

/proc/self/cwd/envoy/init/watcher.h
Line
Count
Source
1
#pragma once
2
3
#include <memory>
4
5
#include "envoy/common/pure.h"
6
7
#include "absl/strings/string_view.h"
8
9
namespace Envoy {
10
namespace Init {
11
12
/**
13
 * A WatcherHandle functions as a weak reference to a Watcher. It is how an implementation of
14
 * Init::Target would safely notify a Manager that it has initialized, and likewise it's how
15
 * an implementation of Init::Manager would safely tell its client that all registered targets
16
 * have initialized, with no guarantees about the lifetimes of the manager or client. Typical usage
17
 * (outside of Init::TargetImpl and ManagerImpl) does not require touching WatcherHandles at
18
 * all.
19
 */
20
struct WatcherHandle {
21
15.0k
  virtual ~WatcherHandle() = default;
22
23
  /**
24
   * Tell the watcher that initialization has completed, if it is still available.
25
   * @return true if the watcher received this call, false if the watcher was already destroyed.
26
   */
27
  virtual bool ready() const PURE;
28
};
29
using WatcherHandlePtr = std::unique_ptr<WatcherHandle>;
30
31
/**
32
 * A Watcher is an entity that listens for notifications that either an initialization target or
33
 * all targets registered with a manager have initialized. It can only be invoked through a
34
 * WatcherHandle.
35
 */
36
struct Watcher {
37
142k
  virtual ~Watcher() = default;
38
39
  /**
40
   * @return a human-readable target name, for logging / debugging.
41
   */
42
  virtual absl::string_view name() const PURE;
43
44
  /**
45
   * Create a new handle that can notify this watcher.
46
   * @param name a human readable handle name, for logging / debugging.
47
   * @return a new handle that can notify this watcher.
48
   */
49
  virtual WatcherHandlePtr createHandle(absl::string_view name) const PURE;
50
};
51
52
} // namespace Init
53
} // namespace Envoy