Pyrogenesis  trunk
dir_watch.h
Go to the documentation of this file.
1 /* Copyright (c) 2010 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 struct DirWatch;
33 typedef shared_ptr<DirWatch> PDirWatch;
34 
35 /**
36  * start watching a single directory for changes.
37  *
38  * @param path (must end in slash)
39  * @param dirWatch opaque smart pointer to the watch state; used to
40  * manage its lifetime (this is deemed more convenient than a
41  * separate dir_watch_Remove interface).
42  *
43  * clients typically want to watch entire directory subtrees (e.g. a mod),
44  * which is supported by Windows but not FAM. to reduce overhead, the
45  * Windows backend always watches subtrees, but portable clients should
46  * still add a watch for each subdirectory (the shared watch state is
47  * reference-counted).
48  * rationale: since the VFS has per-directory data structures, it is
49  * convenient to store PDirWatch there instead of creating a second
50  * tree structure here.
51  **/
52 LIB_API Status dir_watch_Add(const OsPath& path, PDirWatch& dirWatch);
53 
55 {
56 public:
57  enum EType
58  {
62  };
63 
65  : pathname(pathname), type(type)
66  {
67  }
68 
69  const OsPath& Pathname() const
70  {
71  return pathname;
72  }
73 
74  EType Type() const
75  {
76  return type;
77  }
78 
79 private:
82 };
83 
84 typedef std::vector<DirWatchNotification> DirWatchNotifications;
85 
86 /**
87  * return all pending directory watch notifications.
88  *
89  * @param notifications receives any pending notifications in unspecified order.
90  * @return Status (INFO::OK doesn't imply notifications were returned)
91  *
92  * note: the run time of this function is independent of the number of
93  * directory watches and number of files.
94  *
95  * rationale for a polling interface: users (e.g. the main game loop)
96  * typically want to receive change notifications at a single point,
97  * rather than deal with the complexity of asynchronous notifications.
98  **/
99 LIB_API Status dir_watch_Poll(DirWatchNotifications& notifications);
100 
101 #endif // #ifndef INCLUDED_DIR_WATCH
EType
Definition: dir_watch.h:57
const OsPath & Pathname() const
Definition: dir_watch.h:69
std::vector< DirWatchNotification > DirWatchNotifications
Definition: dir_watch.h:84
Definition: dir_watch.h:61
EType type
Definition: dir_watch.h:81
LIB_API Status dir_watch_Add(const OsPath &path, PDirWatch &dirWatch)
start watching a single directory for changes.
Definition: dir_watch.cpp:28
DirWatchNotification(const OsPath &pathname, EType type)
Definition: dir_watch.h:64
OsPath path
Definition: dir_watch_inotify.cpp:78
shared_ptr< DirWatch > PDirWatch
Definition: dir_watch.h:32
Definition: path.h:77
EType Type() const
Definition: dir_watch.h:74
LIB_API Status dir_watch_Poll(DirWatchNotifications &notifications)
return all pending directory watch notifications.
Definition: dir_watch.cpp:33
Definition: dir_watch.h:60
i64 Status
Error handling system.
Definition: status.h:171
Definition: dir_watch.h:54
OsPath pathname
Definition: dir_watch.h:80
Definition: dir_watch.h:59
Definition: dir_watch_inotify.cpp:65