]> git.saurik.com Git - wxWidgets.git/blob - include/wx/private/fdiodispatcher.h
Resolve GCC's 'type-punned pointer will break strict-aliasing rules' warning by break...
[wxWidgets.git] / include / wx / private / fdiodispatcher.h
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 #include "wx/private/fdiohandler.h"
16
17 // those flags describes sets where descriptor should be added
18 enum 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
26 // base class for wxSelectDispatcher and wxEpollDispatcher
27 class WXDLLIMPEXP_BASE wxFDIODispatcher
28 {
29 public:
30 enum { TIMEOUT_INFINITE = -1 };
31
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
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
51 // unregister descriptor previously registered with RegisterFD()
52 virtual bool UnregisterFD(int fd) = 0;
53
54 // check if any events are currently available without dispatching them
55 virtual bool HasPending() const = 0;
56
57 // wait for an event for at most timeout milliseconds and process it;
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;
61
62 virtual ~wxFDIODispatcher() { }
63 };
64
65 //entry for wxFDIOHandlerMap
66 struct 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
83 WX_DECLARE_HASH_MAP(
84 int,
85 wxFDIOHandlerEntry,
86 wxIntegerHash,
87 wxIntegerEqual,
88 wxFDIOHandlerMap
89 );
90
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
93 //
94 // notice that all functions for FD management have implementation
95 // in the base class and should be called from the derived classes
96 class WXDLLIMPEXP_BASE wxMappedFDIODispatcher : public wxFDIODispatcher
97 {
98 public:
99 // find the handler for the given fd, return NULL if none
100 wxFDIOHandler *FindHandler(int fd) const;
101
102 // register handler for the given descriptor with the dispatcher, return
103 // true on success or false on error
104 virtual bool RegisterFD(int fd, wxFDIOHandler *handler, int flags);
105
106 // modify descriptor flags or handler, return true on success
107 virtual bool ModifyFD(int fd, wxFDIOHandler *handler, int flags);
108
109 // unregister descriptor previously registered with RegisterFD()
110 virtual bool UnregisterFD(int fd);
111
112 virtual ~wxMappedFDIODispatcher() { }
113
114 protected:
115 // the fd -> handler map containing all the registered handlers
116 wxFDIOHandlerMap m_handlers;
117 };
118
119 #endif // _WX_PRIVATE_FDIODISPATCHER_H_