2010-02-08 17:23:39 +01:00
|
|
|
/* Copyright (c) 2010 Wildfire Games
|
2009-04-18 19:00:33 +02:00
|
|
|
*
|
2010-02-08 17:23:39 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2009-04-18 19:00:33 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
|
|
|
* portable directory change notification API.
|
2006-04-12 01:59:08 +02:00
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_DIR_WATCH
|
|
|
|
#define INCLUDED_DIR_WATCH
|
2004-07-31 21:55:36 +02:00
|
|
|
|
2011-03-21 18:53:13 +01:00
|
|
|
#include "lib/path_util.h"
|
|
|
|
|
2009-11-05 21:46:15 +01:00
|
|
|
struct DirWatch;
|
2008-08-09 21:22:13 +02:00
|
|
|
typedef shared_ptr<DirWatch> PDirWatch;
|
2004-07-31 21:55:36 +02:00
|
|
|
|
2008-08-09 21:22:13 +02:00
|
|
|
/**
|
|
|
|
* start watching a single directory for changes.
|
|
|
|
*
|
2009-11-05 21:46:15 +01:00
|
|
|
* @param path (must end in slash)
|
|
|
|
* @param dirWatch opaque smart pointer to the watch state; used to
|
|
|
|
* manage its lifetime (this is deemed more convenient than a
|
|
|
|
* separate dir_watch_Remove interface).
|
2008-08-09 21:22:13 +02:00
|
|
|
*
|
2009-11-05 21:46:15 +01:00
|
|
|
* clients typically want to watch entire directory subtrees (e.g. a mod),
|
|
|
|
* which is supported by Windows but not FAM. to reduce overhead, the
|
|
|
|
* Windows backend always watches subtrees, but portable clients should
|
|
|
|
* still add a watch for each subdirectory (the shared watch state is
|
|
|
|
* reference-counted).
|
|
|
|
* rationale: since the VFS has per-directory data structures, it is
|
|
|
|
* convenient to store PDirWatch there instead of creating a second
|
|
|
|
* tree structure here.
|
2008-08-09 21:22:13 +02:00
|
|
|
**/
|
2011-03-21 18:53:13 +01:00
|
|
|
LIB_API LibError dir_watch_Add(const NativePath& path, PDirWatch& dirWatch);
|
2008-08-09 21:22:13 +02:00
|
|
|
|
|
|
|
class DirWatchNotification
|
|
|
|
{
|
|
|
|
public:
|
2009-11-06 17:15:09 +01:00
|
|
|
enum EType
|
2008-08-09 21:22:13 +02:00
|
|
|
{
|
|
|
|
Created,
|
|
|
|
Deleted,
|
2008-12-17 17:32:46 +01:00
|
|
|
Changed
|
2008-08-09 21:22:13 +02:00
|
|
|
};
|
|
|
|
|
2011-03-21 18:53:13 +01:00
|
|
|
DirWatchNotification(const NativePath& pathname, EType type)
|
|
|
|
: pathname(pathname), type(type)
|
2008-08-09 21:22:13 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-21 18:53:13 +01:00
|
|
|
const NativePath& Pathname() const
|
2008-08-09 21:22:13 +02:00
|
|
|
{
|
2011-03-21 18:53:13 +01:00
|
|
|
return pathname;
|
2008-08-09 21:22:13 +02:00
|
|
|
}
|
2004-07-31 21:55:36 +02:00
|
|
|
|
2009-11-06 17:15:09 +01:00
|
|
|
EType Type() const
|
2008-08-09 21:22:13 +02:00
|
|
|
{
|
2011-03-21 18:53:13 +01:00
|
|
|
return type;
|
2008-08-09 21:22:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2011-03-21 18:53:13 +01:00
|
|
|
NativePath pathname;
|
|
|
|
EType type;
|
2008-08-09 21:22:13 +02:00
|
|
|
};
|
|
|
|
|
2009-11-05 21:46:15 +01:00
|
|
|
typedef std::vector<DirWatchNotification> DirWatchNotifications;
|
|
|
|
|
2008-08-09 21:22:13 +02:00
|
|
|
/**
|
2009-11-05 21:46:15 +01:00
|
|
|
* return all pending directory watch notifications.
|
2008-08-09 21:22:13 +02:00
|
|
|
*
|
2009-11-05 21:46:15 +01:00
|
|
|
* @param notifications receives any pending notifications in unspecified order.
|
|
|
|
* @return LibError (INFO::OK doesn't imply notifications were returned)
|
2008-08-09 21:22:13 +02:00
|
|
|
*
|
|
|
|
* note: the run time of this function is independent of the number of
|
|
|
|
* directory watches and number of files.
|
|
|
|
*
|
|
|
|
* rationale for a polling interface: users (e.g. the main game loop)
|
|
|
|
* typically want to receive change notifications at a single point,
|
|
|
|
* rather than deal with the complexity of asynchronous notifications.
|
|
|
|
**/
|
2009-11-05 21:46:15 +01:00
|
|
|
LIB_API LibError dir_watch_Poll(DirWatchNotifications& notifications);
|
2006-04-12 01:59:08 +02:00
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // #ifndef INCLUDED_DIR_WATCH
|