]> git.saurik.com Git - wxWidgets.git/blob - include/wx/private/fdiodispatcher.h
restored accidentally commented-out code
[wxWidgets.git] / include / wx / private / fdiodispatcher.h
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
42 struct wxFDIOHandlerEntry
43 {
44 wxFDIOHandlerEntry()
45 {
46 }
47
48 wxFDIOHandlerEntry(wxFDIOHandler *handler_, int flags_)
49 : handler(handler_),
50 flags(flags_)
51 {
52 }
53
54 wxFDIOHandler *handler;
55 int flags;
56 };
57
58 // this hash is used to map file descriptors to their handlers
59 WX_DECLARE_HASH_MAP(
60 int,
61 wxFDIOHandlerEntry,
62 wxIntegerHash,
63 wxIntegerEqual,
64 wxFDIOHandlerMap
65 );
66
67 // base class for wxSelectDispatcher and wxEpollDispatcher
68 //
69 // notice that all pure virtual functions for FD management have implementation
70 // in the base class and should be called from the derived classes
71 class WXDLLIMPEXP_BASE wxFDIODispatcher
72 {
73 public:
74 enum { TIMEOUT_INFINITE = -1 };
75
76 // find the handler for the given fd, return NULL if none
77 wxFDIOHandler *FindHandler(int fd) const;
78
79 // register handler for the given descriptor with the dispatcher, return
80 // true on success or false on error
81 virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags) = 0;
82
83 // modify descriptor flags or handler, return true on success
84 virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags) = 0;
85
86 // unregister descriptor previously registered with RegisterFD(), the
87 // caller is responsible for deleting the returned handler pointer if
88 // necessary
89 virtual wxFDIOHandler *UnregisterFD(int fd, int flags) = 0;
90
91 // loops waiting for an event to happen on any of the descriptors
92 virtual void RunLoop(int timeout) = 0;
93
94 virtual ~wxFDIODispatcher() { }
95
96 protected:
97 // the fd -> handler map containing all the registered handlers
98 wxFDIOHandlerMap m_handlers;
99 };
100
101 #endif // _WX_PRIVATE_FDIODISPATCHER_H_