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;
35 // those flags describes sets where descriptor should be added
36 enum wxSelectDispatcherEntryFlags
40 wxSelectException
= 4,
41 wxSelectAll
= wxSelectInput
| wxSelectOutput
| wxSelectException
52 class WXDLLIMPEXP_CORE wxSelectDispatcher
55 // returns instance of the table
56 static wxSelectDispatcher
& Get();
58 virtual ~wxSelectDispatcher()
62 // register descriptor in sets.
63 void RegisterFD(int fd
, wxFDIOHandler
* handler
, int flags
= wxSelectAll
);
65 // unregister descriptor from sets and return handler for cleanup
66 wxFDIOHandler
* UnregisterFD(int fd
, int flags
= wxSelectAll
);
68 // return handler for descriptor or null if fd is not registered
69 wxFDIOHandler
* FindHandler(int fd
);
71 // calls select on registered descriptors and
72 void RunLoop(int timeout
= wxSELECT_TIMEOUT_INFINITE
);
75 wxSelectDispatcher() { }
78 void ProcessSets(fd_set
* readset
, fd_set
* writeset
, fd_set
* exeptset
, int max_fd
);
85 wxFDIOHandlerMap m_handlers
;
87 static wxSelectDispatcher
*ms_instance
;
89 friend class wxSelectDispatcherModule
;
93 #endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_