diff options
Diffstat (limited to 'src/3rdParty/efsw/efsw.hpp')
-rwxr-xr-x | src/3rdParty/efsw/efsw.hpp | 195 |
1 files changed, 195 insertions, 0 deletions
diff --git a/src/3rdParty/efsw/efsw.hpp b/src/3rdParty/efsw/efsw.hpp new file mode 100755 index 0000000..12af116 --- /dev/null +++ b/src/3rdParty/efsw/efsw.hpp | |||
@@ -0,0 +1,195 @@ | |||
1 | /** | ||
2 | @author Martín Lucas Golini | ||
3 | |||
4 | Copyright (c) 2013 Martín Lucas Golini | ||
5 | |||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | ||
7 | of this software and associated documentation files (the "Software"), to deal | ||
8 | in the Software without restriction, including without limitation the rights | ||
9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
10 | copies of the Software, and to permit persons to whom the Software is | ||
11 | furnished to do so, subject to the following conditions: | ||
12 | |||
13 | The above copyright notice and this permission notice shall be included in | ||
14 | all copies or substantial portions of the Software. | ||
15 | |||
16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
22 | THE SOFTWARE. | ||
23 | |||
24 | This software is a fork of the "simplefilewatcher" by James Wynn (james@jameswynn.com) | ||
25 | http://code.google.com/p/simplefilewatcher/ also MIT licensed. | ||
26 | */ | ||
27 | |||
28 | #ifndef ESFW_HPP | ||
29 | #define ESFW_HPP | ||
30 | |||
31 | #include <list> | ||
32 | #include <string> | ||
33 | |||
34 | #if defined( _WIN32 ) | ||
35 | #ifdef EFSW_DYNAMIC | ||
36 | // Windows platforms | ||
37 | #ifdef EFSW_EXPORTS | ||
38 | // From DLL side, we must export | ||
39 | #define EFSW_API __declspec( dllexport ) | ||
40 | #else | ||
41 | // From client application side, we must import | ||
42 | #define EFSW_API __declspec( dllimport ) | ||
43 | #endif | ||
44 | #else | ||
45 | // No specific directive needed for static build | ||
46 | #ifndef EFSW_API | ||
47 | #define EFSW_API | ||
48 | #endif | ||
49 | #endif | ||
50 | #else | ||
51 | #if ( __GNUC__ >= 4 ) && defined( EFSW_EXPORTS ) | ||
52 | #ifndef EFSW_API | ||
53 | #define EFSW_API __attribute__( ( visibility( "default" ) ) ) | ||
54 | #endif | ||
55 | #endif | ||
56 | |||
57 | // Other platforms don't need to define anything | ||
58 | #ifndef EFSW_API | ||
59 | #define EFSW_API | ||
60 | #endif | ||
61 | #endif | ||
62 | |||
63 | namespace efsw { | ||
64 | |||
65 | /// Type for a watch id | ||
66 | typedef long WatchID; | ||
67 | |||
68 | // forward declarations | ||
69 | class FileWatcherImpl; | ||
70 | class FileWatchListener; | ||
71 | |||
72 | /// Actions to listen for. Rename will send two events, one for | ||
73 | /// the deletion of the old file, and one for the creation of the | ||
74 | /// new file. | ||
75 | namespace Actions { | ||
76 | enum Action { | ||
77 | /// Sent when a file is created or renamed | ||
78 | Add = 1, | ||
79 | /// Sent when a file is deleted or renamed | ||
80 | Delete = 2, | ||
81 | /// Sent when a file is modified | ||
82 | Modified = 3, | ||
83 | /// Sent when a file is moved | ||
84 | Moved = 4 | ||
85 | }; | ||
86 | } | ||
87 | typedef Actions::Action Action; | ||
88 | |||
89 | /// Errors log namespace | ||
90 | namespace Errors { | ||
91 | |||
92 | enum Error { | ||
93 | FileNotFound = -1, | ||
94 | FileRepeated = -2, | ||
95 | FileOutOfScope = -3, | ||
96 | FileNotReadable = -4, | ||
97 | FileRemote = -5, /** Directory in remote file system ( create a generic FileWatcher instance to | ||
98 | watch this directory ). */ | ||
99 | Unspecified = -6 | ||
100 | }; | ||
101 | |||
102 | class EFSW_API Log { | ||
103 | public: | ||
104 | /// @return The last error logged | ||
105 | static std::string getLastErrorLog(); | ||
106 | |||
107 | /// Creates an error of the type specified | ||
108 | static Error createLastError( Error err, std::string log ); | ||
109 | }; | ||
110 | |||
111 | } // namespace Errors | ||
112 | typedef Errors::Error Error; | ||
113 | |||
114 | /// Listens to files and directories and dispatches events | ||
115 | /// to notify the listener of files and directories changes. | ||
116 | /// @class FileWatcher | ||
117 | class EFSW_API FileWatcher { | ||
118 | public: | ||
119 | /// Default constructor, will use the default platform file watcher | ||
120 | FileWatcher(); | ||
121 | |||
122 | /// Constructor that lets you force the use of the Generic File Watcher | ||
123 | explicit FileWatcher( bool useGenericFileWatcher ); | ||
124 | |||
125 | virtual ~FileWatcher(); | ||
126 | |||
127 | /// Add a directory watch. Same as the other addWatch, but doesn't have recursive option. | ||
128 | /// For backwards compatibility. | ||
129 | /// On error returns WatchID with Error type. | ||
130 | WatchID addWatch( const std::string& directory, FileWatchListener* watcher ); | ||
131 | |||
132 | /// Add a directory watch | ||
133 | /// On error returns WatchID with Error type. | ||
134 | WatchID addWatch( const std::string& directory, FileWatchListener* watcher, bool recursive ); | ||
135 | |||
136 | /// Remove a directory watch. This is a brute force search O(nlogn). | ||
137 | void removeWatch( const std::string& directory ); | ||
138 | |||
139 | /// Remove a directory watch. This is a map lookup O(logn). | ||
140 | void removeWatch( WatchID watchid ); | ||
141 | |||
142 | /// Starts watching ( in other thread ) | ||
143 | void watch(); | ||
144 | |||
145 | /// @return Returns a list of the directories that are being watched | ||
146 | std::list<std::string> directories(); | ||
147 | |||
148 | /** Allow recursive watchers to follow symbolic links to other directories | ||
149 | * followSymlinks is disabled by default | ||
150 | */ | ||
151 | void followSymlinks( bool follow ); | ||
152 | |||
153 | /** @return If can follow symbolic links to directorioes */ | ||
154 | const bool& followSymlinks() const; | ||
155 | |||
156 | /** When enable this it will allow symlinks to watch recursively out of the pointed directory. | ||
157 | * follorSymlinks must be enabled to this work. | ||
158 | * For example, added symlink to /home/folder, and the symlink points to /, this by default is | ||
159 | * not allowed, it's only allowed to symlink anything from /home/ and deeper. This is to avoid | ||
160 | * great levels of recursion. Enabling this could lead in infinite recursion, and crash the | ||
161 | * watcher ( it will try not to avoid this ). Buy enabling out of scope links, it will allow | ||
162 | * this behavior. allowOutOfScopeLinks are disabled by default. | ||
163 | */ | ||
164 | void allowOutOfScopeLinks( bool allow ); | ||
165 | |||
166 | /// @return Returns if out of scope links are allowed | ||
167 | const bool& allowOutOfScopeLinks() const; | ||
168 | |||
169 | private: | ||
170 | /// The implementation | ||
171 | FileWatcherImpl* mImpl; | ||
172 | bool mFollowSymlinks; | ||
173 | bool mOutOfScopeLinks; | ||
174 | }; | ||
175 | |||
176 | /// Basic interface for listening for file events. | ||
177 | /// @class FileWatchListener | ||
178 | class FileWatchListener { | ||
179 | public: | ||
180 | virtual ~FileWatchListener() {} | ||
181 | |||
182 | /// Handles the action file action | ||
183 | /// @param watchid The watch id for the directory | ||
184 | /// @param dir The directory | ||
185 | /// @param filename The filename that was accessed (not full path) | ||
186 | /// @param action Action that was performed | ||
187 | /// @param oldFilename The name of the file or directory moved | ||
188 | virtual void handleFileAction( WatchID watchid, const std::string& dir, | ||
189 | const std::string& filename, Action action, | ||
190 | std::string oldFilename = "" ) = 0; | ||
191 | }; | ||
192 | |||
193 | } // namespace efsw | ||
194 | |||
195 | #endif | ||