Main MRPT website > C++ reference for MRPT 1.9.9
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-2017, 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>
15 #include <thread>
16 
17 namespace mrpt
18 {
19 namespace system
20 {
21 /** This class subscribes to notifications of file system changes, thus it can
22  * be used to efficiently stay informed about changes in a directory tree.
23  * - Windows: Requires Windows 2000 or newer.
24  * - Linux: Requires kernel 2.6.13 or newer.
25  * Using this class in an old Linux or other unsoported system (Unix,etc...)
26  * has no effect, i.e. no notification will be ever received.
27  * \sa CDirectoryExplorer
28  * \ingroup mrpt_base_grp
29  */
31 {
32  public:
33  /** Each of the changes detected by utils::CFileSystemWatcher
34  */
36  {
38  : path(),
39  isDir(false),
40  eventModified(false),
41  eventCloseWrite(false),
42  eventDeleted(false),
43  eventMovedTo(false),
44  eventMovedFrom(false),
45  eventCreated(false),
46  eventAccessed(false)
47  {
48  }
49 
50  /** Complete path of the file/directory that has changed. */
52  /** Whether the event happened to a file or a directory. */
53  bool isDir;
61  };
62 
63  typedef std::deque<TFileSystemChange> TFileSystemChangeList;
64 
65  /** Creates the subscription to a specified path.
66  * \param path The file or directory to watch.
67  */
68  CFileSystemWatcher(const std::string& path);
69 
70  /** Destructor
71  */
72  virtual ~CFileSystemWatcher();
73 
74  /** Call this method sometimes to get the list of changes in the watched
75  * directory.
76  * \sa processChange
77  */
78  void getChanges(TFileSystemChangeList& out_list);
79 
80  private:
81  /** Ended in "/" */
83 #ifdef MRPT_OS_WINDOWS
84  void* m_hNotif;
85  std::thread m_watchThread;
86  /** Watch thread; only needed in win32 */
87  void thread_win32_watch();
89 
90 #endif
91 
92 #if defined(MRPT_OS_LINUX) || defined(MRPT_OS_APPLE)
93  /** The fd returned by inotify_init. */
94  int m_fd;
95  /** The fd of the watch. */
96  int m_wd;
97 #endif
98 
99 }; // End of class def.
100 
101 } // End of namespace
102 } // End of namespace
103 
104 #endif
std::string path
Complete path of the file/directory that has changed.
void getChanges(TFileSystemChangeList &out_list)
Call this method sometimes to get the list of changes in the watched directory.
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...
GLsizei const GLchar ** string
Definition: glext.h:4101
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.
virtual ~CFileSystemWatcher()
Destructor.
Each of the changes detected by utils::CFileSystemWatcher.
CFileSystemWatcher(const std::string &path)
Creates the subscription to a specified path.



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: ae4571287 Thu Nov 23 00:06:53 2017 +0100 at dom oct 27 23:51:55 CET 2019