1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/fswatcher.h
3 // Purpose: File system watcher impl classes
4 // Author: Bartosz Bekier
7 // Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef WX_PRIVATE_FSWATCHER_H_
12 #define WX_PRIVATE_FSWATCHER_H_
14 #include "wx/sharedptr.h"
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(__WINDOWS__)
27 class wxFSWatchEntryMSW
;
28 #define wxFSWatchEntry wxFSWatchEntryMSW
29 WX_DECLARE_STRING_HASH_MAP(wxSharedPtr
<wxFSWatchEntry
>,wxFSWatchEntries
);
30 #include "wx/msw/private/fswatcher.h"
32 #define wxFSWatchEntry wxFSWatchEntryPolling
38 wxFSWatcherImpl(wxFileSystemWatcherBase
* watcher
) :
43 virtual ~wxFSWatcherImpl()
48 virtual bool Init() = 0;
50 virtual bool Add(const wxFSWatchInfo
& winfo
)
52 if ( m_watches
.find(winfo
.GetPath()) != m_watches
.end() )
54 wxLogTrace(wxTRACE_FSWATCHER
,
55 "Path '%s' is already watched", winfo
.GetPath());
56 // This can happen if a dir is watched, then a parent tree added
60 // construct watch entry
61 wxSharedPtr
<wxFSWatchEntry
> watch(new wxFSWatchEntry(winfo
));
66 // add watch to our map (always succeedes, checked above)
67 wxFSWatchEntries::value_type
val(watch
->GetPath(), watch
);
68 return m_watches
.insert(val
).second
;
71 virtual bool Remove(const wxFSWatchInfo
& winfo
)
73 wxFSWatchEntries::iterator it
= m_watches
.find(winfo
.GetPath());
74 if ( it
== m_watches
.end() )
76 wxLogTrace(wxTRACE_FSWATCHER
,
77 "Path '%s' is not watched", winfo
.GetPath());
78 // This can happen if a dir is watched, then a parent tree added
81 wxSharedPtr
<wxFSWatchEntry
> watch
= it
->second
;
83 return DoRemove(watch
);
86 virtual bool RemoveAll()
92 // Check whether any filespec matches the file's ext (if present)
93 bool MatchesFilespec(const wxFileName
& fn
, const wxString
& filespec
) const
95 return filespec
.empty() || wxMatchWild(filespec
, fn
.GetFullName());
99 virtual bool DoAdd(wxSharedPtr
<wxFSWatchEntry
> watch
) = 0;
101 virtual bool DoRemove(wxSharedPtr
<wxFSWatchEntry
> watch
) = 0;
103 wxFSWatchEntries m_watches
;
104 wxFileSystemWatcherBase
* m_watcher
;
108 #endif /* WX_PRIVATE_FSWATCHER_H_ */