Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef FileSystemWatcherH
00033 #define FileSystemWatcherH
00034
00035 #include <zeusbase/System/Thread.h>
00036 #include <zeusbase/System/SingleLinkedList.hpp>
00037 #include <zeusbase/System/StringMap.hpp>
00038 #include <zeusbase/System/Interfaces/IRunnable.hpp>
00039 #include <zeusbase/System/Interfaces/ISubject.hpp>
00040
00041 #if defined(ENABLE_LINUX_BINDING)
00042 #define LOOP_TFileSystemWatcher
00043 #else
00044 #if defined(USE_WINDOWS_H)
00045 #include <windows.h>
00046 #endif
00047
00048 #ifdef _MSC_VER
00049 #pragma warning(push, 1)
00050 #endif
00051
00052 #include <stdio.h>
00053
00054 #ifdef _MSC_VER
00055 #pragma warning(pop)
00056 #endif
00057
00058 #if _WIN32_WINNT >= 0x0351
00059 #undef LOOP_TFileSystemWatcher
00060 #else
00061 #define LOOP_TFileSystemWatcher
00062 #endif
00063 #endif
00064
00065
00066 BEGIN_NAMESPACE_Zeus
00067
00068 class IFileSystemWatcherObserver;
00069 class TCriticalSection;
00070 class TDirectory;
00071
00072
00076
00077 zeusbase_class TFileSystemWatcher : public TZObject, public IRunnable, public ISubject
00078 {
00079 public :
00080 TFileSystemWatcher(const IString& rPath, bool bIncludeSubTree = true);
00081
00082 void start();
00083 void stop();
00084 bool isStarted() const;
00085 void reset();
00086 TString getWatchedPath() const;
00087
00088
00089 virtual Retval MQUALIFIER attach(IObserver& rObserver);
00090 virtual Retval MQUALIFIER detach(IObserver& rObserver);
00091
00092
00093 MEMORY_MANAGER_DECL
00094
00095 protected:
00096 virtual ~TFileSystemWatcher();
00097
00098
00099 virtual void MQUALIFIER execute();
00100
00101
00102 virtual void onFileCreated(const IString& rFileName);
00103 virtual void onFileRemoved(const IString& rFileName);
00104 virtual void onFileChanged(const IString& rFileName);
00105 virtual void onFileRenamed(const IString& rOldFileName, const IString& rNewFileName);
00106 virtual void onUnknownAction(const IString& rFileName);
00107
00108
00109 private:
00111 TString m_strPath;
00113 bool m_bIncludeSubTree;
00115 bool m_bReset;
00117 TThread* m_pWatcherThread;
00119 TSingleLinkedList<IFileSystemWatcherObserver*> m_lstObserver;
00121 TCriticalSection& m_rLock;
00122
00123
00124
00127
00128 struct TypeEntry
00129 {
00131 Uint64 uldStamp;
00133 TString strAbsName;
00135 TStringMap<TypeEntry*> mapFileStamps;
00136
00137
00140
00141 TypeEntry()
00142 {
00143 uldStamp = 0;
00144 }
00145
00146
00149
00150 ~TypeEntry()
00151 {
00152 TIterator<TypeEntry*> It = mapFileStamps.getIterator();
00153 while(It.hasNextItem())
00154 {
00155 delete It.getNextItem();
00156 }
00157 mapFileStamps.clear();
00158 }
00159 };
00160
00161 void checkDirectory(TDirectory& rDir, TypeEntry& rEntry, bool bNotify);
00162
00163
00164 #if defined(LOOP_TFileSystemWatcher)
00165 void notifyOnRemoved(TypeEntry& rEntry);
00166 #else
00167
00168 HANDLE m_hFileSystemHandle;
00170 TCriticalSection& m_rHandleLock;
00171
00172 #endif
00173 };
00174
00175
00176
00177
00180
00181 inline bool TFileSystemWatcher::isStarted() const
00182 {
00183 return (m_pWatcherThread != NULL);
00184 }
00185
00186
00189
00190 inline TString TFileSystemWatcher::getWatchedPath() const
00191 {
00192 return m_strPath;
00193 }
00194
00195 END_NAMESPACE_Zeus
00196
00197
00198
00199
00200
00201 #endif