NexusForce 1.0.0
A Modern C++ Library with extended functionality, web components, and utility libraries
载入中...
搜索中...
未找到
file_watcher.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_FILE_FILE_WATCHER_HPP__
2#define NEFORCE_CORE_FILE_FILE_WATCHER_HPP__
3
10
18NEFORCE_BEGIN_NAMESPACE__
19
25
33class NEFORCE_API file_watcher {
34private:
35 using callback_t = function<void(const path&, file_watch_event)>;
36
37 path watch_path_;
38 bool recursive_;
39 atomic<bool> watching_{false};
40 atomic<bool> stopping_{false};
41 callback_t callback_;
43 vector<char> buffer_;
44 mutex callback_mutex_;
45
46#ifdef NEFORCE_PLATFORM_WINDOWS
47 ::HANDLE dir_handle_ = INVALID_HANDLE_VALUE;
48 ::HANDLE completion_port_ = INVALID_HANDLE_VALUE;
49 ::OVERLAPPED overlapped_{};
50#else
51 int inotify_fd_ = -1;
52 int watch_descriptor_ = -1;
53 int event_fd_ = -1;
54#endif
55
56 thread watch_thread_;
57
63 void watch_thread_func();
64
65public:
72 explicit file_watcher(path watch_path, bool recursive = false);
73
80
81 file_watcher(const file_watcher&) = delete;
82 file_watcher& operator=(const file_watcher&) = delete;
83
93 bool start(callback_t callback, file_watch_event events = file_watch_event::ALL);
94
100 void stop();
101
106 NEFORCE_NODISCARD const path& watch_path() const noexcept { return watch_path_; }
107
112 NEFORCE_NODISCARD file_watch_event current_events() const noexcept { return current_events_; }
113
118 NEFORCE_NODISCARD bool is_watching() const noexcept { return watching_.load(); }
119
124 NEFORCE_NODISCARD bool is_recursive() const noexcept { return recursive_; }
125
134
142 bool update_recursive(bool recursive);
143};
144 // File
146
147NEFORCE_END_NAMESPACE__
148#endif // NEFORCE_CORE_FILE_FILE_WATCHER_HPP__
原子类型完整实现
~file_watcher()
析构函数
NEFORCE_NODISCARD file_watch_event current_events() const noexcept
获取当前监视的事件类型
NEFORCE_NODISCARD const path & watch_path() const noexcept
获取监视的目录路径
bool update_recursive(bool recursive)
更新递归设置
NEFORCE_NODISCARD bool is_watching() const noexcept
检查是否正在监视
void stop()
停止监视
bool start(callback_t callback, file_watch_event events=file_watch_event::ALL)
开始监视
bool update_watch(file_watch_event events)
更新监视的事件类型
file_watcher(path watch_path, bool recursive=false)
构造函数
NEFORCE_NODISCARD bool is_recursive() const noexcept
检查是否递归监视子目录
函数包装器主模板声明
非递归互斥锁
文件路径类
线程类
动态大小数组容器
文件操作常量定义
通用函数包装器
file_watch_event
文件监视事件枚举
@ OVERLAPPED
Linux不支持异步I/O标志
互斥锁
文件路径类
通用原子类型模板
线程管理类
动态大小数组容器