Nebula
Loading...
Searching...
No Matches
filewatcher.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
11#include "core/types.h"
12#include "core/refcounted.h"
13#include "core/singleton.h"
14#include "core/ptr.h"
15#include "util/stringatom.h"
16#include "util/dictionary.h"
17#include "io/uri.h"
18#include "io/ioserver.h"
19#include "threading/thread.h"
20#include "threading/safequeue.h"
21#include <functional>
22#if __WIN32__
24#elif __linux__
26#else
27#error "not implemented"
28#endif
29
30//------------------------------------------------------------------------------
31namespace IO
32{
33
34//------------------------------------------------------------------------------
42
51
52//------------------------------------------------------------------------------
59using WatchDelegate = std::function<void(WatchEvent const&)>;
60
61//------------------------------------------------------------------------------
69
70//------------------------------------------------------------------------------
72{
75
76public:
80 virtual ~FileWatcher();
81
83 void Setup();
84
85 void SetSpeed(double speed);
86
88 void Watch(Util::StringAtom const& folder, bool recursive, WatchFlags flags, WatchDelegate const& callback);
90 void Unwatch(Util::StringAtom const& folder);
91
92private:
94 void Update();
96 void CheckQueue();
98 void DoWork();
99
103 double interval;
104
105};
106
107} // namespace IO
For registering callbacks for file modification events.
Definition filewatcher.h:72
Util::Dictionary< Util::StringAtom, EventHandlerData > watchers
Definition filewatcher.h:101
double interval
Definition filewatcher.h:103
Ptr< IO::IoServer > ioServer
Definition filewatcher.h:100
virtual ~FileWatcher()
destructor
Definition filewatcher.cc:28
FileWatcher()
constructor
Definition filewatcher.cc:19
void DoWork()
Definition filewatcher.cc:122
__DeclareInterfaceSingleton(FileWatcher)
void CheckQueue()
Definition filewatcher.cc:96
Threading::SafeQueue< EventHandlerData > watcherQueue
Definition filewatcher.h:102
__DeclareClass(FileWatcher)
void Unwatch(Util::StringAtom const &folder)
unregister
Definition filewatcher.cc:85
void Watch(Util::StringAtom const &folder, bool recursive, WatchFlags flags, WatchDelegate const &callback)
Register Folder.
Definition filewatcher.cc:74
void Setup()
starts watcher thread
Definition filewatcher.cc:49
void Update()
checks for file modifications and calls registered callbacks
Definition filewatcher.cc:62
void SetSpeed(double speed)
Definition filewatcher.cc:40
Nebula's smart pointer class which manages the life time of RefCounted objects.
Definition ptr.h:38
Thread-safe version of Util::Queue.
Definition safequeue.h:27
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:34
A StringAtom.
Definition stringatom.h:22
Instances of wrapped stream classes.
Definition orientation.cc:10
std::function< void(WatchEvent const &)> WatchDelegate
Definition filewatcher.h:59
WatchEventType
Definition filewatcher.h:36
@ Deleted
Definition filewatcher.h:38
@ Created
Definition filewatcher.h:37
@ NameChange
Definition filewatcher.h:39
@ Modified
Definition filewatcher.h:40
WatchFlags
Definition filewatcher.h:44
@ NameChanged
Definition filewatcher.h:45
@ Write
Definition filewatcher.h:47
@ Creation
Definition filewatcher.h:49
@ SizeChanged
Definition filewatcher.h:46
@ Access
Definition filewatcher.h:48
Definition filewatcher.h:63
FileWatcherPlatform data
Definition filewatcher.h:67
WatchFlags flags
Definition filewatcher.h:66
Util::StringAtom folder
Definition filewatcher.h:65
WatchDelegate callback
Definition filewatcher.h:64
Definition win32filewatcher.h:17
Definition filewatcher.h:54
Util::StringAtom folder
Definition filewatcher.h:56
WatchEventType type
Definition filewatcher.h:55
Util::String file
Definition filewatcher.h:57
Nebula's universal string class.
Definition string.h:50
#define N_BIT(x)
Definition types.h:59