Line data Source code
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/strings/string_view.h" 12 : 13 : namespace Envoy { 14 : namespace Filesystem { 15 : 16 : /** 17 : * Abstraction for a file watcher. 18 : */ 19 : class Watcher { 20 : public: 21 : using OnChangedCb = std::function<void(uint32_t events)>; 22 : 23 : struct Events { 24 : static constexpr uint32_t MovedTo = 0x1; 25 : static constexpr uint32_t Modified = 0x2; 26 : }; 27 : 28 70 : virtual ~Watcher() = default; 29 : 30 : /** 31 : * Add a file watch. 32 : * @param path supplies the path to watch. 33 : * If path is a file, callback is called on events for the given file. 34 : * If path is a directory (ends with "/"), callback is called on events 35 : * for the given directory. 36 : * @param events supplies the events to watch. 37 : * @param cb supplies the callback to invoke when a change occurs. 38 : */ 39 : virtual void addWatch(absl::string_view path, uint32_t events, OnChangedCb cb) PURE; 40 : }; 41 : 42 : using WatcherPtr = std::unique_ptr<Watcher>; 43 : 44 : } // namespace Filesystem 45 : } // namespace Envoy