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 wxCHECK_MSG( m_watches
.find(winfo
.GetPath()) == m_watches
.end(), false,
53 "Path '%s' is already watched");
55 // construct watch entry
56 wxSharedPtr
<wxFSWatchEntry
> watch(new wxFSWatchEntry(winfo
));
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
;
66 virtual bool Remove(const wxFSWatchInfo
& winfo
)
68 wxFSWatchEntries::iterator it
= m_watches
.find(winfo
.GetPath());
69 wxCHECK_MSG( it
!= m_watches
.end(), false, "Path '%s' is not watched");
71 wxSharedPtr
<wxFSWatchEntry
> watch
= it
->second
;
73 return DoRemove(watch
);
76 virtual bool RemoveAll()
83 virtual bool DoAdd(wxSharedPtr
<wxFSWatchEntry
> watch
) = 0;
85 virtual bool DoRemove(wxSharedPtr
<wxFSWatchEntry
> watch
) = 0;
87 wxFSWatchEntries m_watches
;
88 wxFileSystemWatcherBase
* m_watcher
;
92 #endif /* WX_PRIVATE_FSWATCHER_H_ */