make wxFDIOHandler dtor virtual, it's meant to be used as a base class
[wxWidgets.git] / include / wx / private / selectdispatcher.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/selectdispatcher.h
3 // Purpose: wxSelectDispatcher class
4 // Authors: Lukasz Michalski
5 // Modified by:
6 // Created: December 2006
7 // Copyright: (c) Lukasz Michalski
8 // RCS-ID: $Id$
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PRIVATE_SELECTDISPATCHER_H_
13 #define _WX_PRIVATE_SELECTDISPATCHER_H_
14
15 #include "wx/defs.h"
16
17 #include "wx/hashmap.h"
18
19 static const int wxSELECT_TIMEOUT_INFINITE = -1;
20
21 // handler used to process events on descriptors
22 class wxFDIOHandler
23 {
24 public:
25 // called when descriptor is available for non-blocking read
26 virtual void OnReadWaiting(int fd) = 0;
27
28 // called when descriptor is available for non-blocking write
29 virtual void OnWriteWaiting(int fd) = 0;
30
31 // called when there is exception on descriptor
32 virtual void OnExceptionWaiting(int fd) = 0;
33
34 // virtual dtor for the base class
35 virtual ~wxFDIOHandler() { }
36 };
37
38 // those flags describes sets where descriptor should be added
39 enum wxSelectDispatcherEntryFlags
40 {
41 wxSelectInput = 1,
42 wxSelectOutput = 2,
43 wxSelectException = 4,
44 wxSelectAll = wxSelectInput | wxSelectOutput | wxSelectException
45 };
46
47 WX_DECLARE_HASH_MAP(
48 int,
49 wxFDIOHandler*,
50 wxIntegerHash,
51 wxIntegerEqual,
52 wxFDIOHandlerMap
53 );
54
55 class WXDLLIMPEXP_CORE wxSelectDispatcher
56 {
57 public:
58 // returns instance of the table
59 static wxSelectDispatcher& Get();
60
61 virtual ~wxSelectDispatcher()
62 {
63 }
64
65 // register descriptor in sets.
66 void RegisterFD(int fd, wxFDIOHandler* handler, int flags = wxSelectAll);
67
68 // unregister descriptor from sets and return handler for cleanup
69 wxFDIOHandler* UnregisterFD(int fd, int flags = wxSelectAll);
70
71 // return handler for descriptor or null if fd is not registered
72 wxFDIOHandler* FindHandler(int fd);
73
74 // calls select on registered descriptors and
75 void RunLoop(int timeout = wxSELECT_TIMEOUT_INFINITE);
76
77 protected:
78 wxSelectDispatcher() { }
79
80 private:
81 void ProcessSets(fd_set* readset, fd_set* writeset, fd_set* exeptset, int max_fd);
82
83 fd_set m_readset;
84 fd_set m_writeset;
85 fd_set m_exeptset;
86
87 int m_maxFD;
88 wxFDIOHandlerMap m_handlers;
89
90 static wxSelectDispatcher *ms_instance;
91
92 friend class wxSelectDispatcherModule;
93 };
94
95
96 #endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_