Main MRPT website > C++ reference
MRPT logo
CFileSystemWatcher.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | The Mobile Robot Programming Toolkit (MRPT) C++ library |
3  | |
4  | http://www.mrpt.org/ |
5  | |
6  | Copyright (C) 2005-2012 University of Malaga |
7  | |
8  | This software was written by the Machine Perception and Intelligent |
9  | Robotics Lab, University of Malaga (Spain). |
10  | Contact: Jose-Luis Blanco <jlblanco@ctima.uma.es> |
11  | |
12  | This file is part of the MRPT project. |
13  | |
14  | MRPT is free software: you can redistribute it and/or modify |
15  | it under the terms of the GNU General Public License as published by |
16  | the Free Software Foundation, either version 3 of the License, or |
17  | (at your option) any later version. |
18  | |
19  | MRPT is distributed in the hope that it will be useful, |
20  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
21  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
22  | GNU General Public License for more details. |
23  | |
24  | You should have received a copy of the GNU General Public License |
25  | along with MRPT. If not, see <http://www.gnu.org/licenses/>. |
26  | |
27  +---------------------------------------------------------------------------+ */
28 #ifndef CFileSystemWatcher_H
29 #define CFileSystemWatcher_H
30 
31 #include <mrpt/utils/utils_defs.h>
32 #include <mrpt/system/os.h>
33 #include <mrpt/system/threads.h>
35 
36 /*---------------------------------------------------------------
37  Class
38  ---------------------------------------------------------------*/
39 namespace mrpt
40 {
41  namespace system
42  {
43  /** This class subscribes to notifications of file system changes, thus it can be used to efficiently stay informed about changes in a directory tree.
44  * - Windows: Requires Windows 2000 or newer.
45  * - Linux: Requires kernel 2.6.13 or newer.
46  * Using this class in an old Linux or other unsoported system (Unix,etc...) has no effect, i.e. no notification will be ever received.
47  * \sa CDirectoryExplorer
48  * \ingroup mrpt_base_grp
49  */
51  {
52  public:
53  /** Each of the changes detected by utils::CFileSystemWatcher
54  */
56  {
58  path(), isDir(false),
59  eventModified(false), eventCloseWrite(false),
60  eventDeleted(false), eventMovedTo(false),
61  eventMovedFrom(false), eventCreated(false),
62  eventAccessed(false) {}
63 
64  std::string path; //!< Complete path of the file/directory that has changed.
65  bool isDir; //!< Whether the event happened to a file or a directory.
73  };
74 
75  typedef std::deque<TFileSystemChange> TFileSystemChangeList;
76 
77  /** Creates the subscription to a specified path.
78  * \param path The file or directory to watch.
79  */
80  CFileSystemWatcher( const std::string &path );
81 
82  /** Destructor
83  */
84  virtual ~CFileSystemWatcher();
85 
86  /** Call this method sometimes to get the list of changes in the watched directory.
87  * \sa processChange
88  */
89  void getChanges( TFileSystemChangeList &out_list );
90 
91  private:
92  std::string m_watchedDirectory; //!< Ended in "/"
93  #ifdef MRPT_OS_WINDOWS
94  void *m_hNotif;
95  mrpt::system::TThreadHandle m_watchThread;
96  void thread_win32_watch(); //!< Watch thread; only needed in win32
98 
99  #endif
100 
101  #if defined(MRPT_OS_LINUX) || defined(MRPT_OS_APPLE)
102  int m_fd; //!< The fd returned by inotify_init.
103  int m_wd; //!< The fd of the watch.
104  #endif
105 
106  }; // End of class def.
107 
108  } // End of namespace
109 } // End of namespace
110 
111 #endif



Page generated by Doxygen 1.8.3 for MRPT 0.9.6 SVN: at Fri Feb 15 22:05:02 EST 2013