]>
Commit | Line | Data |
---|---|---|
b46b1d59 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: wx/private/fdiodispatcher.h | |
3 | // Purpose: classes for dispatching IO notifications for file descriptors | |
4 | // Authors: Lukasz Michalski | |
5 | // Created: December 2006 | |
6 | // Copyright: (c) Lukasz Michalski | |
7 | // RCS-ID: $Id$ | |
8 | // Licence: wxWindows licence | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | #ifndef _WX_PRIVATE_FDIODISPATCHER_H_ | |
12 | #define _WX_PRIVATE_FDIODISPATCHER_H_ | |
13 | ||
14 | #include "wx/hashmap.h" | |
15 | ||
16 | // handler used to process events on descriptors | |
17 | class wxFDIOHandler | |
18 | { | |
19 | public: | |
20 | // called when descriptor is available for non-blocking read | |
21 | virtual void OnReadWaiting() = 0; | |
22 | ||
23 | // called when descriptor is available for non-blocking write | |
24 | virtual void OnWriteWaiting() = 0; | |
25 | ||
26 | // called when there is exception on descriptor | |
27 | virtual void OnExceptionWaiting() = 0; | |
28 | ||
29 | // virtual dtor for the base class | |
30 | virtual ~wxFDIOHandler() { } | |
31 | }; | |
32 | ||
33 | // those flags describes sets where descriptor should be added | |
34 | enum wxFDIODispatcherEntryFlags | |
35 | { | |
36 | wxFDIO_INPUT = 1, | |
37 | wxFDIO_OUTPUT = 2, | |
38 | wxFDIO_EXCEPTION = 4, | |
39 | wxFDIO_ALL = wxFDIO_INPUT | wxFDIO_OUTPUT | wxFDIO_EXCEPTION | |
40 | }; | |
41 | ||
ad8d42f8 VZ |
42 | // base class for wxSelectDispatcher and wxEpollDispatcher |
43 | class WXDLLIMPEXP_BASE wxFDIODispatcher | |
44 | { | |
45 | public: | |
46 | enum { TIMEOUT_INFINITE = -1 }; | |
47 | ||
48 | // register handler for the given descriptor with the dispatcher, return | |
49 | // true on success or false on error | |
50 | virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags) = 0; | |
51 | ||
52 | // modify descriptor flags or handler, return true on success | |
53 | virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags) = 0; | |
54 | ||
55 | // unregister descriptor previously registered with RegisterFD(), the | |
56 | // caller is responsible for deleting the returned handler pointer if | |
57 | // necessary | |
58 | virtual bool UnregisterFD(int fd, int flags) = 0; | |
59 | ||
60 | // loops waiting for an event to happen on any of the descriptors | |
61 | virtual void RunLoop(int timeout) = 0; | |
62 | ||
63 | virtual ~wxFDIODispatcher() { } | |
64 | }; | |
65 | ||
66 | //entry for wxFDIOHandlerMap | |
b46b1d59 VZ |
67 | struct wxFDIOHandlerEntry |
68 | { | |
69 | wxFDIOHandlerEntry() | |
70 | { | |
71 | } | |
72 | ||
73 | wxFDIOHandlerEntry(wxFDIOHandler *handler_, int flags_) | |
74 | : handler(handler_), | |
75 | flags(flags_) | |
76 | { | |
77 | } | |
78 | ||
79 | wxFDIOHandler *handler; | |
80 | int flags; | |
81 | }; | |
82 | ||
83 | // this hash is used to map file descriptors to their handlers | |
84 | WX_DECLARE_HASH_MAP( | |
85 | int, | |
86 | wxFDIOHandlerEntry, | |
87 | wxIntegerHash, | |
88 | wxIntegerEqual, | |
89 | wxFDIOHandlerMap | |
90 | ); | |
91 | ||
ad8d42f8 VZ |
92 | // FDIODispatcher that holds map fd <-> FDIOHandler, this should be used if |
93 | // this map isn't maintained elsewhere already as it is usually needed anyhow | |
b46b1d59 | 94 | // |
ad8d42f8 | 95 | // notice that all functions for FD management have implementation |
b46b1d59 | 96 | // in the base class and should be called from the derived classes |
ad8d42f8 | 97 | class WXDLLIMPEXP_BASE wxMappedFDIODispatcher : public wxFDIODispatcher { |
b46b1d59 | 98 | public: |
b46b1d59 VZ |
99 | // find the handler for the given fd, return NULL if none |
100 | wxFDIOHandler *FindHandler(int fd) const; | |
b46b1d59 VZ |
101 | // register handler for the given descriptor with the dispatcher, return |
102 | // true on success or false on error | |
ad8d42f8 | 103 | virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags); |
b46b1d59 VZ |
104 | |
105 | // modify descriptor flags or handler, return true on success | |
ad8d42f8 | 106 | virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags); |
b46b1d59 VZ |
107 | |
108 | // unregister descriptor previously registered with RegisterFD(), the | |
109 | // caller is responsible for deleting the returned handler pointer if | |
110 | // necessary | |
ad8d42f8 | 111 | virtual bool UnregisterFD(int fd, int flags); |
b46b1d59 | 112 | |
ad8d42f8 | 113 | virtual ~wxMappedFDIODispatcher() { } |
b46b1d59 VZ |
114 | |
115 | protected: | |
116 | // the fd -> handler map containing all the registered handlers | |
117 | wxFDIOHandlerMap m_handlers; | |
118 | }; | |
119 | ||
120 | #endif // _WX_PRIVATE_FDIODISPATCHER_H_ |