1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/selectdispatcher.h
3 // Purpose: wxSelectDispatcher class
4 // Authors: Lukasz Michalski
6 // Created: December 2006
7 // Copyright: (c) Lukasz Michalski
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PRIVATE_SELECTDISPATCHER_H_
13 #define _WX_PRIVATE_SELECTDISPATCHER_H_
17 #include "wx/hashmap.h"
19 static const int wxSELECT_TIMEOUT_INFINITE
= -1;
21 // handler used to process events on descriptors
25 // called when descriptor is available for non-blocking read
26 virtual void OnReadWaiting(int fd
) = 0;
28 // called when descriptor is available for non-blocking write
29 virtual void OnWriteWaiting(int fd
) = 0;
31 // called when there is exception on descriptor
32 virtual void OnExceptionWaiting(int fd
) = 0;
34 // virtual dtor for the base class
35 virtual ~wxFDIOHandler() { }
38 // those flags describes sets where descriptor should be added
39 enum wxSelectDispatcherEntryFlags
43 wxSelectException
= 4,
44 wxSelectAll
= wxSelectInput
| wxSelectOutput
| wxSelectException
55 class WXDLLIMPEXP_CORE wxSelectDispatcher
58 // returns instance of the table
59 static wxSelectDispatcher
& Get();
61 virtual ~wxSelectDispatcher()
65 // register descriptor in sets.
66 void RegisterFD(int fd
, wxFDIOHandler
* handler
, int flags
= wxSelectAll
);
68 // unregister descriptor from sets and return handler for cleanup
69 wxFDIOHandler
* UnregisterFD(int fd
, int flags
= wxSelectAll
);
71 // return handler for descriptor or null if fd is not registered
72 wxFDIOHandler
* FindHandler(int fd
);
74 // calls select on registered descriptors and
75 void RunLoop(int timeout
= wxSELECT_TIMEOUT_INFINITE
);
78 wxSelectDispatcher() { m_maxFD
= -1; }
81 void ProcessSets(fd_set
* readset
, fd_set
* writeset
, fd_set
* exeptset
, int max_fd
);
88 wxFDIOHandlerMap m_handlers
;
90 static wxSelectDispatcher
*ms_instance
;
92 friend class wxSelectDispatcherModule
;
96 #endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_