Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
dir_watch.cpp File Reference
#include "precompiled.h"
#include "lib/sysdep/dir_watch.h"
#include "lib/file/file_system.h"
#include "osx_sys_version.h"
#include "lib/os_path.h"
#include "lib/file/file.h"
#include "lib/posix/posix_filesystem.h"
#include "ps/CLogger.h"
#include <AvailabilityMacros.h>
#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <vector>
Include dependency graph for dir_watch.cpp:

Classes

struct  DirWatch
 

Macros

#define kFSEventStreamCreateFlagFileEvents   0x00000010
 
#define kFSEventStreamEventFlagItemIsFile   0x00010000
 
#define kFSEventStreamEventFlagItemRemoved   0x00000200
 
#define kFSEventStreamEventFlagItemRenamed   0x00000800
 
#define kFSEventStreamEventFlagItemCreated   0x00000100
 
#define kFSEventStreamEventFlagItemModified   0x00001000
 

Typedefs

typedef std::vector< DirWatchDirWatchMap
 

Functions

static bool CanRunNotifications ()
 
static void fsevent_callback (ConstFSEventStreamRef streamRef, void *clientCallBackInfo, size_t numEvents, void *eventPaths, const FSEventStreamEventFlags eventFlags[], const FSEventStreamEventId eventIds[])
 
static FSEventStreamRef CreateEventStream (DirWatchMap path)
 
static void DeleteEventStream ()
 
Status dir_watch_Add (const OsPath &path, PDirWatch &dirWatch)
 start watching a single directory for changes. More...
 
Status dir_watch_Poll (DirWatchNotifications &notifications)
 return all pending directory watch notifications. More...
 

Variables

static FSEventStreamRef g_Stream = NULL
 
static DirWatchMap g_Paths
 
static DirWatchMap g_RootPaths
 
static DirWatchNotifications g_QueuedDirs
 

Macro Definition Documentation

◆ kFSEventStreamCreateFlagFileEvents

#define kFSEventStreamCreateFlagFileEvents   0x00000010

◆ kFSEventStreamEventFlagItemCreated

#define kFSEventStreamEventFlagItemCreated   0x00000100

◆ kFSEventStreamEventFlagItemIsFile

#define kFSEventStreamEventFlagItemIsFile   0x00010000

◆ kFSEventStreamEventFlagItemModified

#define kFSEventStreamEventFlagItemModified   0x00001000

◆ kFSEventStreamEventFlagItemRemoved

#define kFSEventStreamEventFlagItemRemoved   0x00000200

◆ kFSEventStreamEventFlagItemRenamed

#define kFSEventStreamEventFlagItemRenamed   0x00000800

Typedef Documentation

◆ DirWatchMap

typedef std::vector<DirWatch> DirWatchMap

Function Documentation

◆ CanRunNotifications()

static bool CanRunNotifications ( )
static

◆ CreateEventStream()

static FSEventStreamRef CreateEventStream ( DirWatchMap  path)
static

◆ DeleteEventStream()

static void DeleteEventStream ( )
static

◆ dir_watch_Add()

Status dir_watch_Add ( const OsPath path,
PDirWatch dirWatch 
)

start watching a single directory for changes.

Parameters
path(must end in slash)
dirWatchopaque smart pointer to the watch state; used to manage its lifetime (this is deemed more convenient than a separate dir_watch_Remove interface).

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.

◆ dir_watch_Poll()

Status dir_watch_Poll ( DirWatchNotifications notifications)

return all pending directory watch notifications.

Parameters
notificationsreceives any pending notifications in unspecified order.
Returns
Status (INFO::OK doesn't imply notifications were returned)

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.

◆ fsevent_callback()

static void fsevent_callback ( ConstFSEventStreamRef  streamRef,
void *  clientCallBackInfo,
size_t  numEvents,
void *  eventPaths,
const FSEventStreamEventFlags  eventFlags[],
const FSEventStreamEventId  eventIds[] 
)
static

Variable Documentation

◆ g_Paths

DirWatchMap g_Paths
static

◆ g_QueuedDirs

DirWatchNotifications g_QueuedDirs
static

◆ g_RootPaths

DirWatchMap g_RootPaths
static

◆ g_Stream

FSEventStreamRef g_Stream = NULL
static