]> git.saurik.com Git - wxWidgets.git/blob - include/wx/private/fswatcher.h
Update vc10 build file versions to 3.0.0.
[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 // Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #ifndef WX_PRIVATE_FSWATCHER_H_
11 #define WX_PRIVATE_FSWATCHER_H_
12
13 #include "wx/sharedptr.h"
14
15 #ifdef wxHAS_INOTIFY
16 class wxFSWatchEntryUnix;
17 #define wxFSWatchEntry wxFSWatchEntryUnix
18 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
19 #include "wx/unix/private/fswatcher_inotify.h"
20 #elif defined(wxHAS_KQUEUE)
21 class wxFSWatchEntryKq;
22 #define wxFSWatchEntry wxFSWatchEntryKq
23 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
24 #include "wx/unix/private/fswatcher_kqueue.h"
25 #elif defined(__WINDOWS__)
26 class wxFSWatchEntryMSW;
27 #define wxFSWatchEntry wxFSWatchEntryMSW
28 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr<wxFSWatchEntry>,wxFSWatchEntries);
29 #include "wx/msw/private/fswatcher.h"
30 #else
31 #define wxFSWatchEntry wxFSWatchEntryPolling
32 #endif
33
34 class wxFSWatcherImpl
35 {
36 public:
37 wxFSWatcherImpl(wxFileSystemWatcherBase* watcher) :
38 m_watcher(watcher)
39 {
40 }
41
42 virtual ~wxFSWatcherImpl()
43 {
44 (void) RemoveAll();
45 }
46
47 virtual bool Init() = 0;
48
49 virtual bool Add(const wxFSWatchInfo& winfo)
50 {
51 if ( m_watches.find(winfo.GetPath()) != m_watches.end() )
52 {
53 wxLogTrace(wxTRACE_FSWATCHER,
54 "Path '%s' is already watched", winfo.GetPath());
55 // This can happen if a dir is watched, then a parent tree added
56 return true;
57 }
58
59 // construct watch entry
60 wxSharedPtr<wxFSWatchEntry> watch(new wxFSWatchEntry(winfo));
61
62 if (!DoAdd(watch))
63 return false;
64
65 // add watch to our map (always succeedes, checked above)
66 wxFSWatchEntries::value_type val(watch->GetPath(), watch);
67 return m_watches.insert(val).second;
68 }
69
70 virtual bool Remove(const wxFSWatchInfo& winfo)
71 {
72 wxFSWatchEntries::iterator it = m_watches.find(winfo.GetPath());
73 if ( it == m_watches.end() )
74 {
75 wxLogTrace(wxTRACE_FSWATCHER,
76 "Path '%s' is not watched", winfo.GetPath());
77 // This can happen if a dir is watched, then a parent tree added
78 return true;
79 }
80 wxSharedPtr<wxFSWatchEntry> watch = it->second;
81 m_watches.erase(it);
82 return DoRemove(watch);
83 }
84
85 virtual bool RemoveAll()
86 {
87 m_watches.clear();
88 return true;
89 }
90
91 // Check whether any filespec matches the file's ext (if present)
92 bool MatchesFilespec(const wxFileName& fn, const wxString& filespec) const
93 {
94 return filespec.empty() || wxMatchWild(filespec, fn.GetFullName());
95 }
96
97 protected:
98 virtual bool DoAdd(wxSharedPtr<wxFSWatchEntry> watch) = 0;
99
100 virtual bool DoRemove(wxSharedPtr<wxFSWatchEntry> watch) = 0;
101
102 wxFSWatchEntries m_watches;
103 wxFileSystemWatcherBase* m_watcher;
104 };
105
106
107 #endif /* WX_PRIVATE_FSWATCHER_H_ */