Main MRPT website > C++ reference for MRPT 1.4.0
CFileSystemWatcher.h
Go to the documentation of this file.
1 /* +---------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2016, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +---------------------------------------------------------------------------+ */
9 #ifndef CFileSystemWatcher_H
10 #define CFileSystemWatcher_H
11 
12 #include <mrpt/utils/utils_defs.h>
13 #include <mrpt/system/os.h>
14 #include <mrpt/system/threads.h>
16 
17 /*---------------------------------------------------------------
18  Class
19  ---------------------------------------------------------------*/
20 namespace mrpt
21 {
22  namespace system
23  {
24  /** This class subscribes to notifications of file system changes, thus it can be used to efficiently stay informed about changes in a directory tree.
25  * - Windows: Requires Windows 2000 or newer.
26  * - Linux: Requires kernel 2.6.13 or newer.
27  * Using this class in an old Linux or other unsoported system (Unix,etc...) has no effect, i.e. no notification will be ever received.
28  * \sa CDirectoryExplorer
29  * \ingroup mrpt_base_grp
30  */
32  {
33  public:
34  /** Each of the changes detected by utils::CFileSystemWatcher
35  */
37  {
39  path(), isDir(false),
40  eventModified(false), eventCloseWrite(false),
41  eventDeleted(false), eventMovedTo(false),
42  eventMovedFrom(false), eventCreated(false),
43  eventAccessed(false) {}
44 
45  std::string path; //!< Complete path of the file/directory that has changed.
46  bool isDir; //!< Whether the event happened to a file or a directory.
54  };
55 
56  typedef std::deque<TFileSystemChange> TFileSystemChangeList;
57 
58  /** Creates the subscription to a specified path.
59  * \param path The file or directory to watch.
60  */
61  CFileSystemWatcher( const std::string &path );
62 
63  /** Destructor
64  */
65  virtual ~CFileSystemWatcher();
66 
67  /** Call this method sometimes to get the list of changes in the watched directory.
68  * \sa processChange
69  */
70  void getChanges( TFileSystemChangeList &out_list );
71 
72  private:
73  std::string m_watchedDirectory; //!< Ended in "/"
74  #ifdef MRPT_OS_WINDOWS
75  void *m_hNotif;
76  mrpt::system::TThreadHandle m_watchThread;
77  void thread_win32_watch(); //!< Watch thread; only needed in win32
79 
80  #endif
81 
82  #if defined(MRPT_OS_LINUX) || defined(MRPT_OS_APPLE)
83  int m_fd; //!< The fd returned by inotify_init.
84  int m_wd; //!< The fd of the watch.
85  #endif
86 
87  }; // End of class def.
88 
89  } // End of namespace
90 } // End of namespace
91 
92 #endif
std::string path
Complete path of the file/directory that has changed.
std::string m_watchedDirectory
Ended in "/".
std::deque< TFileSystemChange > TFileSystemChangeList
A thread-safe template queue for object passing between threads; for a template argument of T...
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
This class subscribes to notifications of file system changes, thus it can be used to efficiently sta...
bool isDir
Whether the event happened to a file or a directory.
This structure contains the information needed to interface the threads API on each platform: ...
Definition: threads.h:25
Each of the changes detected by utils::CFileSystemWatcher.



Page generated by Doxygen 1.8.11 for MRPT 1.4.0 SVN:Unversioned directory at Sun Jul 10 11:38:36 UTC 2016