![]() |
Main Page
Class Hierarchy
Alphabetical List
Compound List
File List
Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * Monitor the status of a file * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2003 by Mathew Robertson. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************/ 00022 #ifndef FXFILEMONITOR_H 00023 #define FXFILEMONITOR_H 00024 00025 #ifndef FXBASEOBJECT_H 00026 #include "FXBaseObject.h" 00027 #endif 00028 namespace FXEX { 00029 00030 /** 00031 * Monitors the status of a file, whether it exists, and its size as it grows. 00032 * Can optionally specify a timeout for when a file stops growing. 00033 */ 00034 class FXAPI FXFileMonitor : public FXBaseObject { 00035 FXDECLARE (FXFileMonitor) 00036 00037 private: 00038 FXString file; 00039 FXint growtime; 00040 FXint endtimeout; 00041 unsigned long size; 00042 FXTime modified; 00043 00044 protected: 00045 FXFileMonitor(){} 00046 00047 public: 00048 enum { 00049 ID_FILE_CREATE=FXBaseObject::ID_LAST, 00050 ID_FILE_CHANGED, 00051 ID_FILE_END, 00052 ID_LAST 00053 }; 00054 00055 public: 00056 long onFileCreate(FXObject*,FXSelector,void*); 00057 long onFileChange(FXObject*,FXSelector,void*); 00058 long onFileEnd(FXObject*,FXSelector,void*); 00059 long onFileCreated(FXObject*,FXSelector,void*); 00060 long onFileChanged(FXObject*,FXSelector,void*); 00061 long onFileDeleted(FXObject*,FXSelector,void*); 00062 long onFileClosed(FXObject*,FXSelector,void*); 00063 00064 public: 00065 /** 00066 * Monitor a file: 00067 * -> ms frequency of scanning to see if the file exists or is growing 00068 * -> to once the file starts growing, an event is generated if the file stops 00069 * growing for at least this timeout. (in secs) Can be <= 0 to stop this 00070 * begin generated (ie we detect changes only) 00071 * Note: If the file grows after the timeout event, further change events will be generated. 00072 */ 00073 FXFileMonitor(FXApp *a,const FXString& file,FXint ms=2000,FXint to=0,FXObject *tgt=NULL,FXSelector sel=0); 00074 00075 /// create resource 00076 virtual void create(); 00077 00078 /// set monitor to new file 00079 void filename(const FXString& file); 00080 00081 /// get filename being monitored 00082 FXString filename() { return file; } 00083 00084 /// set the scantime 00085 void setScanTime(FXint ms); 00086 00087 /// get the scantime 00088 FXint getScanTime() const { return growtime; } 00089 00090 /// set the timeout (in secs) 00091 void setEndTimeout(FXint to); 00092 00093 /// get the timeout 00094 FXint getEndTimeout() const { return endtimeout; } 00095 00096 /// reset the monitor - this causes the events to be regenerated 00097 void reset(); 00098 00099 /// save object to stream 00100 virtual void save(FXStream& store) const; 00101 00102 /// load object from stream 00103 virtual void load(FXStream& store); 00104 00105 /// dtor 00106 virtual ~FXFileMonitor(); 00107 }; 00108 00109 } // namespace FXEX 00110 #endif // FXFILEMONITOR_H