diff options
Diffstat (limited to 'src/3rdParty/efsw/efsw.h')
-rw-r--r--[-rwxr-xr-x] | src/3rdParty/efsw/efsw.h | 175 |
1 files changed, 109 insertions, 66 deletions
diff --git a/src/3rdParty/efsw/efsw.h b/src/3rdParty/efsw/efsw.h index 28e63e2..30cf595 100755..100644 --- a/src/3rdParty/efsw/efsw.h +++ b/src/3rdParty/efsw/efsw.h | |||
@@ -1,7 +1,7 @@ | |||
1 | /** | 1 | /** |
2 | @author Sepul Sepehr Taghdisian | 2 | @author Sepul Sepehr Taghdisian |
3 | 3 | ||
4 | Copyright (c) 2013 Martin Lucas Golini | 4 | Copyright (c) 2024 Martín Lucas Golini |
5 | 5 | ||
6 | Permission is hereby granted, free of charge, to any person obtaining a copy | 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 | 7 | of this software and associated documentation files (the "Software"), to deal |
@@ -32,31 +32,31 @@ | |||
32 | extern "C" { | 32 | extern "C" { |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | #if defined(_WIN32) | 35 | #if defined( _WIN32 ) |
36 | #ifdef EFSW_DYNAMIC | 36 | #ifdef EFSW_DYNAMIC |
37 | // Windows platforms | 37 | // Windows platforms |
38 | #ifdef EFSW_EXPORTS | 38 | #ifdef EFSW_EXPORTS |
39 | // From DLL side, we must export | 39 | // From DLL side, we must export |
40 | #define EFSW_API __declspec(dllexport) | 40 | #define EFSW_API __declspec( dllexport ) |
41 | #else | ||
42 | // From client application side, we must import | ||
43 | #define EFSW_API __declspec(dllimport) | ||
44 | #endif | ||
45 | #else | ||
46 | // No specific directive needed for static build | ||
47 | #ifndef EFSW_API | ||
48 | #define EFSW_API | ||
49 | #endif | ||
50 | #endif | ||
51 | #else | 41 | #else |
52 | #if ( __GNUC__ >= 4 ) && defined( EFSW_EXPORTS ) | 42 | // From client application side, we must import |
53 | #define EFSW_API __attribute__ ((visibility("default"))) | 43 | #define EFSW_API __declspec( dllimport ) |
54 | #endif | 44 | #endif |
55 | 45 | #else | |
56 | // Other platforms don't need to define anything | 46 | // No specific directive needed for static build |
57 | #ifndef EFSW_API | 47 | #ifndef EFSW_API |
58 | #define EFSW_API | 48 | #define EFSW_API |
59 | #endif | 49 | #endif |
50 | #endif | ||
51 | #else | ||
52 | #if ( __GNUC__ >= 4 ) && defined( EFSW_EXPORTS ) | ||
53 | #define EFSW_API __attribute__( ( visibility( "default" ) ) ) | ||
54 | #endif | ||
55 | |||
56 | // Other platforms don't need to define anything | ||
57 | #ifndef EFSW_API | ||
58 | #define EFSW_API | ||
59 | #endif | ||
60 | #endif | 60 | #endif |
61 | 61 | ||
62 | /// Type for a watch id | 62 | /// Type for a watch id |
@@ -65,84 +65,127 @@ typedef long efsw_watchid; | |||
65 | /// Type for watcher | 65 | /// Type for watcher |
66 | typedef void* efsw_watcher; | 66 | typedef void* efsw_watcher; |
67 | 67 | ||
68 | enum efsw_action | 68 | enum efsw_action { |
69 | { | 69 | EFSW_ADD = 1, /// Sent when a file is created or renamed |
70 | EFSW_ADD = 1, /// Sent when a file is created or renamed | 70 | EFSW_DELETE = 2, /// Sent when a file is deleted or renamed |
71 | EFSW_DELETE = 2, /// Sent when a file is deleted or renamed | 71 | EFSW_MODIFIED = 3, /// Sent when a file is modified |
72 | EFSW_MODIFIED = 3, /// Sent when a file is modified | 72 | EFSW_MOVED = 4 /// Sent when a file is moved |
73 | EFSW_MOVED = 4 /// Sent when a file is moved | 73 | }; |
74 | |||
75 | enum efsw_error { | ||
76 | EFSW_NOTFOUND = -1, | ||
77 | EFSW_REPEATED = -2, | ||
78 | EFSW_OUTOFSCOPE = -3, | ||
79 | EFSW_NOTREADABLE = -4, | ||
80 | EFSW_REMOTE = -5, | ||
81 | EFSW_WATCHER_FAILED = -6, | ||
82 | EFSW_UNSPECIFIED = -7 | ||
74 | }; | 83 | }; |
75 | 84 | ||
76 | enum efsw_error | 85 | enum efsw_option { |
77 | { | 86 | /// For Windows, the default buffer size of 63*1024 bytes sometimes is not enough and |
78 | EFSW_NOTFOUND = -1, | 87 | /// file system events may be dropped. For that, using a different (bigger) buffer size |
79 | EFSW_REPEATED = -2, | 88 | /// can be defined here, but note that this does not work for network drives, |
80 | EFSW_OUTOFSCOPE = -3, | 89 | /// because a buffer larger than 64K will fail the folder being watched, see |
81 | EFSW_NOTREADABLE = -4, | 90 | /// http://msdn.microsoft.com/en-us/library/windows/desktop/aa365465(v=vs.85).aspx) |
82 | EFSW_REMOTE = -5, | 91 | EFSW_OPT_WIN_BUFFER_SIZE = 1, |
83 | EFSW_UNSPECIFIED = -6 | 92 | /// For Windows, per default all events are captured but we might only be interested |
93 | /// in a subset; the value of the option should be set to a bitwise or'ed set of | ||
94 | /// FILE_NOTIFY_CHANGE_* flags. | ||
95 | EFSW_OPT_WIN_NOTIFY_FILTER = 2, | ||
96 | /// For macOS (FSEvents backend), per default all modified event types are capture but we might | ||
97 | // only be interested in a subset; the value of the option should be set to a set of bitwise | ||
98 | // from: | ||
99 | // kFSEventStreamEventFlagItemFinderInfoMod | ||
100 | // kFSEventStreamEventFlagItemModified | ||
101 | // kFSEventStreamEventFlagItemInodeMetaMod | ||
102 | // Default configuration will set the 3 flags | ||
103 | EFSW_OPT_MAC_MODIFIED_FILTER = 3, | ||
104 | /// macOS sometimes informs incorrect or old file states that may confuse the consumer | ||
105 | /// The events sanitizer will try to sanitize incorrectly reported events in favor of reducing | ||
106 | /// the number of events reported. This will have an small performance and memory impact as a | ||
107 | /// consequence. | ||
108 | EFSW_OPT_MAC_SANITIZE_EVENTS = 4, | ||
109 | /// Linux does not support natively recursive watchers. This means that when using recursive | ||
110 | /// watches efsw registers new watchers for each directory. If new file are created between | ||
111 | /// the time efsw takes to register the new directory those events might be missed. To avoid | ||
112 | /// missing new file notifications efsw will trigger synthetic new file events for existing | ||
113 | /// files in the new directroy watched. This might have the unintended consequence of sending | ||
114 | /// duplicated created events due to the system also emitting this event. | ||
115 | LINUX_PRODUCE_SYNTHETIC_EVENTS = 5, | ||
84 | }; | 116 | }; |
85 | 117 | ||
86 | /// Basic interface for listening for file events. | 118 | /// Basic interface for listening for file events. |
87 | typedef void (*efsw_pfn_fileaction_callback) ( | 119 | typedef void ( *efsw_pfn_fileaction_callback )( efsw_watcher watcher, efsw_watchid watchid, |
88 | efsw_watcher watcher, | 120 | const char* dir, const char* filename, |
89 | efsw_watchid watchid, | 121 | enum efsw_action action, const char* old_filename, |
90 | const char* dir, | 122 | void* param ); |
91 | const char* filename, | 123 | |
92 | enum efsw_action action, | 124 | typedef struct { |
93 | const char* old_filename, | 125 | enum efsw_option option; |
94 | void* param | 126 | int value; |
95 | ); | 127 | } efsw_watcher_option; |
96 | 128 | ||
97 | /** | 129 | /** |
98 | * Creates a new file-watcher | 130 | * Creates a new file-watcher |
99 | * @param generic_mode Force the use of the Generic file watcher | 131 | * @param generic_mode Force the use of the Generic file watcher |
100 | */ | 132 | */ |
101 | efsw_watcher EFSW_API efsw_create(int generic_mode); | 133 | efsw_watcher EFSW_API efsw_create( int generic_mode ); |
102 | 134 | ||
103 | /// Release the file-watcher and unwatch any directories | 135 | /// Release the file-watcher and unwatch any directories |
104 | void EFSW_API efsw_release(efsw_watcher watcher); | 136 | void EFSW_API efsw_release( efsw_watcher watcher ); |
105 | 137 | ||
106 | /// Retreive last error occured by file-watcher | 138 | /// Retrieve last error occured by file-watcher |
107 | EFSW_API const char* efsw_getlasterror(); | 139 | EFSW_API const char* efsw_getlasterror(); |
108 | 140 | ||
109 | /// Add a directory watch. Same as the other addWatch, but doesn't have recursive option. | 141 | /// Reset file-watcher last error |
110 | /// For backwards compatibility. | 142 | EFSW_API void efsw_clearlasterror(); |
143 | |||
144 | /// Add a directory watch | ||
111 | /// On error returns WatchID with Error type. | 145 | /// On error returns WatchID with Error type. |
112 | efsw_watchid EFSW_API efsw_addwatch(efsw_watcher watcher, const char* directory, | 146 | efsw_watchid EFSW_API efsw_addwatch( efsw_watcher watcher, const char* directory, |
113 | efsw_pfn_fileaction_callback callback_fn, int recursive, void* param); | 147 | efsw_pfn_fileaction_callback callback_fn, int recursive, |
148 | void* param ); | ||
149 | |||
150 | /// Add a directory watch, specifying options | ||
151 | /// @param options Pointer to an array of watcher options | ||
152 | /// @param nr_options Number of options referenced by \p options | ||
153 | efsw_watchid EFSW_API efsw_addwatch_withoptions( efsw_watcher watcher, const char* directory, | ||
154 | efsw_pfn_fileaction_callback callback_fn, | ||
155 | int recursive, efsw_watcher_option* options, | ||
156 | int options_number, void* param ); | ||
114 | 157 | ||
115 | /// Remove a directory watch. This is a brute force search O(nlogn). | 158 | /// Remove a directory watch. This is a brute force search O(nlogn). |
116 | void EFSW_API efsw_removewatch(efsw_watcher watcher, const char* directory); | 159 | void EFSW_API efsw_removewatch( efsw_watcher watcher, const char* directory ); |
117 | 160 | ||
118 | /// Remove a directory watch. This is a map lookup O(logn). | 161 | /// Remove a directory watch. This is a map lookup O(logn). |
119 | void EFSW_API efsw_removewatch_byid(efsw_watcher watcher, efsw_watchid watchid); | 162 | void EFSW_API efsw_removewatch_byid( efsw_watcher watcher, efsw_watchid watchid ); |
120 | 163 | ||
121 | /// Starts watching ( in other thread ) | 164 | /// Starts watching ( in other thread ) |
122 | void EFSW_API efsw_watch(efsw_watcher watcher); | 165 | void EFSW_API efsw_watch( efsw_watcher watcher ); |
123 | 166 | ||
124 | /** | 167 | /** |
125 | * Allow recursive watchers to follow symbolic links to other directories | 168 | * Allow recursive watchers to follow symbolic links to other directories |
126 | * followSymlinks is disabled by default | 169 | * followSymlinks is disabled by default |
127 | */ | 170 | */ |
128 | void EFSW_API efsw_follow_symlinks(efsw_watcher watcher, int enable); | 171 | void EFSW_API efsw_follow_symlinks( efsw_watcher watcher, int enable ); |
129 | 172 | ||
130 | /** @return If can follow symbolic links to directorioes */ | 173 | /** @return If can follow symbolic links to directorioes */ |
131 | int EFSW_API efsw_follow_symlinks_isenabled(efsw_watcher watcher); | 174 | int EFSW_API efsw_follow_symlinks_isenabled( efsw_watcher watcher ); |
132 | 175 | ||
133 | /** | 176 | /** |
134 | * When enable this it will allow symlinks to watch recursively out of the pointed directory. | 177 | * When enable this it will allow symlinks to watch recursively out of the pointed directory. |
135 | * follorSymlinks must be enabled to this work. | 178 | * follorSymlinks must be enabled to this work. |
136 | * For example, added symlink to /home/folder, and the symlink points to /, this by default is not allowed, | 179 | * For example, added symlink to /home/folder, and the symlink points to /, this by default is not |
137 | * it's only allowed to symlink anything from /home/ and deeper. This is to avoid great levels of recursion. | 180 | * allowed, it's only allowed to symlink anything from /home/ and deeper. This is to avoid great |
138 | * Enabling this could lead in infinite recursion, and crash the watcher ( it will try not to avoid this ). | 181 | * levels of recursion. Enabling this could lead in infinite recursion, and crash the watcher ( it |
139 | * Buy enabling out of scope links, it will allow this behavior. | 182 | * will try not to avoid this ). Buy enabling out of scope links, it will allow this behavior. |
140 | * allowOutOfScopeLinks are disabled by default. | 183 | * allowOutOfScopeLinks are disabled by default. |
141 | */ | 184 | */ |
142 | void EFSW_API efsw_allow_outofscopelinks(efsw_watcher watcher, int allow); | 185 | void EFSW_API efsw_allow_outofscopelinks( efsw_watcher watcher, int allow ); |
143 | 186 | ||
144 | /// @return Returns if out of scope links are allowed | 187 | /// @return Returns if out of scope links are allowed |
145 | int EFSW_API efsw_outofscopelinks_isallowed(efsw_watcher watcher); | 188 | int EFSW_API efsw_outofscopelinks_isallowed( efsw_watcher watcher ); |
146 | 189 | ||
147 | #ifdef __cplusplus | 190 | #ifdef __cplusplus |
148 | } | 191 | } |