aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/efsw/FileWatcherFSEvents.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdParty/efsw/FileWatcherFSEvents.hpp')
-rw-r--r--[-rwxr-xr-x]src/3rdParty/efsw/FileWatcherFSEvents.hpp49
1 files changed, 13 insertions, 36 deletions
diff --git a/src/3rdParty/efsw/FileWatcherFSEvents.hpp b/src/3rdParty/efsw/FileWatcherFSEvents.hpp
index 5279847..daa538c 100755..100644
--- a/src/3rdParty/efsw/FileWatcherFSEvents.hpp
+++ b/src/3rdParty/efsw/FileWatcherFSEvents.hpp
@@ -7,33 +7,15 @@
7 7
8#include <CoreFoundation/CoreFoundation.h> 8#include <CoreFoundation/CoreFoundation.h>
9#include <CoreServices/CoreServices.h> 9#include <CoreServices/CoreServices.h>
10#include <dispatch/dispatch.h>
10#include <efsw/WatcherFSEvents.hpp> 11#include <efsw/WatcherFSEvents.hpp>
11#include <list>
12#include <map> 12#include <map>
13#include <vector> 13#include <vector>
14#include <condition_variable>
15#include <mutex>
14 16
15namespace efsw { 17namespace efsw {
16 18
17/* OSX < 10.7 has no file events */
18/* So i declare the events constants */
19enum FSEventEvents {
20 efswFSEventStreamCreateFlagFileEvents = 0x00000010,
21 efswFSEventStreamEventFlagItemCreated = 0x00000100,
22 efswFSEventStreamEventFlagItemRemoved = 0x00000200,
23 efswFSEventStreamEventFlagItemInodeMetaMod = 0x00000400,
24 efswFSEventStreamEventFlagItemRenamed = 0x00000800,
25 efswFSEventStreamEventFlagItemModified = 0x00001000,
26 efswFSEventStreamEventFlagItemFinderInfoMod = 0x00002000,
27 efswFSEventStreamEventFlagItemChangeOwner = 0x00004000,
28 efswFSEventStreamEventFlagItemXattrMod = 0x00008000,
29 efswFSEventStreamEventFlagItemIsFile = 0x00010000,
30 efswFSEventStreamEventFlagItemIsDir = 0x00020000,
31 efswFSEventStreamEventFlagItemIsSymlink = 0x00040000,
32 efswFSEventsModified = efswFSEventStreamEventFlagItemFinderInfoMod |
33 efswFSEventStreamEventFlagItemModified |
34 efswFSEventStreamEventFlagItemInodeMetaMod
35};
36
37/// Implementation for Win32 based on ReadDirectoryChangesW. 19/// Implementation for Win32 based on ReadDirectoryChangesW.
38/// @class FileWatcherFSEvents 20/// @class FileWatcherFSEvents
39class FileWatcherFSEvents : public FileWatcherImpl { 21class FileWatcherFSEvents : public FileWatcherImpl {
@@ -52,48 +34,43 @@ class FileWatcherFSEvents : public FileWatcherImpl {
52 34
53 /// Add a directory watch 35 /// Add a directory watch
54 /// On error returns WatchID with Error type. 36 /// On error returns WatchID with Error type.
55 WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive ); 37 WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive,
38 const std::vector<WatcherOption> &options ) override;
56 39
57 /// Remove a directory watch. This is a brute force lazy search O(nlogn). 40 /// Remove a directory watch. This is a brute force lazy search O(nlogn).
58 void removeWatch( const std::string& directory ); 41 void removeWatch( const std::string& directory ) override;
59 42
60 /// Remove a directory watch. This is a map lookup O(logn). 43 /// Remove a directory watch. This is a map lookup O(logn).
61 void removeWatch( WatchID watchid ); 44 void removeWatch( WatchID watchid ) override;
62 45
63 /// Updates the watcher. Must be called often. 46 /// Updates the watcher. Must be called often.
64 void watch(); 47 void watch() override;
65 48
66 /// Handles the action 49 /// Handles the action
67 void handleAction( Watcher* watch, const std::string& filename, unsigned long action, 50 void handleAction( Watcher* watch, const std::string& filename, unsigned long action,
68 std::string oldFilename = "" ); 51 std::string oldFilename = "" ) override;
69 52
70 /// @return Returns a list of the directories that are being watched 53 /// @return Returns a list of the directories that are being watched
71 std::list<std::string> directories(); 54 std::vector<std::string> directories() override;
72 55
73 protected: 56 protected:
74 static void FSEventCallback( ConstFSEventStreamRef streamRef, void* userData, size_t numEvents, 57 static void FSEventCallback( ConstFSEventStreamRef streamRef, void* userData, size_t numEvents,
75 void* eventPaths, const FSEventStreamEventFlags eventFlags[], 58 void* eventPaths, const FSEventStreamEventFlags eventFlags[],
76 const FSEventStreamEventId eventIds[] ); 59 const FSEventStreamEventId eventIds[] );
77 60
78 Atomic<CFRunLoopRef> mRunLoopRef;
79
80 /// Vector of WatcherWin32 pointers 61 /// Vector of WatcherWin32 pointers
81 WatchMap mWatches; 62 WatchMap mWatches;
82 63
83 /// The last watchid 64 /// The last watchid
84 WatchID mLastWatchID; 65 WatchID mLastWatchID;
85 66
86 Thread* mThread;
87
88 Mutex mWatchesLock; 67 Mutex mWatchesLock;
89 68
90 bool pathInWatches( const std::string& path ); 69 bool pathInWatches( const std::string& path ) override;
91 70
92 std::vector<WatcherFSEvents*> mNeedInit; 71 std::mutex mWatchesMutex;
93 Mutex mNeedInitMutex; 72 std::condition_variable mWatchCond;
94 73
95 private:
96 void run();
97}; 74};
98 75
99} // namespace efsw 76} // namespace efsw