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"
15 #include "wx/private/fdiohandler.h"
17 // those flags describes sets where descriptor should be added
18 enum wxFDIODispatcherEntryFlags
23 wxFDIO_ALL
= wxFDIO_INPUT
| wxFDIO_OUTPUT
| wxFDIO_EXCEPTION
26 // base class for wxSelectDispatcher and wxEpollDispatcher
27 class WXDLLIMPEXP_BASE wxFDIODispatcher
30 enum { TIMEOUT_INFINITE
= -1 };
32 // return the global dispatcher to be used for IO events, can be NULL only
33 // if wxSelectDispatcher wasn't compiled into the library at all as
34 // creating it never fails
36 // don't delete the returned pointer
37 static wxFDIODispatcher
*Get();
39 // if we have any registered handlers, check for any pending events to them
40 // and dispatch them -- this is used from wxX11 and wxDFB event loops
42 static void DispatchPending();
44 // register handler for the given descriptor with the dispatcher, return
45 // true on success or false on error
46 virtual bool RegisterFD(int fd
, wxFDIOHandler
*handler
, int flags
) = 0;
48 // modify descriptor flags or handler, return true on success
49 virtual bool ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
) = 0;
51 // unregister descriptor previously registered with RegisterFD()
52 virtual bool UnregisterFD(int fd
) = 0;
54 // check if any events are currently available without dispatching them
55 virtual bool HasPending() const = 0;
57 // wait for an event for at most timeout milliseconds and process it;
58 // return the number of events processed (possibly 0 if timeout expired) or
59 // -1 if an error occurred
60 virtual int Dispatch(int timeout
= TIMEOUT_INFINITE
) = 0;
62 virtual ~wxFDIODispatcher() { }
65 //entry for wxFDIOHandlerMap
66 struct wxFDIOHandlerEntry
72 wxFDIOHandlerEntry(wxFDIOHandler
*handler_
, int flags_
)
78 wxFDIOHandler
*handler
;
82 // this hash is used to map file descriptors to their handlers
91 // FDIODispatcher that holds map fd <-> FDIOHandler, this should be used if
92 // this map isn't maintained elsewhere already as it is usually needed anyhow
94 // notice that all functions for FD management have implementation
95 // in the base class and should be called from the derived classes
96 class WXDLLIMPEXP_BASE wxMappedFDIODispatcher
: public wxFDIODispatcher
99 // find the handler for the given fd, return NULL if none
100 wxFDIOHandler
*FindHandler(int fd
) const;
102 // register handler for the given descriptor with the dispatcher, return
103 // true on success or false on error
104 virtual bool RegisterFD(int fd
, wxFDIOHandler
*handler
, int flags
);
106 // modify descriptor flags or handler, return true on success
107 virtual bool ModifyFD(int fd
, wxFDIOHandler
*handler
, int flags
);
109 // unregister descriptor previously registered with RegisterFD()
110 virtual bool UnregisterFD(int fd
);
112 virtual ~wxMappedFDIODispatcher() { }
115 // the fd -> handler map containing all the registered handlers
116 wxFDIOHandlerMap m_handlers
;
119 #endif // _WX_PRIVATE_FDIODISPATCHER_H_