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/path.h"
19#include "io/ioserver.h"
20#include "threading/thread.h"
21#include "threading/safequeue.h"
22#include <functional>
23#include "util/bitfield.h"
24#if __WIN32__
26#elif __linux__
28#else
29#error "not implemented"
30#endif
31
32//------------------------------------------------------------------------------
33namespace IO
34{
35
36//------------------------------------------------------------------------------
44
53
54//------------------------------------------------------------------------------
62using WatchDelegate = std::function<void(WatchEvent const&)>;
63
64//------------------------------------------------------------------------------
72
73//------------------------------------------------------------------------------
74class FileWatcher : public Threading::Thread
75{
78
79public:
83 virtual ~FileWatcher();
84
86 void Setup();
87
88 void SetSpeed(double speed);
89
91 void Watch(Util::StringAtom const& folder, bool recursive, Util::BitField<8> flags, WatchDelegate const& callback);
93 void Unwatch(Util::StringAtom const& folder);
95 bool IsWatched(Util::StringAtom const& folder) const;
96
97private:
99 void Update();
101 void CheckQueue();
103 void DoWork();
104
108 double interval;
109
110};
111
112} // namespace IO
Util::Dictionary< Util::StringAtom, EventHandlerData > watchers
Definition filewatcher.h:106
double interval
Definition filewatcher.h:108
Ptr< IO::IoServer > ioServer
Definition filewatcher.h:105
void Watch(Util::StringAtom const &folder, bool recursive, Util::BitField< 8 > flags, WatchDelegate const &callback)
Register Folder.
Definition filewatcher.cc:74
FileWatcher()
constructor
Definition filewatcher.cc:19
bool IsWatched(Util::StringAtom const &folder) const
check if folder is watched
Definition filewatcher.cc:98
void DoWork()
Definition filewatcher.cc:136
__DeclareInterfaceSingleton(FileWatcher)
void CheckQueue()
Definition filewatcher.cc:107
Threading::SafeQueue< EventHandlerData > watcherQueue
Definition filewatcher.h:107
__DeclareClass(FileWatcher)
void Unwatch(Util::StringAtom const &folder)
unregister
Definition filewatcher.cc:86
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
Implements large bit field.
Definition bitfield.h:24
A collection of key/value pairs with quick value retrieval by key at roughly O(log n).
Definition dictionary.h:35
A StringAtom.
Definition stringatom.h:22
Nebula's universal string class.
Definition string.h:50
Instances of wrapped stream classes.
Definition multiplayerfeatureunit.cc:324
std::function< void(WatchEvent const &)> WatchDelegate
Definition filewatcher.h:62
WatchEventType
Definition filewatcher.h:38
@ Deleted
Definition filewatcher.h:40
@ Created
Definition filewatcher.h:39
@ NameChange
Definition filewatcher.h:41
@ Modified
Definition filewatcher.h:42
WatchFlags
Definition filewatcher.h:46
@ NameChanged
Definition filewatcher.h:47
@ Write
Definition filewatcher.h:49
@ Creation
Definition filewatcher.h:51
@ SizeChanged
Definition filewatcher.h:48
@ Access
Definition filewatcher.h:50
Definition filewatcher.h:66
FileWatcherPlatform data
Definition filewatcher.h:70
Util::BitField< 8 > flags
Definition filewatcher.h:69
Util::StringAtom folder
Definition filewatcher.h:68
WatchDelegate callback
Definition filewatcher.h:67
Definition linuxfilewatcher.h:19
Definition filewatcher.h:56
Util::String relativePath
Definition filewatcher.h:59
Util::StringAtom folder
Definition filewatcher.h:58
WatchEventType type
Definition filewatcher.h:57
Util::String file
Definition filewatcher.h:60