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-2018, 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 #pragma once
10 
11 #include <mrpt/system/os.h>
12 #include <thread>
13 #include <mutex>
14 #include <queue>
15 
16 namespace mrpt
17 {
18 namespace system
19 {
20 /** This class subscribes to notifications of file system changes, thus it can
21  * 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...)
25  * has no effect, i.e. no notification will be ever received.
26  * \sa CDirectoryExplorer
27  * \ingroup mrpt_system_grp
28  */
30 {
31  public:
32  /** Each of the changes detected by utils::CFileSystemWatcher
33  */
35  {
37  /** Complete path of the file/directory that has changed. */
39  /** Whether the event happened to a file or a directory. */
40  bool isDir{false};
41  bool eventModified{false};
42  bool eventCloseWrite{false};
43  bool eventDeleted{false};
44  bool eventMovedTo{false};
45  bool eventMovedFrom{false};
46  bool eventCreated{false};
47  bool eventAccessed{false};
48  };
49 
50  using TFileSystemChangeList = std::deque<TFileSystemChange>;
51 
52  /** Creates the subscription to a specified path.
53  * \param path The file or directory to watch.
54  */
55  CFileSystemWatcher(const std::string& path);
56 
57  /** Destructor
58  */
59  virtual ~CFileSystemWatcher();
60 
61  /** Call this method sometimes to get the list of changes in the watched
62  * directory.
63  * \sa processChange
64  */
65  void getChanges(TFileSystemChangeList& out_list);
66 
67  private:
68  /** Ended in "/" */
70 #ifdef _WIN32
71  void* m_hNotif{nullptr};
72  std::thread m_watchThread;
73  /** Watch thread; only needed in win32 */
74  void thread_win32_watch();
75  std::queue<TFileSystemChange*> m_queue_events_win32_msgs;
76  mutable std::mutex m_queue_events_win32_cs;
77 #endif
78 
79 #if defined(MRPT_OS_LINUX) || defined(__APPLE__)
80  /** The fd returned by inotify_init. */
81  int m_fd;
82  /** The fd of the watch. */
83  int m_wd;
84 #endif
85 
86 }; // End of class def.
87 
88 } // End of namespace
89 } // End of namespace
os.h
mrpt::system::CFileSystemWatcher::~CFileSystemWatcher
virtual ~CFileSystemWatcher()
Destructor.
Definition: CFileSystemWatcher.cpp:90
mrpt::system::CFileSystemWatcher::TFileSystemChange
Each of the changes detected by utils::CFileSystemWatcher.
Definition: CFileSystemWatcher.h:34
mrpt::system::CFileSystemWatcher::m_watchedDirectory
std::string m_watchedDirectory
Ended in "/".
Definition: CFileSystemWatcher.h:69
mrpt::system::CFileSystemWatcher::TFileSystemChange::TFileSystemChange
TFileSystemChange()
Definition: CFileSystemWatcher.h:36
mrpt::system::CFileSystemWatcher::m_hNotif
void * m_hNotif
Definition: CFileSystemWatcher.h:71
mrpt::system::CFileSystemWatcher::thread_win32_watch
void thread_win32_watch()
Watch thread; only needed in win32.
Definition: CFileSystemWatcher.cpp:252
mrpt::system::CFileSystemWatcher::TFileSystemChange::eventMovedTo
bool eventMovedTo
Definition: CFileSystemWatcher.h:44
mrpt::system::CFileSystemWatcher::TFileSystemChange::isDir
bool isDir
Whether the event happened to a file or a directory.
Definition: CFileSystemWatcher.h:40
mrpt
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
Definition: CKalmanFilterCapable.h:30
mrpt::system::CFileSystemWatcher::TFileSystemChange::eventAccessed
bool eventAccessed
Definition: CFileSystemWatcher.h:47
mrpt::system::CFileSystemWatcher::TFileSystemChange::eventMovedFrom
bool eventMovedFrom
Definition: CFileSystemWatcher.h:45
mrpt::system::CFileSystemWatcher::TFileSystemChange::eventDeleted
bool eventDeleted
Definition: CFileSystemWatcher.h:43
mrpt::system::CFileSystemWatcher
This class subscribes to notifications of file system changes, thus it can be used to efficiently sta...
Definition: CFileSystemWatcher.h:29
mrpt::system::CFileSystemWatcher::TFileSystemChange::eventCreated
bool eventCreated
Definition: CFileSystemWatcher.h:46
mrpt::system::CFileSystemWatcher::m_queue_events_win32_msgs
std::queue< TFileSystemChange * > m_queue_events_win32_msgs
Definition: CFileSystemWatcher.h:75
mrpt::system::CFileSystemWatcher::m_watchThread
std::thread m_watchThread
Definition: CFileSystemWatcher.h:72
mrpt::system::CFileSystemWatcher::m_queue_events_win32_cs
std::mutex m_queue_events_win32_cs
Definition: CFileSystemWatcher.h:76
mrpt::system::CFileSystemWatcher::CFileSystemWatcher
CFileSystemWatcher(const std::string &path)
Creates the subscription to a specified path.
Definition: CFileSystemWatcher.cpp:41
mrpt::system::CFileSystemWatcher::getChanges
void getChanges(TFileSystemChangeList &out_list)
Call this method sometimes to get the list of changes in the watched directory.
Definition: CFileSystemWatcher.cpp:116
mrpt::system::CFileSystemWatcher::TFileSystemChange::eventModified
bool eventModified
Definition: CFileSystemWatcher.h:41
mrpt::system::CFileSystemWatcher::TFileSystemChange::eventCloseWrite
bool eventCloseWrite
Definition: CFileSystemWatcher.h:42
string
GLsizei const GLchar ** string
Definition: glext.h:4101
mrpt::system::CFileSystemWatcher::TFileSystemChangeList
std::deque< TFileSystemChange > TFileSystemChangeList
Definition: CFileSystemWatcher.h:50
mrpt::system::CFileSystemWatcher::TFileSystemChange::path
std::string path
Complete path of the file/directory that has changed.
Definition: CFileSystemWatcher.h:38



Page generated by Doxygen 1.8.17 for MRPT 1.9.9 Git: ad3a9d8ae Tue May 1 23:10:22 2018 -0700 at miƩ 12 jul 2023 10:03:34 CEST