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