00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Gerome Mortelecque 00008 * Side Effects 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT_FileMonitor.h UT library (C++) 00015 * 00016 * COMMENTS: Check if files in a given directory have been changed. 00017 * 00018 * 00019 */ 00020 00021 #ifndef __UT_FileMonitor_h__ 00022 #define __UT_FileMonitor_h__ 00023 00024 #include "UT_API.h" 00025 #include "UT_StringArray.h" 00026 #include "UT_RefArray.h" 00027 #include "UT_IntArray.h" 00028 #include "UT_Lock.h" 00029 #include "UT_Signal.h" 00030 #include "UT_Thread.h" 00031 00032 00033 class UT_FileMonitor; 00034 class UT_String; 00035 class UT_Thread; 00036 00037 typedef bool ( *UTmonitorFunc )( void *op , const char* filename ); 00038 00039 class UT_API UT_FileMonitor 00040 { 00041 public: 00042 UT_FileMonitor(); 00043 virtual ~UT_FileMonitor(); 00044 00045 // add file to the monitor list 00046 bool addFile( const char *filename, 00047 UTmonitorFunc func, void *data ); 00048 // remove file from the monitor list 00049 bool removeFile( void *data , const char* filename=0 ); 00050 00051 const UT_StringArray &getFileList() const { return myMonitoredFiles; } ; 00052 00053 void startMyThread(); 00054 void stopMyThread(); 00055 00056 void getDirectory( const char *str, UT_String &dir ); 00057 00058 void executeCallbacks( const char* file ); 00059 00060 00061 protected: 00062 UT_RefArray < UTmonitorFunc > myCallbacks; 00063 00064 00065 private: 00066 static void* monitorFiles( void *data ); 00067 00068 void removeMonitoredFile( const char *filename ); 00069 void removeFileEntry( int index ); 00070 00071 00072 UT_Lock myFileLock; 00073 UT_PtrArray < void* > myOPs; 00074 UT_StringArray myOPFileRoots; 00075 UT_StringArray myOPFiles; 00076 UT_StringArray myDirList; 00077 UT_StringArray myMonitoredFiles; 00078 UT_IntArray myFHandle; 00079 UT_IntArray myFTime; 00080 00081 UT_Thread *myThread; 00082 bool myQuitThread; 00083 }; 00084 00085 UT_API extern UT_FileMonitor *UTgetFileMonitor(); 00086 00087 00088 #endif //__UT_FileMonitor_h__
1.5.9