]> git.saurik.com Git - wxWidgets.git/blame - include/wx/private/selectdispatcher.h
Update vc10 build file versions to 3.0.0.
[wxWidgets.git] / include / wx / private / selectdispatcher.h
CommitLineData
30c45bdd
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/private/selectdispatcher.h
3// Purpose: wxSelectDispatcher class
b46b1d59 4// Authors: Lukasz Michalski and Vadim Zeitlin
30c45bdd
VZ
5// Created: December 2006
6// Copyright: (c) Lukasz Michalski
30c45bdd
VZ
7// Licence: wxWindows licence
8/////////////////////////////////////////////////////////////////////////////
9
10#ifndef _WX_PRIVATE_SELECTDISPATCHER_H_
11#define _WX_PRIVATE_SELECTDISPATCHER_H_
12
13#include "wx/defs.h"
14
a1873279
VZ
15#if wxUSE_SELECT_DISPATCHER
16
d1418268
VZ
17#if defined(HAVE_SYS_SELECT_H) || defined(__WATCOMC__)
18 #include <sys/time.h>
19 #include <sys/select.h>
20#endif
21
ddfed775 22#ifdef __WATCOMC__
d1418268
VZ
23 #include <types.h>
24 #include <sys/ioctl.h>
25 #include <tcpustd.h>
ddfed775 26#else
d1418268 27 #include <sys/types.h>
ddfed775 28#endif
c3938816 29
b46b1d59 30#include "wx/private/fdiodispatcher.h"
30c45bdd 31
b46b1d59
VZ
32// helper class storing all the select() fd sets
33class WXDLLIMPEXP_BASE wxSelectSets
30c45bdd
VZ
34{
35public:
b46b1d59
VZ
36 // ctor zeroes out all fd_sets
37 wxSelectSets();
30c45bdd 38
b46b1d59 39 // default copy ctor, assignment operator and dtor are ok
72fa3e8a 40
30c45bdd 41
b46b1d59
VZ
42 // return true if fd appears in any of the sets
43 bool HasFD(int fd) const;
30c45bdd 44
b46b1d59
VZ
45 // add or remove FD to our sets depending on whether flags contains
46 // wxFDIO_INPUT/OUTPUT/EXCEPTION bits
47 bool SetFD(int fd, int flags);
30c45bdd 48
b46b1d59
VZ
49 // same as SetFD() except it unsets the bits set in the flags for the given
50 // fd
af57c51a 51 bool ClearFD(int fd)
30c45bdd 52 {
af57c51a 53 return SetFD(fd, 0);
30c45bdd
VZ
54 }
55
30c45bdd 56
b46b1d59
VZ
57 // call select() with our sets: the other parameters are the same as for
58 // select() itself
59 int Select(int nfds, struct timeval *tv);
60
a12698ab
VZ
61 // call the handler methods corresponding to the sets having this fd if it
62 // is present in any set and return true if it is
63 bool Handle(int fd, wxFDIOHandler& handler) const;
b46b1d59
VZ
64
65private:
66 typedef void (wxFDIOHandler::*Callback)();
67
68 // the FD sets indices
69 enum
70 {
71 Read,
72 Write,
73 Except,
74 Max
75 };
76
77 // the sets used with select()
78 fd_set m_fds[Max];
79
80 // the wxFDIO_XXX flags, functions and names (used for debug messages only)
81 // corresponding to the FD sets above
82 static int ms_flags[Max];
83 static const char *ms_names[Max];
84 static Callback ms_handlers[Max];
85};
86
ad8d42f8 87class WXDLLIMPEXP_BASE wxSelectDispatcher : public wxMappedFDIODispatcher
b46b1d59
VZ
88{
89public:
fdf7ff73
VZ
90 // default ctor
91 wxSelectDispatcher() { m_maxFD = -1; }
30c45bdd 92
b46b1d59
VZ
93 // implement pure virtual methods of the base class
94 virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL);
95 virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL);
af57c51a 96 virtual bool UnregisterFD(int fd);
a12698ab
VZ
97 virtual bool HasPending() const;
98 virtual int Dispatch(int timeout = TIMEOUT_INFINITE);
30c45bdd 99
30c45bdd 100private:
b46b1d59
VZ
101 // common part of RegisterFD() and ModifyFD()
102 bool DoUpdateFDAndHandler(int fd, wxFDIOHandler *handler, int flags);
30c45bdd 103
a12698ab
VZ
104 // call the handlers for the fds present in the given sets, return the
105 // number of handlers we called
106 int ProcessSets(const wxSelectSets& sets);
30c45bdd 107
b46b1d59
VZ
108 // helper of ProcessSets(): call the handler if its fd is in the set
109 void DoProcessFD(int fd, const fd_set& fds, wxFDIOHandler *handler,
110 const char *name);
30c45bdd 111
a12698ab
VZ
112 // common part of HasPending() and Dispatch(): calls select() with the
113 // specified timeout
114 int DoSelect(wxSelectSets& sets, int timeout) const;
115
30c45bdd 116
b46b1d59
VZ
117 // the select sets containing all the registered fds
118 wxSelectSets m_sets;
119
120 // the highest registered fd value or -1 if none
121 int m_maxFD;
30c45bdd
VZ
122};
123
a1873279 124#endif // wxUSE_SELECT_DISPATCHER
30c45bdd
VZ
125
126#endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_