aboutsummaryrefslogtreecommitdiff
path: root/src/3rdParty/efsw/WatcherFSEvents.hpp
blob: 4dbb2316480ff1b332e1833ac2d9bc260896c294 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#ifndef EFSW_WATCHERINOTIFY_HPP
#define EFSW_WATCHERINOTIFY_HPP

#include <efsw/FileWatcherImpl.hpp>

#if EFSW_PLATFORM == EFSW_PLATFORM_FSEVENTS

#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>
#include <efsw/FileInfo.hpp>
#include <efsw/WatcherGeneric.hpp>
#include <set>
#include <vector>

namespace efsw {

class FileWatcherFSEvents;

class FSEvent {
  public:
	FSEvent( std::string path, long flags, Uint64 id ) : Path( path ), Flags( flags ), Id( id ) {}

	std::string Path;
	long Flags;
	Uint64 Id;
};

class WatcherFSEvents : public Watcher {
  public:
	WatcherFSEvents();

	WatcherFSEvents( WatchID id, std::string directory, FileWatchListener* listener, bool recursive,
					 WatcherFSEvents* parent = NULL );

	~WatcherFSEvents();

	void init();

	void initAsync();

	void handleActions( std::vector<FSEvent>& events );

	void process();

	Atomic<FileWatcherFSEvents*> FWatcher;
	FSEventStreamRef FSStream;

  protected:
	void handleAddModDel( const Uint32& flags, const std::string& path, std::string& dirPath,
						  std::string& filePath );

	WatcherGeneric* WatcherGen;

	Atomic<bool> initializedAsync;

	std::set<std::string> DirsChanged;

	void sendFileAction( WatchID watchid, const std::string& dir, const std::string& filename,
						 Action action, std::string oldFilename = "" );
};

} // namespace efsw

#endif

#endif