Main MRPT website > C++ reference
MRPT logo

CFileSystemWatcher.h

Go to the documentation of this file.
00001 /* +---------------------------------------------------------------------------+
00002    |          The Mobile Robot Programming Toolkit (MRPT) C++ library          |
00003    |                                                                           |
00004    |                   http://mrpt.sourceforge.net/                            |
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                   */
00049                 class BASE_IMPEXP CFileSystemWatcher
00050                 {
00051                 public:
00052                         /** Each of the changes detected by utils::CFileSystemWatcher
00053                           */
00054                         struct BASE_IMPEXP TFileSystemChange
00055                         {
00056                                 TFileSystemChange() : 
00057                                         path(), isDir(false),
00058                                         eventModified(false), eventCloseWrite(false),
00059                                         eventDeleted(false), eventMovedTo(false),
00060                                         eventMovedFrom(false), eventCreated(false),
00061                                         eventAccessed(false) {}
00062 
00063                                 std::string path;                               //!< Complete path of the file/directory that has changed.
00064                                 bool            isDir;                          //!< Whether the event happened to a file or a directory.
00065                                 bool            eventModified;
00066                                 bool            eventCloseWrite;
00067                                 bool            eventDeleted;
00068                                 bool            eventMovedTo;
00069                                 bool            eventMovedFrom;
00070                                 bool            eventCreated;
00071                                 bool            eventAccessed;
00072                         };
00073 
00074                         typedef std::deque<TFileSystemChange>   TFileSystemChangeList;
00075 
00076                         /** Creates the subscription to a specified path.
00077                           * \param path The file or directory to watch.
00078                           */
00079                         CFileSystemWatcher(     const std::string &path );
00080 
00081                         /** Destructor
00082                           */
00083                         virtual ~CFileSystemWatcher();
00084 
00085                         /** Call this method sometimes to get the list of changes in the watched directory.
00086                           *  \sa processChange
00087                           */
00088                         void getChanges( TFileSystemChangeList &out_list );
00089 
00090                 private:
00091                         std::string             m_watchedDirectory; //!< Ended in "/"
00092         #ifdef MRPT_OS_WINDOWS
00093                         void    *m_hNotif;
00094                         mrpt::system::TThreadHandle     m_watchThread;
00095                         void thread_win32_watch(); //!< Watch thread; only needed in win32
00096                         mrpt::utils::CThreadSafeQueue<TFileSystemChange>  m_queue_events_win32;
00097 
00098         #endif
00099 
00100         #if defined(MRPT_OS_LINUX) || defined(MRPT_OS_APPLE)
00101                         int     m_fd;  //!< The fd returned by inotify_init.
00102                         int     m_wd;  //!< The fd of the watch.
00103         #endif
00104 
00105                 }; // End of class def.
00106 
00107         } // End of namespace
00108 } // End of namespace
00109 
00110 #endif



Page generated by Doxygen 1.7.3 for MRPT 0.9.4 SVN:exported at Tue Jan 25 21:56:31 UTC 2011