Pyrogenesis  trunk
dir_watch.h
Go to the documentation of this file.
1 /* Copyright (C) 2022 Wildfire Games.
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * portable directory change notification API.
25  */
26 
27 #ifndef INCLUDED_DIR_WATCH
28 #define INCLUDED_DIR_WATCH
29 
30 #include "lib/os_path.h"
31 
32 #include <vector>
33 #include <memory>
34 
35 struct DirWatch;
36 typedef std::shared_ptr<DirWatch> PDirWatch;
37 
38 /**
39  * start watching a single directory for changes.
40  *
41  * @param path (must end in slash)
42  * @param dirWatch opaque smart pointer to the watch state; used to
43  * manage its lifetime (this is deemed more convenient than a
44  * separate dir_watch_Remove interface).
45  *
46  * clients typically want to watch entire directory subtrees (e.g. a mod),
47  * which is supported by Windows but not FAM. to reduce overhead, the
48  * Windows backend always watches subtrees, but portable clients should
49  * still add a watch for each subdirectory (the shared watch state is
50  * reference-counted).
51  * rationale: since the VFS has per-directory data structures, it is
52  * convenient to store PDirWatch there instead of creating a second
53  * tree structure here.
54  **/
55 Status dir_watch_Add(const OsPath& path, PDirWatch& dirWatch);
56 
58 {
59 public:
60  enum EType
61  {
65  };
66 
68  : pathname(pathname), type(type)
69  {
70  }
71 
72  const OsPath& Pathname() const
73  {
74  return pathname;
75  }
76 
77  EType Type() const
78  {
79  return type;
80  }
81 
82 private:
85 };
86 
87 typedef std::vector<DirWatchNotification> DirWatchNotifications;
88 
89 /**
90  * return all pending directory watch notifications.
91  *
92  * @param notifications receives any pending notifications in unspecified order.
93  * @return Status (INFO::OK doesn't imply notifications were returned)
94  *
95  * note: the run time of this function is independent of the number of
96  * directory watches and number of files.
97  *
98  * rationale for a polling interface: users (e.g. the main game loop)
99  * typically want to receive change notifications at a single point,
100  * rather than deal with the complexity of asynchronous notifications.
101  **/
103 
104 #endif // #ifndef INCLUDED_DIR_WATCH
EType
Definition: dir_watch.h:60
std::vector< DirWatchNotification > DirWatchNotifications
Definition: dir_watch.h:87
std::shared_ptr< DirWatch > PDirWatch
Definition: dir_watch.h:35
const OsPath & Pathname() const
Definition: dir_watch.h:72
Definition: dir_watch.h:64
EType type
Definition: dir_watch.h:84
DirWatchNotification(const OsPath &pathname, EType type)
Definition: dir_watch.h:67
Status dir_watch_Add(const OsPath &path, PDirWatch &dirWatch)
start watching a single directory for changes.
Definition: dir_watch.cpp:28
OsPath path
Definition: dir_watch_inotify.cpp:78
Definition: path.h:79
EType Type() const
Definition: dir_watch.h:77
Definition: dir_watch.h:63
i64 Status
Error handling system.
Definition: status.h:169
Definition: dir_watch.h:57
OsPath pathname
Definition: dir_watch.h:83
Definition: dir_watch.h:62
Status dir_watch_Poll(DirWatchNotifications &notifications)
return all pending directory watch notifications.
Definition: dir_watch.cpp:33
Definition: dir_watch_inotify.cpp:65