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
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PRIVATE_FDIODISPATCHER_H_
12 #define _WX_PRIVATE_FDIODISPATCHER_H_
14 #include "wx/hashmap.h"
16 // handler used to process events on descriptors
20 // called when descriptor is available for non-blocking read
21 virtual void OnReadWaiting() = 0;
23 // called when descriptor is available for non-blocking write
24 virtual void OnWriteWaiting() = 0;
26 // called when there is exception on descriptor
27 virtual void OnExceptionWaiting() = 0;
29 // virtual dtor for the base class
30 virtual ~wxFDIOHandler() { }
33 // those flags describes sets where descriptor should be added
34 enum wxFDIODispatcherEntryFlags
39 wxFDIO_ALL
= wxFDIO_INPUT
| wxFDIO_OUTPUT
| wxFDIO_EXCEPTION
42 // base class for wxSelectDispatcher and wxEpollDispatcher
43 class WXDLLIMPEXP_BASE wxFDIODispatcher
46 enum { TIMEOUT_INFINITE
= -1 };
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;
52 // modify descriptor flags or handler, return true on success
53 virtual bool ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
) = 0;
55 // unregister descriptor previously registered with RegisterFD()
56 virtual bool UnregisterFD(int fd
) = 0;
58 // loops waiting for an event to happen on any of the descriptors
59 virtual void RunLoop(int timeout
) = 0;
61 virtual ~wxFDIODispatcher() { }
64 //entry for wxFDIOHandlerMap
65 struct wxFDIOHandlerEntry
71 wxFDIOHandlerEntry(wxFDIOHandler
*handler_
, int flags_
)
77 wxFDIOHandler
*handler
;
81 // this hash is used to map file descriptors to their handlers
90 // FDIODispatcher that holds map fd <-> FDIOHandler, this should be used if
91 // this map isn't maintained elsewhere already as it is usually needed anyhow
93 // notice that all functions for FD management have implementation
94 // in the base class and should be called from the derived classes
95 class WXDLLIMPEXP_BASE wxMappedFDIODispatcher
: public wxFDIODispatcher
98 // find the handler for the given fd, return NULL if none
99 wxFDIOHandler
*FindHandler(int fd
) const;
101 // register handler for the given descriptor with the dispatcher, return
102 // true on success or false on error
103 virtual bool RegisterFD(int fd
, wxFDIOHandler
*handler
, int flags
);
105 // modify descriptor flags or handler, return true on success
106 virtual bool ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
);
108 // unregister descriptor previously registered with RegisterFD()
109 virtual bool UnregisterFD(int fd
);
111 virtual ~wxMappedFDIODispatcher() { }
114 // the fd -> handler map containing all the registered handlers
115 wxFDIOHandlerMap m_handlers
;
118 #endif // _WX_PRIVATE_FDIODISPATCHER_H_