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
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PRIVATE_SELECTDISPATCHER_H_
12 #define _WX_PRIVATE_SELECTDISPATCHER_H_
16 #if wxUSE_SELECT_DISPATCHER
20 #include <sys/ioctl.h>
22 #include <sys/select.h>
25 #include <sys/types.h>
28 #include "wx/private/fdiodispatcher.h"
30 // helper class storing all the select() fd sets
31 class WXDLLIMPEXP_BASE wxSelectSets
34 // ctor zeroes out all fd_sets
37 // default copy ctor, assignment operator and dtor are ok
40 // return true if fd appears in any of the sets
41 bool HasFD(int fd
) const;
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
);
47 // same as SetFD() except it unsets the bits set in the flags for the given
55 // call select() with our sets: the other parameters are the same as for
57 int Select(int nfds
, struct timeval
*tv
);
59 // call the handler methods corresponding to the sets having this fd
60 void Handle(int fd
, wxFDIOHandler
& handler
) const;
63 typedef void (wxFDIOHandler::*Callback
)();
65 // the FD sets indices
74 // the sets used with select()
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
];
84 class WXDLLIMPEXP_BASE wxSelectDispatcher
: public wxMappedFDIODispatcher
88 wxSelectDispatcher() { m_maxFD
= -1; }
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
);
93 virtual bool UnregisterFD(int fd
);
94 virtual void Dispatch(int timeout
= TIMEOUT_INFINITE
);
97 // common part of RegisterFD() and ModifyFD()
98 bool DoUpdateFDAndHandler(int fd
, wxFDIOHandler
*handler
, int flags
);
100 // call the handlers for the fds present in the given sets
101 void ProcessSets(const wxSelectSets
& sets
);
103 // helper of ProcessSets(): call the handler if its fd is in the set
104 void DoProcessFD(int fd
, const fd_set
& fds
, wxFDIOHandler
*handler
,
108 // the select sets containing all the registered fds
111 // the highest registered fd value or -1 if none
115 #endif // wxUSE_SELECT_DISPATCHER
117 #endif // _WX_PRIVATE_SOCKETEVTDISPATCH_H_