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