NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
file_watcher.hpp
浏览该文件的文档.
1#ifndef NEFORCE_CORE_FILE_FILE_WATCHER_HPP__
2#define NEFORCE_CORE_FILE_FILE_WATCHER_HPP__
3
10
15#include "NeForce/core/exception/system_exception.hpp"
19NEFORCE_BEGIN_NAMESPACE__
20
26
34class NEFORCE_API file_watcher {
35private:
36 using callback_t = function<void(const path&, file_watch_event)>;
37
38 path watch_path_;
39 bool recursive_;
40 atomic<bool> watching_{false};
41 atomic<bool> stopping_{false};
42 callback_t callback_;
44 vector<char> buffer_;
45 mutex callback_mutex_;
46
47#ifdef NEFORCE_PLATFORM_WINDOWS
48 native_handle_type dir_handle_ = INVALID_HANDLE_VALUE;
49 native_handle_type completion_port_ = INVALID_HANDLE_VALUE;
50 ::OVERLAPPED overlapped_{};
51#else
52 native_handle_type inotify_fd_ = -1;
53 native_handle_type watch_descriptor_ = -1;
54 native_handle_type event_fd_ = -1;
55#endif
56
57 thread watch_thread_;
58
64 void watch_thread_func();
65
66public:
73 explicit file_watcher(path watch_path, bool recursive = false);
74
81
82 file_watcher(const file_watcher&) = delete;
83 file_watcher& operator=(const file_watcher&) = delete;
84
94 bool start(callback_t callback, file_watch_event events = file_watch_event::ALL);
95
101 void stop();
102
107 NEFORCE_NODISCARD const path& watch_path() const noexcept { return watch_path_; }
108
113 NEFORCE_NODISCARD file_watch_event current_events() const noexcept { return current_events_; }
114
119 NEFORCE_NODISCARD bool is_watching() const noexcept { return watching_.load(); }
120
125 NEFORCE_NODISCARD bool is_recursive() const noexcept { return recursive_; }
126
135
143 bool update_recursive(bool recursive);
144};
145 // File
147
148NEFORCE_END_NAMESPACE__
149#endif // NEFORCE_CORE_FILE_FILE_WATCHER_HPP__
原子类型完整实现
bool is_watching() const noexcept
检查是否正在监视
bool start(callback_t callback, file_watch_event events=file_watch_event::ALL)
开始监视
const path & watch_path() const noexcept
获取监视的目录路径
bool is_recursive() const noexcept
检查是否递归监视子目录
bool update_recursive(bool recursive)
更新递归设置
file_watcher(path watch_path, bool recursive=false)
构造函数
void stop()
停止监视
bool update_watch(file_watch_event events)
更新监视的事件类型
~file_watcher()
析构函数
file_watch_event current_events() const noexcept
获取当前监视的事件类型
函数包装器主模板声明
非递归互斥锁
文件路径类
动态大小数组容器
文件操作常量定义
通用函数包装器
void * native_handle_type
系统句柄类型
file_watch_event
文件监视事件枚举
互斥锁
文件路径类
通用原子类型模板
线程管理类
动态大小数组容器