openclonk/src/platform/C4FileMonitor.h

92 lines
2.1 KiB
C
Raw Normal View History

2009-05-08 13:28:41 +00:00
/*
* OpenClonk, http://www.openclonk.org
*
* Copyright (c) 2008-2009, RedWolf Design GmbH, http://www.clonk.de/
2016-04-03 18:18:29 +00:00
* Copyright (c) 2009-2016, The OpenClonk Team and contributors
2009-05-08 13:28:41 +00:00
*
* Distributed under the terms of the ISC license; see accompanying file
* "COPYING" for details.
2009-05-08 13:28:41 +00:00
*
* "Clonk" is a registered trademark of Matthes Bender, used with permission.
* See accompanying file "TRADEMARK" for details.
2009-05-08 13:28:41 +00:00
*
* To redistribute this file separately, substitute the full license texts
* for the above references.
2009-05-08 13:28:41 +00:00
*/
// An inotify wrapper
#ifndef STD_FILE_MONITOR_H_INC
#define STD_FILE_MONITOR_H_INC
#include "network/C4InteractiveThread.h"
#include "platform/StdScheduler.h"
2009-05-08 13:28:41 +00:00
#ifdef __APPLE__
#import <CoreFoundation/CoreFoundation.h>
#import <CoreServices/CoreServices.h>
#import "platform/ObjectiveCAssociated.h"
#endif
class C4FileMonitor: public StdSchedulerProc, public C4InteractiveThread::Callback
#ifdef __APPLE__
, public ObjectiveCAssociated
#endif
{
2009-05-08 13:28:41 +00:00
public:
typedef void (*ChangeNotify)(const char *, const char *);
C4FileMonitor(ChangeNotify pCallback);
~C4FileMonitor() override;
2009-05-08 13:28:41 +00:00
void StartMonitoring();
void AddDirectory(const char *szDir);
// StdSchedulerProc:
bool Execute(int iTimeout = -1, pollfd * = nullptr) override;
2009-05-08 13:28:41 +00:00
// Signal for calling Execute()
#ifdef STDSCHEDULER_USE_EVENTS
HANDLE GetEvent() override;
2009-05-08 13:28:41 +00:00
#else
void GetFDs(std::vector<struct pollfd> & FDs) override;
2009-05-08 13:28:41 +00:00
#endif
// C4InteractiveThread::Callback:
void OnThreadEvent(C4InteractiveEventType eEvent, void *pEventData) override;
2009-05-08 13:28:41 +00:00
private:
bool fStarted;
ChangeNotify pCallback;
#ifdef HAVE_SYS_INOTIFY_H
2009-05-08 13:28:41 +00:00
int fd;
std::map<int, const char *> watch_descriptors;
#elif defined(_WIN32)
HANDLE hEvent;
struct TreeWatch
{
2009-05-08 13:28:41 +00:00
HANDLE hDir;
StdCopyStrBuf DirName;
OVERLAPPED ov;
char Buffer[1024];
TreeWatch *Next;
};
2009-05-08 13:28:41 +00:00
TreeWatch *pWatches;
void HandleNotify(const char *szDir, const struct _FILE_NOTIFY_INFORMATION *pNotify);
#elif defined(__APPLE__)
FSEventStreamRef eventStream;
FSEventStreamContext context;
void StartStream();
void StopStream();
2009-05-08 13:28:41 +00:00
#endif
};
#endif // STD_FILE_MONITOR_H_INC