OpenClonk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros
C4FileMonitor.h
Go to the documentation of this file.
1 /*
2  * OpenClonk, http://www.openclonk.org
3  *
4  * Copyright (c) 2008-2009, RedWolf Design GmbH, http://www.clonk.de/
5  * Copyright (c) 2009-2016, The OpenClonk Team and contributors
6  *
7  * Distributed under the terms of the ISC license; see accompanying file
8  * "COPYING" for details.
9  *
10  * "Clonk" is a registered trademark of Matthes Bender, used with permission.
11  * See accompanying file "TRADEMARK" for details.
12  *
13  * To redistribute this file separately, substitute the full license texts
14  * for the above references.
15  */
16 
17 // An inotify wrapper
18 
19 #ifndef STD_FILE_MONITOR_H_INC
20 #define STD_FILE_MONITOR_H_INC
21 
22 #include "platform/StdScheduler.h"
24 #include <map>
25 
26 #ifdef __APPLE__
27 #import <CoreFoundation/CoreFoundation.h>
28 #import <CoreServices/CoreServices.h>
30 #endif
31 
33 #ifdef __APPLE__
34 , public ObjectiveCAssociated
35 #endif
36 {
37 
38 public:
39 
40  typedef void (*ChangeNotify)(const char *, const char *);
41 
42  C4FileMonitor(ChangeNotify pCallback);
44 
45  void StartMonitoring();
46  void AddDirectory(const char *szDir);
47 
48  // StdSchedulerProc:
49  virtual bool Execute(int iTimeout = -1, pollfd * = 0);
50 
51  // Signal for calling Execute()
52 #ifdef STDSCHEDULER_USE_EVENTS
53  virtual HANDLE GetEvent();
54 #else
55  virtual void GetFDs(std::vector<struct pollfd> & FDs);
56 #endif
57 
58  // C4InteractiveThread::Callback:
59  virtual void OnThreadEvent(C4InteractiveEventType eEvent, void *pEventData);
60 
61 private:
62 
63  bool fStarted;
64  ChangeNotify pCallback;
65 
66 #ifdef HAVE_SYS_INOTIFY_H
67  int fd;
68  std::map<int, const char *> watch_descriptors;
69 #elif defined(_WIN32)
70 
71  HANDLE hEvent;
72 
73  struct TreeWatch
74  {
75  HANDLE hDir;
76  StdCopyStrBuf DirName;
77  OVERLAPPED ov;
78  char Buffer[1024];
79  TreeWatch *Next;
80  };
81  TreeWatch *pWatches;
82 
83  void HandleNotify(const char *szDir, const struct _FILE_NOTIFY_INFORMATION *pNotify);
84 #elif defined(__APPLE__)
85  FSEventStreamRef eventStream;
86  FSEventStreamContext context;
87  void StartStream();
88  void StopStream();
89 #endif
90 };
91 
92 #endif // STD_FILE_MONITOR_H_INC
void AddDirectory(const char *szDir)
void StartMonitoring()
virtual bool Execute(int iTimeout=-1, pollfd *=0)
C4InteractiveEventType
C4FileMonitor(ChangeNotify pCallback)
void(* ChangeNotify)(const char *, const char *)
Definition: C4FileMonitor.h:40
virtual void OnThreadEvent(C4InteractiveEventType eEvent, void *pEventData)
virtual void GetFDs(std::vector< struct pollfd > &FDs)