diff options
| author | Li Jin <dragon-fly@qq.com> | 2022-11-15 17:23:46 +0800 |
|---|---|---|
| committer | Li Jin <dragon-fly@qq.com> | 2022-11-15 17:52:09 +0800 |
| commit | 94f8330613877b3582d32bd11abd83a97b4399ad (patch) | |
| tree | 5359de314be1ebde17f8d1e48632a97d18f9e50f /src/3rdParty/efsw/WatcherKqueue.hpp | |
| parent | 60f8f00a022ac08701792b2897b72d8c99b50f52 (diff) | |
| download | yuescript-94f8330613877b3582d32bd11abd83a97b4399ad.tar.gz yuescript-94f8330613877b3582d32bd11abd83a97b4399ad.tar.bz2 yuescript-94f8330613877b3582d32bd11abd83a97b4399ad.zip | |
adding -w option to Yuescript tool.
Diffstat (limited to 'src/3rdParty/efsw/WatcherKqueue.hpp')
| -rwxr-xr-x | src/3rdParty/efsw/WatcherKqueue.hpp | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/3rdParty/efsw/WatcherKqueue.hpp b/src/3rdParty/efsw/WatcherKqueue.hpp new file mode 100755 index 0000000..87d898c --- /dev/null +++ b/src/3rdParty/efsw/WatcherKqueue.hpp | |||
| @@ -0,0 +1,97 @@ | |||
| 1 | #ifndef EFSW_WATCHEROSX_HPP | ||
| 2 | #define EFSW_WATCHEROSX_HPP | ||
| 3 | |||
| 4 | #include <efsw/FileWatcherImpl.hpp> | ||
| 5 | |||
| 6 | #if EFSW_PLATFORM == EFSW_PLATFORM_KQUEUE || EFSW_PLATFORM == EFSW_PLATFORM_FSEVENTS | ||
| 7 | |||
| 8 | #include <efsw/DirectorySnapshot.hpp> | ||
| 9 | #include <map> | ||
| 10 | #include <sys/event.h> | ||
| 11 | #include <sys/types.h> | ||
| 12 | #include <vector> | ||
| 13 | |||
| 14 | namespace efsw { | ||
| 15 | |||
| 16 | class FileWatcherKqueue; | ||
| 17 | class WatcherKqueue; | ||
| 18 | |||
| 19 | typedef struct kevent KEvent; | ||
| 20 | |||
| 21 | /// type for a map from WatchID to WatcherKqueue pointer | ||
| 22 | typedef std::map<WatchID, Watcher*> WatchMap; | ||
| 23 | |||
| 24 | class WatcherKqueue : public Watcher { | ||
| 25 | public: | ||
| 26 | WatcherKqueue( WatchID watchid, const std::string& dirname, FileWatchListener* listener, | ||
| 27 | bool recursive, FileWatcherKqueue* watcher, WatcherKqueue* parent = NULL ); | ||
| 28 | |||
| 29 | virtual ~WatcherKqueue(); | ||
| 30 | |||
| 31 | void addFile( const std::string& name, bool emitEvents = true ); | ||
| 32 | |||
| 33 | void removeFile( const std::string& name, bool emitEvents = true ); | ||
| 34 | |||
| 35 | // called when the directory is actually changed | ||
| 36 | // means a file has been added or removed | ||
| 37 | // rescans the watched directory adding/removing files and sending notices | ||
| 38 | void rescan(); | ||
| 39 | |||
| 40 | void handleAction( const std::string& filename, efsw::Action action, | ||
| 41 | const std::string& oldFilename = "" ); | ||
| 42 | |||
| 43 | void handleFolderAction( std::string filename, efsw::Action action, | ||
| 44 | const std::string& oldFilename = "" ); | ||
| 45 | |||
| 46 | void addAll(); | ||
| 47 | |||
| 48 | void removeAll(); | ||
| 49 | |||
| 50 | WatchID watchingDirectory( std::string dir ); | ||
| 51 | |||
| 52 | void watch(); | ||
| 53 | |||
| 54 | WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive, | ||
| 55 | WatcherKqueue* parent ); | ||
| 56 | |||
| 57 | void removeWatch( WatchID watchid ); | ||
| 58 | |||
| 59 | bool initOK(); | ||
| 60 | |||
| 61 | int lastErrno(); | ||
| 62 | |||
| 63 | protected: | ||
| 64 | WatchMap mWatches; | ||
| 65 | int mLastWatchID; | ||
| 66 | |||
| 67 | // index 0 is always the directory | ||
| 68 | std::vector<KEvent> mChangeList; | ||
| 69 | size_t mChangeListCount; | ||
| 70 | DirectorySnapshot mDirSnap; | ||
| 71 | |||
| 72 | /// The descriptor for the kqueue | ||
| 73 | int mKqueue; | ||
| 74 | |||
| 75 | FileWatcherKqueue* mWatcher; | ||
| 76 | |||
| 77 | WatcherKqueue* mParent; | ||
| 78 | |||
| 79 | bool mInitOK; | ||
| 80 | int mErrno; | ||
| 81 | |||
| 82 | bool pathInWatches( const std::string& path ); | ||
| 83 | |||
| 84 | bool pathInParent( const std::string& path ); | ||
| 85 | |||
| 86 | Watcher* findWatcher( const std::string path ); | ||
| 87 | |||
| 88 | void moveDirectory( std::string oldPath, std::string newPath, bool emitEvents = true ); | ||
| 89 | |||
| 90 | void sendDirChanged(); | ||
| 91 | }; | ||
| 92 | |||
| 93 | } // namespace efsw | ||
| 94 | |||
| 95 | #endif | ||
| 96 | |||
| 97 | #endif | ||
