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



Page generated by Doxygen 1.8.14 for MRPT 1.5.9 Git: 690a4699f Wed Apr 15 19:29:53 2020 +0200 at mié abr 15 19:30:12 CEST 2020