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