AsyncFw 1.2
Async Framework is c++ runtime with timers, poll notifiers, sockets, coroutines, etc.
 
Loading...
Searching...
No Matches
FileSystemWatcher.h
1/*
2Copyright (c) 2026 Alexandr Kuzmuk
3
4This file is part of the AsyncFw project. Licensed under the MIT License.
5See {Link: LICENSE file https://mit-license.org} in the project root for full license information.
6*/
7
8#pragma once
9
10#include <string>
11#include "../core/FunctionConnector.h"
12#include "../main/Instance.h"
13
14namespace AsyncFw {
17class FileSystemWatcher {
18 friend LogStream &operator<<(LogStream &, const FileSystemWatcher &);
19
20public:
21 static FileSystemWatcher *instance() { return instance_.value; }
22 FileSystemWatcher(const std::vector<std::string> & = {});
23 ~FileSystemWatcher();
24 bool addPath(const std::string &path);
25 bool addPaths(const std::vector<std::string> &paths);
26 bool removePath(const std::string &path);
27 bool removePaths(const std::vector<std::string> &paths);
28 std::vector<std::string> paths() const;
29
31 FunctionConnectorProtected<FileSystemWatcher>::Connector<const std::string &, int> notify;
32
33private:
34 inline static AsyncFw::Instance<FileSystemWatcher> instance_ {"FileSystemWatcher"};
35 struct WatchPath {
36 WatchPath() = default;
37 WatchPath(const std::string &);
38 std::string directory;
39 std::string name;
40 };
41 struct Watch : public WatchPath {
42 using WatchPath::WatchPath;
43 int d;
44 };
45 std::vector<Watch *> files_;
46 std::vector<Watch *> wds_;
47 int notifyfd_;
48 AbstractThread *thread_;
49
50 int timerid_;
51 std::vector<const Watch *> we_;
52 void append_(const Watch *);
53 void remove_(const Watch *);
54 struct CompareWatch {
55 bool operator()(const Watch *, const Watch *) const;
56 bool operator()(const WatchPath &, const Watch *) const;
57 bool operator()(const Watch *, const WatchPath &) const;
58 };
59 struct CompareWatchDescriptor {
60 bool operator()(const Watch *, const Watch *) const;
61 bool operator()(const Watch *, int) const;
62 };
63};
64} // namespace AsyncFw
FunctionConnectorProtected< FileSystemWatcher >::Connector< const std::string &, int > notify
The FunctionConnector for notification of file-related events.
Definition FileSystemWatcher.h:31
The Instance class.
Definition Instance.h:40
The LogStream class.
Definition LogStream.h:44