]> git.saurik.com Git - wxWidgets.git/blob - include/wx/unix/private/fswatcher_kqueue.h
Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / include / wx / unix / private / fswatcher_kqueue.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/unix/private/fswatcher_kqueue.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_UNIX_PRIVATE_FSWATCHER_KQUEUE_H_
11 #define WX_UNIX_PRIVATE_FSWATCHER_KQUEUE_H_
12
13 #include <fcntl.h>
14 #include <unistd.h>
15 #include "wx/dir.h"
16 #include "wx/debug.h"
17 #include "wx/arrstr.h"
18
19 // ============================================================================
20 // wxFSWatcherEntry implementation & helper declarations
21 // ============================================================================
22
23 class wxFSWatcherImplKqueue;
24
25 class wxFSWatchEntryKq : public wxFSWatchInfo
26 {
27 public:
28 struct wxDirState
29 {
30 wxDirState(const wxFSWatchInfo& winfo)
31 {
32 if (!wxDir::Exists(winfo.GetPath()))
33 return;
34
35 wxDir dir(winfo.GetPath());
36 wxCHECK_RET( dir.IsOpened(),
37 wxString::Format("Unable to open dir '%s'", winfo.GetPath()));
38
39 wxString filename;
40 bool ret = dir.GetFirst(&filename);
41 while (ret)
42 {
43 files.push_back(filename);
44 ret = dir.GetNext(&filename);
45 }
46 }
47
48 wxSortedArrayString files;
49 };
50
51 wxFSWatchEntryKq(const wxFSWatchInfo& winfo) :
52 wxFSWatchInfo(winfo), m_lastState(winfo)
53 {
54 m_fd = wxOpen(m_path, O_RDONLY, 0);
55 if (m_fd == -1)
56 {
57 wxLogSysError(_("Unable to open path '%s'"), m_path);
58 }
59 }
60
61 virtual ~wxFSWatchEntryKq()
62 {
63 (void) Close();
64 }
65
66 bool Close()
67 {
68 if (!IsOk())
69 return false;
70
71 int ret = close(m_fd);
72 if (ret == -1)
73 {
74 wxLogSysError(_("Unable to close path '%s'"), m_path);
75 }
76 m_fd = -1;
77
78 return ret != -1;
79 }
80
81 bool IsOk() const
82 {
83 return m_fd != -1;
84 }
85
86 int GetFileDescriptor() const
87 {
88 return m_fd;
89 }
90
91 void RefreshState()
92 {
93 m_lastState = wxDirState(*this);
94 }
95
96 const wxDirState& GetLastState() const
97 {
98 return m_lastState;
99 }
100
101 private:
102 int m_fd;
103 wxDirState m_lastState;
104
105 wxDECLARE_NO_COPY_CLASS(wxFSWatchEntryKq);
106 };
107
108 #endif /* WX_UNIX_PRIVATE_FSWATCHER_KQUEUE_H_ */