diff options
Diffstat (limited to '')
| -rwxr-xr-x | src/3rdParty/efsw/FileWatcher.cpp | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/src/3rdParty/efsw/FileWatcher.cpp b/src/3rdParty/efsw/FileWatcher.cpp new file mode 100755 index 0000000..696a46f --- /dev/null +++ b/src/3rdParty/efsw/FileWatcher.cpp | |||
| @@ -0,0 +1,119 @@ | |||
| 1 | #include <efsw/FileSystem.hpp> | ||
| 2 | #include <efsw/FileWatcherGeneric.hpp> | ||
| 3 | #include <efsw/FileWatcherImpl.hpp> | ||
| 4 | #include <efsw/efsw.hpp> | ||
| 5 | |||
| 6 | #if EFSW_PLATFORM == EFSW_PLATFORM_WIN32 | ||
| 7 | #include <efsw/FileWatcherWin32.hpp> | ||
| 8 | #define FILEWATCHER_IMPL FileWatcherWin32 | ||
| 9 | #define BACKEND_NAME "Win32" | ||
| 10 | #elif EFSW_PLATFORM == EFSW_PLATFORM_INOTIFY | ||
| 11 | #include <efsw/FileWatcherInotify.hpp> | ||
| 12 | #define FILEWATCHER_IMPL FileWatcherInotify | ||
| 13 | #define BACKEND_NAME "Inotify" | ||
| 14 | #elif EFSW_PLATFORM == EFSW_PLATFORM_KQUEUE | ||
| 15 | #include <efsw/FileWatcherKqueue.hpp> | ||
| 16 | #define FILEWATCHER_IMPL FileWatcherKqueue | ||
| 17 | #define BACKEND_NAME "Kqueue" | ||
| 18 | #elif EFSW_PLATFORM == EFSW_PLATFORM_FSEVENTS | ||
| 19 | #include <efsw/FileWatcherFSEvents.hpp> | ||
| 20 | #define FILEWATCHER_IMPL FileWatcherFSEvents | ||
| 21 | #define BACKEND_NAME "FSEvents" | ||
| 22 | #else | ||
| 23 | #define FILEWATCHER_IMPL FileWatcherGeneric | ||
| 24 | #define BACKEND_NAME "Generic" | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #include <efsw/Debug.hpp> | ||
| 28 | |||
| 29 | namespace efsw { | ||
| 30 | |||
| 31 | FileWatcher::FileWatcher() : mFollowSymlinks( false ), mOutOfScopeLinks( false ) { | ||
| 32 | efDEBUG( "Using backend: %s\n", BACKEND_NAME ); | ||
| 33 | |||
| 34 | mImpl = new FILEWATCHER_IMPL( this ); | ||
| 35 | |||
| 36 | if ( !mImpl->initOK() ) { | ||
| 37 | efSAFE_DELETE( mImpl ); | ||
| 38 | |||
| 39 | efDEBUG( "Falled back to backend: %s\n", BACKEND_NAME ); | ||
| 40 | |||
| 41 | mImpl = new FileWatcherGeneric( this ); | ||
| 42 | } | ||
| 43 | } | ||
| 44 | |||
| 45 | FileWatcher::FileWatcher( bool useGenericFileWatcher ) : | ||
| 46 | mFollowSymlinks( false ), mOutOfScopeLinks( false ) { | ||
| 47 | if ( useGenericFileWatcher ) { | ||
| 48 | efDEBUG( "Using backend: Generic\n" ); | ||
| 49 | |||
| 50 | mImpl = new FileWatcherGeneric( this ); | ||
| 51 | } else { | ||
| 52 | efDEBUG( "Using backend: %s\n", BACKEND_NAME ); | ||
| 53 | |||
| 54 | mImpl = new FILEWATCHER_IMPL( this ); | ||
| 55 | |||
| 56 | if ( !mImpl->initOK() ) { | ||
| 57 | efSAFE_DELETE( mImpl ); | ||
| 58 | |||
| 59 | efDEBUG( "Falled back to backend: %s\n", BACKEND_NAME ); | ||
| 60 | |||
| 61 | mImpl = new FileWatcherGeneric( this ); | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 | FileWatcher::~FileWatcher() { | ||
| 67 | efSAFE_DELETE( mImpl ); | ||
| 68 | } | ||
| 69 | |||
| 70 | WatchID FileWatcher::addWatch( const std::string& directory, FileWatchListener* watcher ) { | ||
| 71 | if ( mImpl->mIsGeneric || !FileSystem::isRemoteFS( directory ) ) { | ||
| 72 | return mImpl->addWatch( directory, watcher, false ); | ||
| 73 | } else { | ||
| 74 | return Errors::Log::createLastError( Errors::FileRemote, directory ); | ||
| 75 | } | ||
| 76 | } | ||
| 77 | |||
| 78 | WatchID FileWatcher::addWatch( const std::string& directory, FileWatchListener* watcher, | ||
| 79 | bool recursive ) { | ||
| 80 | if ( mImpl->mIsGeneric || !FileSystem::isRemoteFS( directory ) ) { | ||
| 81 | return mImpl->addWatch( directory, watcher, recursive ); | ||
| 82 | } else { | ||
| 83 | return Errors::Log::createLastError( Errors::FileRemote, directory ); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | void FileWatcher::removeWatch( const std::string& directory ) { | ||
| 88 | mImpl->removeWatch( directory ); | ||
| 89 | } | ||
| 90 | |||
| 91 | void FileWatcher::removeWatch( WatchID watchid ) { | ||
| 92 | mImpl->removeWatch( watchid ); | ||
| 93 | } | ||
| 94 | |||
| 95 | void FileWatcher::watch() { | ||
| 96 | mImpl->watch(); | ||
| 97 | } | ||
| 98 | |||
| 99 | std::list<std::string> FileWatcher::directories() { | ||
| 100 | return mImpl->directories(); | ||
| 101 | } | ||
| 102 | |||
| 103 | void FileWatcher::followSymlinks( bool follow ) { | ||
| 104 | mFollowSymlinks = follow; | ||
| 105 | } | ||
| 106 | |||
| 107 | const bool& FileWatcher::followSymlinks() const { | ||
| 108 | return mFollowSymlinks; | ||
| 109 | } | ||
| 110 | |||
| 111 | void FileWatcher::allowOutOfScopeLinks( bool allow ) { | ||
| 112 | mOutOfScopeLinks = allow; | ||
| 113 | } | ||
| 114 | |||
| 115 | const bool& FileWatcher::allowOutOfScopeLinks() const { | ||
| 116 | return mOutOfScopeLinks; | ||
| 117 | } | ||
| 118 | |||
| 119 | } // namespace efsw | ||
