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