]> git.saurik.com Git - wxWidgets.git/blame - include/wx/private/fdiodispatcher.h
Add more echo trace statements to runtests.bat script.
[wxWidgets.git] / include / wx / private / fdiodispatcher.h
CommitLineData
b46b1d59
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: wx/private/fdiodispatcher.h
3// Purpose: classes for dispatching IO notifications for file descriptors
4// Authors: Lukasz Michalski
5// Created: December 2006
6// Copyright: (c) Lukasz Michalski
7// RCS-ID: $Id$
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#ifndef _WX_PRIVATE_FDIODISPATCHER_H_
12#define _WX_PRIVATE_FDIODISPATCHER_H_
13
14#include "wx/hashmap.h"
3327957c 15#include "wx/private/fdiohandler.h"
b46b1d59
VZ
16
17// those flags describes sets where descriptor should be added
18enum wxFDIODispatcherEntryFlags
19{
20 wxFDIO_INPUT = 1,
21 wxFDIO_OUTPUT = 2,
22 wxFDIO_EXCEPTION = 4,
23 wxFDIO_ALL = wxFDIO_INPUT | wxFDIO_OUTPUT | wxFDIO_EXCEPTION
24};
25
ad8d42f8
VZ
26// base class for wxSelectDispatcher and wxEpollDispatcher
27class WXDLLIMPEXP_BASE wxFDIODispatcher
28{
29public:
30 enum { TIMEOUT_INFINITE = -1 };
31
5e1eac14
VZ
32 // return the global dispatcher to be used for IO events, can be NULL only
33 // if wxSelectDispatcher wasn't compiled into the library at all as
34 // creating it never fails
35 //
36 // don't delete the returned pointer
37 static wxFDIODispatcher *Get();
38
39 // if we have any registered handlers, check for any pending events to them
40 // and dispatch them -- this is used from wxX11 and wxDFB event loops
41 // implementation
42 static void DispatchPending();
43
ad8d42f8
VZ
44 // register handler for the given descriptor with the dispatcher, return
45 // true on success or false on error
46 virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags) = 0;
47
48 // modify descriptor flags or handler, return true on success
49 virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags) = 0;
50
af57c51a
VZ
51 // unregister descriptor previously registered with RegisterFD()
52 virtual bool UnregisterFD(int fd) = 0;
ad8d42f8 53
a12698ab
VZ
54 // check if any events are currently available without dispatching them
55 virtual bool HasPending() const = 0;
56
5a557d1e 57 // wait for an event for at most timeout milliseconds and process it;
a12698ab
VZ
58 // return the number of events processed (possibly 0 if timeout expired) or
59 // -1 if an error occurred
60 virtual int Dispatch(int timeout = TIMEOUT_INFINITE) = 0;
ad8d42f8
VZ
61
62 virtual ~wxFDIODispatcher() { }
63};
64
65//entry for wxFDIOHandlerMap
b46b1d59
VZ
66struct wxFDIOHandlerEntry
67{
68 wxFDIOHandlerEntry()
69 {
70 }
71
72 wxFDIOHandlerEntry(wxFDIOHandler *handler_, int flags_)
73 : handler(handler_),
74 flags(flags_)
75 {
76 }
77
78 wxFDIOHandler *handler;
79 int flags;
80};
81
82// this hash is used to map file descriptors to their handlers
83WX_DECLARE_HASH_MAP(
84 int,
85 wxFDIOHandlerEntry,
86 wxIntegerHash,
87 wxIntegerEqual,
88 wxFDIOHandlerMap
89);
90
ad8d42f8
VZ
91// FDIODispatcher that holds map fd <-> FDIOHandler, this should be used if
92// this map isn't maintained elsewhere already as it is usually needed anyhow
b46b1d59 93//
ad8d42f8 94// notice that all functions for FD management have implementation
b46b1d59 95// in the base class and should be called from the derived classes
af57c51a
VZ
96class WXDLLIMPEXP_BASE wxMappedFDIODispatcher : public wxFDIODispatcher
97{
b46b1d59 98public:
b46b1d59
VZ
99 // find the handler for the given fd, return NULL if none
100 wxFDIOHandler *FindHandler(int fd) const;
af57c51a 101
b46b1d59
VZ
102 // register handler for the given descriptor with the dispatcher, return
103 // true on success or false on error
ad8d42f8 104 virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags);
b46b1d59
VZ
105
106 // modify descriptor flags or handler, return true on success
ad8d42f8 107 virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags);
b46b1d59 108
af57c51a
VZ
109 // unregister descriptor previously registered with RegisterFD()
110 virtual bool UnregisterFD(int fd);
b46b1d59 111
ad8d42f8 112 virtual ~wxMappedFDIODispatcher() { }
b46b1d59
VZ
113
114protected:
115 // the fd -> handler map containing all the registered handlers
116 wxFDIOHandlerMap m_handlers;
117};
118
119#endif // _WX_PRIVATE_FDIODISPATCHER_H_