aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/efsw/FileWatcherFSEvents.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/3rdParty/efsw/FileWatcherFSEvents.hpp')
-rwxr-xr-xsrc/3rdParty/efsw/FileWatcherFSEvents.hpp103
1 files changed, 103 insertions, 0 deletions
diff --git a/src/3rdParty/efsw/FileWatcherFSEvents.hpp b/src/3rdParty/efsw/FileWatcherFSEvents.hpp
new file mode 100755
index 0000000..5279847
--- /dev/null
+++ b/src/3rdParty/efsw/FileWatcherFSEvents.hpp
@@ -0,0 +1,103 @@
1#ifndef EFSW_FILEWATCHERFSEVENTS_HPP
2#define EFSW_FILEWATCHERFSEVENTS_HPP
3
4#include <efsw/FileWatcherImpl.hpp>
5
6#if EFSW_PLATFORM == EFSW_PLATFORM_FSEVENTS
7
8#include <CoreFoundation/CoreFoundation.h>
9#include <CoreServices/CoreServices.h>
10#include <efsw/WatcherFSEvents.hpp>
11#include <list>
12#include <map>
13#include <vector>
14
15namespace efsw {
16
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.
38/// @class FileWatcherFSEvents
39class FileWatcherFSEvents : public FileWatcherImpl {
40 friend class WatcherFSEvents;
41
42 public:
43 /// @return If FSEvents supports file-level notifications ( true if OS X >= 10.7 )
44 static bool isGranular();
45
46 /// type for a map from WatchID to WatcherWin32 pointer
47 typedef std::map<WatchID, WatcherFSEvents*> WatchMap;
48
49 FileWatcherFSEvents( FileWatcher* parent );
50
51 virtual ~FileWatcherFSEvents();
52
53 /// Add a directory watch
54 /// On error returns WatchID with Error type.
55 WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive );
56
57 /// Remove a directory watch. This is a brute force lazy search O(nlogn).
58 void removeWatch( const std::string& directory );
59
60 /// Remove a directory watch. This is a map lookup O(logn).
61 void removeWatch( WatchID watchid );
62
63 /// Updates the watcher. Must be called often.
64 void watch();
65
66 /// Handles the action
67 void handleAction( Watcher* watch, const std::string& filename, unsigned long action,
68 std::string oldFilename = "" );
69
70 /// @return Returns a list of the directories that are being watched
71 std::list<std::string> directories();
72
73 protected:
74 static void FSEventCallback( ConstFSEventStreamRef streamRef, void* userData, size_t numEvents,
75 void* eventPaths, const FSEventStreamEventFlags eventFlags[],
76 const FSEventStreamEventId eventIds[] );
77
78 Atomic<CFRunLoopRef> mRunLoopRef;
79
80 /// Vector of WatcherWin32 pointers
81 WatchMap mWatches;
82
83 /// The last watchid
84 WatchID mLastWatchID;
85
86 Thread* mThread;
87
88 Mutex mWatchesLock;
89
90 bool pathInWatches( const std::string& path );
91
92 std::vector<WatcherFSEvents*> mNeedInit;
93 Mutex mNeedInitMutex;
94
95 private:
96 void run();
97};
98
99} // namespace efsw
100
101#endif
102
103#endif