]> git.saurik.com Git - wxWidgets.git/blob - include/wx/private/fswatcher.h
Added wxThread::OnKill() and OnDelete() callbacks.
[wxWidgets.git] / include / wx / private / fswatcher.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/fswatcher.h
3 // Purpose: File system watcher impl classes
4 // Author: Bartosz Bekier
5 // Created: 2009-05-26
6 // RCS-ID: $Id$
7 // Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef WX_PRIVATE_FSWATCHER_H_
12 #define WX_PRIVATE_FSWATCHER_H_
13
14 #include "wx/sharedptr.h"
15
16 #ifdef wxHAS_INOTIFY
17 class wxFSWatchEntryUnix;
18 #define wxFSWatchEntry wxFSWatchEntryUnix
19 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
20 #include "wx/unix/private/fswatcher_inotify.h"
21 #elif defined(wxHAS_KQUEUE)
22 class wxFSWatchEntryKq;
23 #define wxFSWatchEntry wxFSWatchEntryKq
24 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
25 #include "wx/unix/private/fswatcher_kqueue.h"
26 #elif defined(__WXMSW__)
27 class wxFSWatchEntryMSW;
28 #define wxFSWatchEntry wxFSWatchEntryMSW
29 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
30 #include "wx/msw/private/fswatcher.h"
31 #else
32 #define wxFSWatchEntry wxFSWatchEntryPolling
33 #endif
34
35 class wxFSWatcherImpl
36 {
37 public:
38 wxFSWatcherImpl(wxFileSystemWatcherBase* watcher) :
39 m_watcher(watcher)
40 {
41 }
42
43 virtual ~wxFSWatcherImpl()
44 {
45 (void) RemoveAll();
46 }
47
48 virtual bool Init() = 0;
49
50 virtual bool Add(const wxFSWatchInfo& winfo)
51 {
52 wxCHECK_MSG( m_watches.find(winfo.GetPath()) == m_watches.end(), false,
53 "Path '%s' is already watched");
54
55 // construct watch entry
56 wxSharedPtr<wxFSWatchEntry> watch(new wxFSWatchEntry(winfo));
57
58 if (!DoAdd(watch))
59 return false;
60
61 // add watch to our map (always succeedes, checked above)
62 wxFSWatchEntries::value_type val(watch->GetPath(), watch);
63 return m_watches.insert(val).second;
64 }
65
66 virtual bool Remove(const wxFSWatchInfo& winfo)
67 {
68 wxFSWatchEntries::iterator it = m_watches.find(winfo.GetPath());
69 wxCHECK_MSG( it != m_watches.end(), false, "Path '%s' is not watched");
70
71 wxSharedPtr<wxFSWatchEntry> watch = it->second;
72 m_watches.erase(it);
73 return DoRemove(watch);
74 }
75
76 virtual bool RemoveAll()
77 {
78 m_watches.clear();
79 return true;
80 }
81
82 protected:
83 virtual bool DoAdd(wxSharedPtr<wxFSWatchEntry> watch) = 0;
84
85 virtual bool DoRemove(wxSharedPtr<wxFSWatchEntry> watch) = 0;
86
87 wxFSWatchEntries m_watches;
88 wxFileSystemWatcherBase* m_watcher;
89 };
90
91
92 #endif /* WX_PRIVATE_FSWATCHER_H_ */