Debian Codegraph @

CodeLite/clFileSystemWatcher.h

raw
1 #ifndef CLFILESYSTEMWATCHER_H
2 #define CLFILESYSTEMWATCHER_H
3
4 #include "codelite_exports.h"
5 #include "clFileSystemEvent.h"
6 #include <map>
7 #include <wx/timer.h>
8 #include <wx/filename.h>
9
10 #ifdef __WXMSW__
11 #define CL_FSW_USE_TIMER 1
12 #else
13 #define CL_FSW_USE_TIMER 1
14 #endif
15
16 #if !CL_FSW_USE_TIMER
17 #include <wx/fswatcher.h>
18 #endif
19
20 class WXDLLIMPEXP_CL clFileSystemWatcher : public wxEvtHandler
21 {
22 public:
23 struct File {
24 wxFileName filename;
25 time_t lastModified;
26 size_t file_size;
27 typedef std::map<wxString, File> Map_t;
28 };
29
30 wxEvtHandler* m_owner;
31 #if CL_FSW_USE_TIMER
32 clFileSystemWatcher::File::Map_t m_files;
33 wxTimer* m_timer;
34 #else
35 wxFileSystemWatcher m_watcher;
36 wxFileName m_watchedFile;
37 #endif
38
39 public:
40 typedef wxSharedPtr<clFileSystemWatcher> Ptr_t;
41
42 protected:
43 #if CL_FSW_USE_TIMER
44 void OnTimer(wxTimerEvent& event);
45 #else
46 void OnFileModified(wxFileSystemWatcherEvent& event);
47 #endif
48
49 public:
50 clFileSystemWatcher();
51 virtual ~clFileSystemWatcher();
52
53 void SetOwner(wxEvtHandler* owner) { this->m_owner = owner; }
54 wxEvtHandler* GetOwner() { return m_owner; }
55
56 /**
57 * @brief add a file to watch
58 */
59 void SetFile(const wxFileName& filename);
60
61 /**
62 * @brief remove file from the watch list
63 */
64 void RemoveFile(const wxFileName& filename);
65
66 /**
67 * @brief start to watching list of files.
68 * This object fires the following events (clFileSystemEvent):
69 * wxEVT_FILE_MODIFIED, wxEVT_FILE_DELETED
70 */
71 void Start();
72
73 /**
74 * @brief stop watching the list of files
75 */
76 void Stop();
77
78 /**
79 * @brief clear the list of files to watch and stop the watcher
80 */
81 void Clear();
82
83 /**
84 * @brief is the watcher running?
85 */
86 bool IsRunning() const;
87 };
88
89 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_FILE_MODIFIED, clFileSystemEvent);
90 wxDECLARE_EXPORTED_EVENT(WXDLLIMPEXP_CL, wxEVT_FILE_NOT_FOUND, clFileSystemEvent);
91
92 #endif // CLFILESYSTEMWATCHER_H