1
#pragma once
2

            
3
#include <cstdint>
4
#include <functional>
5
#include <memory>
6
#include <string>
7

            
8
#include "envoy/common/platform.h"
9
#include "envoy/common/pure.h"
10

            
11
#include "absl/status/status.h"
12
#include "absl/status/statusor.h"
13
#include "absl/strings/string_view.h"
14

            
15
namespace Envoy {
16
namespace Filesystem {
17

            
18
/**
19
 * Abstraction for a file watcher.
20
 */
21
class Watcher {
22
public:
23
  using OnChangedCb = std::function<absl::Status(uint32_t events)>;
24

            
25
  struct Events {
26
    static constexpr uint32_t MovedTo = 0x1;
27
    static constexpr uint32_t Modified = 0x2;
28
  };
29

            
30
10849
  virtual ~Watcher() = default;
31

            
32
  /**
33
   * Add a file watch.
34
   * @param path supplies the path to watch.
35
   *        If path is a file, callback is called on events for the given file.
36
   *        If path is a directory (ends with "/"), callback is called on events
37
   *        for the given directory.
38
   * @param events supplies the events to watch.
39
   * @param cb supplies the callback to invoke when a change occurs.
40
   * @return a failure status if the file does not exist
41
   */
42
  virtual absl::Status addWatch(absl::string_view path, uint32_t events, OnChangedCb cb) PURE;
43
};
44

            
45
using WatcherPtr = std::unique_ptr<Watcher>;
46

            
47
} // namespace Filesystem
48
} // namespace Envoy