1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
|
/* -*- C++ -*- */
//=============================================================================
/**
* @file QtReactor.h
*
* $Id$
*
* @author Hamish Friedlander <ullexco@wave.co.nz>
* @author Balachandran Natarajan <bala@cs.wustl.edu>
*/
//=============================================================================
#ifndef ACE_QTREACTOR_H
#define ACE_QTREACTOR_H
#include "ace/pre.h"
#include "ace/Select_Reactor.h"
#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */
#if defined (ACE_HAS_QT)
#include "ace/Map_Manager.h"
// Qttoolkit specific includes.
#include <qapplication.h>
#include <qobject.h>
#include <qsocketnotifier.h>
#include <qtimer.h>
/**
* @class ACE_QtReactor
*
* @brief An object-oriented event demultiplexor and event handler
* dispatcher that uses the Qt Library. This class declaration
* also uses the extension facilities provided by the Qt. So,
* readers of the class declaration should not be upset with
* the appearence of the Keywords like Q_OBJECT, private slots
* etc. They are specific to Qt which uses these as a call back
* methods implementation mechanism.
*/
class ACE_Export ACE_QtReactor : public QObject, public ACE_Select_Reactor
{
Q_OBJECT
public:
// = Initialization and termination methods.
ACE_QtReactor (QApplication *qapp = NULL,
size_t size = DEFAULT_SIZE,
int restart = 0,
ACE_Sig_Handler *handler = 0);
virtual ~ACE_QtReactor (void);
void qapplication (QApplication *qapp);
// = Timer operations.
virtual long schedule_timer (ACE_Event_Handler *handler,
const void *arg,
const ACE_Time_Value &delta_time,
const ACE_Time_Value &interval);
virtual int cancel_timer (ACE_Event_Handler *handler,
int dont_call_handle_close = 1);
virtual int cancel_timer (long timer_id,
const void **arg = 0,
int dont_call_handle_close = 1);
protected:
// = Register timers/handles with Qt
/// Register a single <handler>.
virtual int register_handler_i (ACE_HANDLE handle,
ACE_Event_Handler *handler,
ACE_Reactor_Mask mask);
/// Register a set of <handlers> with Qt.
virtual int register_handler_i (const ACE_Handle_Set &handles,
ACE_Event_Handler *handler,
ACE_Reactor_Mask mask);
/// Remove the <handler> associated with this <handle>.
virtual int remove_handler_i (ACE_HANDLE handle,
ACE_Reactor_Mask mask);
/// Remove a set of <handles>.
virtual int remove_handler_i (const ACE_Handle_Set &handles,
ACE_Reactor_Mask mask);
/// Wait for events to occur.
virtual int wait_for_multiple_events (ACE_Select_Reactor_Handle_Set &handle_set,
ACE_Time_Value *max_wait_time);
virtual int QtWaitForMultipleEvents (int width,
ACE_Select_Reactor_Handle_Set &wait_set,
ACE_Time_Value *max_wait_time);
// Wait for Qt events to occur
/// Some Qt stuff that we need to have
QApplication *qapp_ ;
/// Typedef of a map.
typedef ACE_Map_Manager<ACE_HANDLE, QSocketNotifier *, ACE_Null_Mutex> MAP;
/// A notifier for a read
MAP read_notifier_;
/// A write notifier
MAP write_notifier_;
/// An exception notifier
MAP exception_notifier_;
/// The timer class that would provide timer-sgnals & single-shot timers
QTimer *qtime_ ;
private:
/// This method ensures there's an Qt timeout for the first timeout
/// in the Reactor's Timer_Queue.
void reset_timeout (void);
/// Deny access since member-wise won't work...
ACE_QtReactor (const ACE_QtReactor &);
ACE_QtReactor &operator= (const ACE_QtReactor &);
private slots:
// These are all part of the communication mechanism adopted in Qt.
/// Dispatch a Read Event
void read_event (int FD);
/// Dispatch a Write Event
void write_event (int FD);
/// Dispatch an exception event
void exception_event (int FD);
/// Dispach a timeout event
void timeout_event (void);
};
#endif /*ACE_HAS_QT */
#include "ace/post.h"
#endif /* ACE_QTREACTOR_H */
|