]> git.saurik.com Git - wxWidgets.git/blame - include/wx/private/fdiodispatcher.h
made wxHeaderColumnBase dtor virtual to avoid gcc warnings
[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"
15
16// handler used to process events on descriptors
17class wxFDIOHandler
18{
19public:
20 // called when descriptor is available for non-blocking read
21 virtual void OnReadWaiting() = 0;
22
23 // called when descriptor is available for non-blocking write
24 virtual void OnWriteWaiting() = 0;
25
26 // called when there is exception on descriptor
27 virtual void OnExceptionWaiting() = 0;
28
29 // virtual dtor for the base class
30 virtual ~wxFDIOHandler() { }
31};
32
33// those flags describes sets where descriptor should be added
34enum wxFDIODispatcherEntryFlags
35{
36 wxFDIO_INPUT = 1,
37 wxFDIO_OUTPUT = 2,
38 wxFDIO_EXCEPTION = 4,
39 wxFDIO_ALL = wxFDIO_INPUT | wxFDIO_OUTPUT | wxFDIO_EXCEPTION
40};
41
ad8d42f8
VZ
42// base class for wxSelectDispatcher and wxEpollDispatcher
43class WXDLLIMPEXP_BASE wxFDIODispatcher
44{
45public:
46 enum { TIMEOUT_INFINITE = -1 };
47
5e1eac14
VZ
48 // return the global dispatcher to be used for IO events, can be NULL only
49 // if wxSelectDispatcher wasn't compiled into the library at all as
50 // creating it never fails
51 //
52 // don't delete the returned pointer
53 static wxFDIODispatcher *Get();
54
55 // if we have any registered handlers, check for any pending events to them
56 // and dispatch them -- this is used from wxX11 and wxDFB event loops
57 // implementation
58 static void DispatchPending();
59
ad8d42f8
VZ
60 // register handler for the given descriptor with the dispatcher, return
61 // true on success or false on error
62 virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags) = 0;
63
64 // modify descriptor flags or handler, return true on success
65 virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags) = 0;
66
af57c51a
VZ
67 // unregister descriptor previously registered with RegisterFD()
68 virtual bool UnregisterFD(int fd) = 0;
ad8d42f8 69
5a557d1e
VZ
70 // wait for an event for at most timeout milliseconds and process it;
71 // return true if we processed any events or false if timeout expired
72 // without anything happening
73 virtual bool Dispatch(int timeout = TIMEOUT_INFINITE) = 0;
ad8d42f8
VZ
74
75 virtual ~wxFDIODispatcher() { }
76};
77
78//entry for wxFDIOHandlerMap
b46b1d59
VZ
79struct wxFDIOHandlerEntry
80{
81 wxFDIOHandlerEntry()
82 {
83 }
84
85 wxFDIOHandlerEntry(wxFDIOHandler *handler_, int flags_)
86 : handler(handler_),
87 flags(flags_)
88 {
89 }
90
91 wxFDIOHandler *handler;
92 int flags;
93};
94
95// this hash is used to map file descriptors to their handlers
96WX_DECLARE_HASH_MAP(
97 int,
98 wxFDIOHandlerEntry,
99 wxIntegerHash,
100 wxIntegerEqual,
101 wxFDIOHandlerMap
102);
103
ad8d42f8
VZ
104// FDIODispatcher that holds map fd <-> FDIOHandler, this should be used if
105// this map isn't maintained elsewhere already as it is usually needed anyhow
b46b1d59 106//
ad8d42f8 107// notice that all functions for FD management have implementation
b46b1d59 108// in the base class and should be called from the derived classes
af57c51a
VZ
109class WXDLLIMPEXP_BASE wxMappedFDIODispatcher : public wxFDIODispatcher
110{
b46b1d59 111public:
b46b1d59
VZ
112 // find the handler for the given fd, return NULL if none
113 wxFDIOHandler *FindHandler(int fd) const;
af57c51a 114
b46b1d59
VZ
115 // register handler for the given descriptor with the dispatcher, return
116 // true on success or false on error
ad8d42f8 117 virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags);
b46b1d59
VZ
118
119 // modify descriptor flags or handler, return true on success
ad8d42f8 120 virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags);
b46b1d59 121
af57c51a
VZ
122 // unregister descriptor previously registered with RegisterFD()
123 virtual bool UnregisterFD(int fd);
b46b1d59 124
ad8d42f8 125 virtual ~wxMappedFDIODispatcher() { }
b46b1d59
VZ
126
127protected:
128 // the fd -> handler map containing all the registered handlers
129 wxFDIOHandlerMap m_handlers;
130};
131
132#endif // _WX_PRIVATE_FDIODISPATCHER_H_