]> git.saurik.com Git - wxWidgets.git/blob - include/wx/private/selectdispatcher.h
Add a wxLog::DoCreateOnDemand and call it from DoCommonPreInit so that
[wxWidgets.git] / include / wx / private / selectdispatcher.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/private/selectdispatcher.h
3 // Purpose: wxSelectDispatcher class
4 // Authors: Lukasz Michalski and Vadim Zeitlin
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
16 #include "wx/private/fdiodispatcher.h"
17
18 // helper class storing all the select() fd sets
19 class WXDLLIMPEXP_BASE wxSelectSets
20 {
21 public:
22 // ctor zeroes out all fd_sets
23 wxSelectSets();
24
25 // default copy ctor, assignment operator and dtor are ok
26
27
28 // return true if fd appears in any of the sets
29 bool HasFD(int fd) const;
30
31 // add or remove FD to our sets depending on whether flags contains
32 // wxFDIO_INPUT/OUTPUT/EXCEPTION bits
33 bool SetFD(int fd, int flags);
34
35 // same as SetFD() except it unsets the bits set in the flags for the given
36 // fd
37 bool ClearFD(int fd, int flags)
38 {
39 return SetFD(fd, wxFDIO_ALL & ~flags);
40 }
41
42
43 // call select() with our sets: the other parameters are the same as for
44 // select() itself
45 int Select(int nfds, struct timeval *tv);
46
47 // call the handler methods corresponding to the sets having this fd
48 void Handle(int fd, wxFDIOHandler& handler) const;
49
50 private:
51 typedef void (wxFDIOHandler::*Callback)();
52
53 // the FD sets indices
54 enum
55 {
56 Read,
57 Write,
58 Except,
59 Max
60 };
61
62 // the sets used with select()
63 fd_set m_fds[Max];
64
65 // the wxFDIO_XXX flags, functions and names (used for debug messages only)
66 // corresponding to the FD sets above
67 static int ms_flags[Max];
68 static const char *ms_names[Max];
69 static Callback ms_handlers[Max];
70 };
71
72 class WXDLLIMPEXP_BASE wxSelectDispatcher : public wxFDIODispatcher
73 {
74 public:
75 // returns the unique instance of this class, the pointer shouldn't be
76 // deleted and is normally never NULL
77 static wxSelectDispatcher *Get();
78
79 // if we have any registered handlers, check for any pending events to them
80 // and dispatch them -- this is used from wxX11 and wxDFB event loops
81 // implementation
82 static void DispatchPending();
83
84 // implement pure virtual methods of the base class
85 virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL);
86 virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags = wxFDIO_ALL);
87 virtual wxFDIOHandler *UnregisterFD(int fd, int flags = wxFDIO_ALL);
88 virtual void RunLoop(int timeout = TIMEOUT_INFINITE);
89
90 protected:
91 wxSelectDispatcher();
92
93 private:
94 // common part of RegisterFD() and ModifyFD()
95 bool DoUpdateFDAndHandler(int fd, wxFDIOHandler *handler, int flags);
96
97 // call the handlers for the fds present in the given sets
98 void ProcessSets(const wxSelectSets& sets);
99
100 // helper of ProcessSets(): call the handler if its fd is in the set
101 void DoProcessFD(int fd, const fd_set& fds, wxFDIOHandler *handler,
102 const char *name);
103
104
105 // the select sets containing all the registered fds
106 wxSelectSets m_sets;
107
108 // the highest registered fd value or -1 if none
109 int m_maxFD;
110 };
111
112
113 #endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_