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 // return the global dispatcher to be used for IO events, can be NULL only
49 // if wxSelectDispatcher wasn't compiled into the library at all as
50 // creating it never fails
52 // don't delete the returned pointer
53 static wxFDIODispatcher
*Get();
55 // if we have any registered handlers, check for any pending events to them
56 // and dispatch them -- this is used from wxX11 and wxDFB event loops
58 static void DispatchPending();
60 // register handler for the given descriptor with the dispatcher, return
61 // true on success or false on error
62 virtual bool RegisterFD(int fd
, wxFDIOHandler
*handler
, int flags
) = 0;
64 // modify descriptor flags or handler, return true on success
65 virtual bool ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
) = 0;
67 // unregister descriptor previously registered with RegisterFD()
68 virtual bool UnregisterFD(int fd
) = 0;
70 // wait for an event for at most timeout milliseconds and process it
71 virtual void Dispatch(int timeout
= TIMEOUT_INFINITE
) = 0;
73 virtual ~wxFDIODispatcher() { }
76 //entry for wxFDIOHandlerMap
77 struct wxFDIOHandlerEntry
83 wxFDIOHandlerEntry(wxFDIOHandler
*handler_
, int flags_
)
89 wxFDIOHandler
*handler
;
93 // this hash is used to map file descriptors to their handlers
102 // FDIODispatcher that holds map fd <-> FDIOHandler, this should be used if
103 // this map isn't maintained elsewhere already as it is usually needed anyhow
105 // notice that all functions for FD management have implementation
106 // in the base class and should be called from the derived classes
107 class WXDLLIMPEXP_BASE wxMappedFDIODispatcher
: public wxFDIODispatcher
110 // find the handler for the given fd, return NULL if none
111 wxFDIOHandler
*FindHandler(int fd
) const;
113 // register handler for the given descriptor with the dispatcher, return
114 // true on success or false on error
115 virtual bool RegisterFD(int fd
, wxFDIOHandler
*handler
, int flags
);
117 // modify descriptor flags or handler, return true on success
118 virtual bool ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
);
120 // unregister descriptor previously registered with RegisterFD()
121 virtual bool UnregisterFD(int fd
);
123 virtual ~wxMappedFDIODispatcher() { }
126 // the fd -> handler map containing all the registered handlers
127 wxFDIOHandlerMap m_handlers
;
130 #endif // _WX_PRIVATE_FDIODISPATCHER_H_