1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/fswatcher.h
3 // Purpose: File system watcher impl classes
4 // Author: Bartosz Bekier
6 // Copyright: (c) 2009 Bartosz Bekier <bartosz.bekier@gmail.com>
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #ifndef WX_PRIVATE_FSWATCHER_H_
11 #define WX_PRIVATE_FSWATCHER_H_
13 #include "wx/sharedptr.h"
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"
31 #define wxFSWatchEntry wxFSWatchEntryPolling
37 wxFSWatcherImpl(wxFileSystemWatcherBase
* watcher
) :
42 virtual ~wxFSWatcherImpl()
47 virtual bool Init() = 0;
49 virtual bool Add(const wxFSWatchInfo
& winfo
)
51 if ( m_watches
.find(winfo
.GetPath()) != m_watches
.end() )
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
59 // construct watch entry
60 wxSharedPtr
<wxFSWatchEntry
> watch(new wxFSWatchEntry(winfo
));
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
;
70 virtual bool Remove(const wxFSWatchInfo
& winfo
)
72 wxFSWatchEntries::iterator it
= m_watches
.find(winfo
.GetPath());
73 if ( it
== m_watches
.end() )
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
80 wxSharedPtr
<wxFSWatchEntry
> watch
= it
->second
;
82 return DoRemove(watch
);
85 virtual bool RemoveAll()
91 // Check whether any filespec matches the file's ext (if present)
92 bool MatchesFilespec(const wxFileName
& fn
, const wxString
& filespec
) const
94 return filespec
.empty() || wxMatchWild(filespec
, fn
.GetFullName());
98 virtual bool DoAdd(wxSharedPtr
<wxFSWatchEntry
> watch
) = 0;
100 virtual bool DoRemove(wxSharedPtr
<wxFSWatchEntry
> watch
) = 0;
102 wxFSWatchEntries m_watches
;
103 wxFileSystemWatcherBase
* m_watcher
;
107 #endif /* WX_PRIVATE_FSWATCHER_H_ */