00001 /* +---------------------------------------------------------------------------+ 00002 | The Mobile Robot Programming Toolkit (MRPT) C++ library | 00003 | | 00004 | http://www.mrpt.org/ | 00005 | | 00006 | Copyright (C) 2005-2011 University of Malaga | 00007 | | 00008 | This software was written by the Machine Perception and Intelligent | 00009 | Robotics Lab, University of Malaga (Spain). | 00010 | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> | 00011 | | 00012 | This file is part of the MRPT project. | 00013 | | 00014 | MRPT is free software: you can redistribute it and/or modify | 00015 | it under the terms of the GNU General Public License as published by | 00016 | the Free Software Foundation, either version 3 of the License, or | 00017 | (at your option) any later version. | 00018 | | 00019 | MRPT is distributed in the hope that it will be useful, | 00020 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00021 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 00022 | GNU General Public License for more details. | 00023 | | 00024 | You should have received a copy of the GNU General Public License | 00025 | along with MRPT. If not, see <http://www.gnu.org/licenses/>. | 00026 | | 00027 +---------------------------------------------------------------------------+ */ 00028 #ifndef CFileSystemWatcher_H 00029 #define CFileSystemWatcher_H 00030 00031 #include <mrpt/utils/utils_defs.h> 00032 #include <mrpt/system/os.h> 00033 #include <mrpt/system/threads.h> 00034 #include <mrpt/utils/CThreadSafeQueue.h> 00035 00036 /*--------------------------------------------------------------- 00037 Class 00038 ---------------------------------------------------------------*/ 00039 namespace mrpt 00040 { 00041 namespace system 00042 { 00043 /** This class subscribes to notifications of file system changes, thus it can be used to efficiently stay informed about changes in a directory tree. 00044 * - Windows: Requires Windows 2000 or newer. 00045 * - Linux: Requires kernel 2.6.13 or newer. 00046 * Using this class in an old Linux or other unsoported system (Unix,etc...) has no effect, i.e. no notification will be ever received. 00047 * \sa CDirectoryExplorer 00048 * \ingroup mrpt_base_grp 00049 */ 00050 class BASE_IMPEXP CFileSystemWatcher 00051 { 00052 public: 00053 /** Each of the changes detected by utils::CFileSystemWatcher 00054 */ 00055 struct BASE_IMPEXP TFileSystemChange 00056 { 00057 TFileSystemChange() : 00058 path(), isDir(false), 00059 eventModified(false), eventCloseWrite(false), 00060 eventDeleted(false), eventMovedTo(false), 00061 eventMovedFrom(false), eventCreated(false), 00062 eventAccessed(false) {} 00063 00064 std::string path; //!< Complete path of the file/directory that has changed. 00065 bool isDir; //!< Whether the event happened to a file or a directory. 00066 bool eventModified; 00067 bool eventCloseWrite; 00068 bool eventDeleted; 00069 bool eventMovedTo; 00070 bool eventMovedFrom; 00071 bool eventCreated; 00072 bool eventAccessed; 00073 }; 00074 00075 typedef std::deque<TFileSystemChange> TFileSystemChangeList; 00076 00077 /** Creates the subscription to a specified path. 00078 * \param path The file or directory to watch. 00079 */ 00080 CFileSystemWatcher( const std::string &path ); 00081 00082 /** Destructor 00083 */ 00084 virtual ~CFileSystemWatcher(); 00085 00086 /** Call this method sometimes to get the list of changes in the watched directory. 00087 * \sa processChange 00088 */ 00089 void getChanges( TFileSystemChangeList &out_list ); 00090 00091 private: 00092 std::string m_watchedDirectory; //!< Ended in "/" 00093 #ifdef MRPT_OS_WINDOWS 00094 void *m_hNotif; 00095 mrpt::system::TThreadHandle m_watchThread; 00096 void thread_win32_watch(); //!< Watch thread; only needed in win32 00097 mrpt::utils::CThreadSafeQueue<TFileSystemChange> m_queue_events_win32; 00098 00099 #endif 00100 00101 #if defined(MRPT_OS_LINUX) || defined(MRPT_OS_APPLE) 00102 int m_fd; //!< The fd returned by inotify_init. 00103 int m_wd; //!< The fd of the watch. 00104 #endif 00105 00106 }; // End of class def. 00107 00108 } // End of namespace 00109 } // End of namespace 00110 00111 #endif
| Page generated by Doxygen 1.7.5 for MRPT 0.9.5 SVN: at Thu Oct 13 21:25:36 UTC 2011 |