# ACE_QtReactor Class Reference

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. More...

`#include <QtReactor.h>`

Inheritance diagram for ACE_QtReactor:

[legend]
Collaboration diagram for ACE_QtReactor:

[legend]
List of all members.

## Public Member Functions

| ACE_QtReactor (QApplication *qapp=0, ACE_Sig_Handler *=0, ACE_Timer_Queue *=0, int disable_notify_pipe=0, ACE_Reactor_Notify *notify=0, int mask_signals=1, int s_queue=ACE_SELECT_TOKEN::FIFO)
| Constructor follows .
| ACE_QtReactor (size_t size, QApplication *qapp=0, int restart=0, ACE_Sig_Handler *=0, ACE_Timer_Queue *=0, int disable_notify_pipe=0, ACE_Reactor_Notify *notify=0, int mask_signals=1, int s_queue=ACE_SELECT_TOKEN::FIFO)
| Constructor follows .
virtual | ~ACE_QtReactor (void)
void | qapplication (QApplication *qapp)
virtual long | schedule_timer (ACE_Event_Handler *handler, const void *arg, const ACE_Time_Value &delay_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 Types

typedef ACE_Map_Manager< ACE_HANDLE, QSocketNotifier *, ACE_Null_Mutex > | MAP
| Typedef of a map.

## Protected Member Functions

virtual int | register_handler_i (ACE_HANDLE handle, ACE_Event_Handler *handler, ACE_Reactor_Mask mask)
| Register a single <handler>.
virtual int | register_handler_i (const ACE_Handle_Set &handles, ACE_Event_Handler *handler, ACE_Reactor_Mask mask)
| Register a set of <handlers> with Qt.
virtual int | remove_handler_i (ACE_HANDLE handle, ACE_Reactor_Mask mask)
| Remove the <handler> associated with this <handle>.
virtual int | remove_handler_i (const ACE_Handle_Set &handles, ACE_Reactor_Mask mask)
| Remove a set of <handles>.
virtual int | wait_for_multiple_events (ACE_Select_Reactor_Handle_Set &handle_set, ACE_Time_Value *max_wait_time)
| Wait for events to occur.
virtual int | QtWaitForMultipleEvents (int width, ACE_Select_Reactor_Handle_Set &wait_set, ACE_Time_Value *max_wait_time)
virtual int | bit_ops (ACE_HANDLE handle, ACE_Reactor_Mask mask, ACE_Select_Reactor_Handle_Set &handle_set, int ops)
| Allow manipulation of the <wait_set_> mask and <ready_set_> mask.
int | set_enable_flag_by_mask (int flag_value, ACE_HANDLE handle, ACE_Reactor_Mask mask)
void | create_notifiers_for_handle (ACE_HANDLE handle)
void | destroy_notifiers_for_handle (ACE_HANDLE handle)

## Protected Attributes

QApplication * | qapp_
| Some Qt stuff that we need to have.
MAP | read_notifier_
| A notifier for a read.
MAP | write_notifier_
| A write notifier.
MAP | exception_notifier_
| An exception notifier.
QTimer * | qtime_
| The timer class that would provide timer-sgnals & single-shot timers.

## Private Slots

void | read_event (int FD)
| Dispatch a Read Event.
void | write_event (int FD)
| Dispatch a Write Event.
void | exception_event (int FD)
| Dispatch an exception event.
void | timeout_event (void)
| Dispach a timeout event.

## Private Member Functions

void | reset_timeout (void)
void | reopen_notification_pipe (void)
| reopens notification pipe to create SocketNotifier for it
| ACE_QtReactor (const ACE_QtReactor &)
| Deny access since member-wise won't work...
ACE_QtReactor & | operator= (const ACE_QtReactor &)

## Detailed Description

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.

Note:
  Marek Brudka <mbrudka@elka.pw.edu.pl>: ACE_QtReactor was quickly bugfixed to meet ACE 5.4.2 (6.0.0?) deadline. While it passes QtReactor_Test now, there is a great room for improvements as the implementation is rather inefficient and obfuscated To be more specific:
  - reset_timeout always creates and removes qtimer after each timeout event! Obviously, for fast triggering timers this may lead to excessive memory management.
  - create/destroy_notifiers_for_handle may also be reworked to establish more clean relations between handles and QSocketNotifiers.
  - read/write_exception_event disable now SocketNotifier for a while to clear pending events. The cost of this operation is high: two hash acces in ACE and at least two next ones in Qt. This makes QtReator slow, but how clear pending events another way ?
  - there is qapplication() mutator, which sets new qapplication for QtReactor. This mutator violates implicit assumption about the relations between QTimer and QSocketNotifiers and QApplication for this reactor, namely one may expect that after qapplication(), none of QtReactor artifacts is bound to old qapplication. That's not true now, as QTimer and QSocketNotifiers are not reparent to new QApplication. As a result, the sequence: QApplication *old_qapp = new QApplication(..); QtReactor qreactor( old_qapp); // .. register handlers, schedule_timers etc QApplication *new_qapp = new QApplication(..); qreactor.qpplication( new_qapp ); delete old_qapp; almost always leads to problems and memory violation, because QSocketNotifiers are released by old_qapp. Therefore QtReactor should not be reparent now by setting new qapplication.
  - the lifecycle of Qt objects in ACE contects is rather mysterious and should be made more explicit.
  - valgrind reports a small memory leak in QtReactor_Test, though as for now it is not clear if the leak is introduced by QtReactor, or rather incorrect memory management in QtReactor_Test.

## Member Typedef Documentation

typedef ACE_Map_Manager<ACE_HANDLE, QSocketNotifier *, ACE_Null_Mutex> ACE_QtReactor::MAP`[protected]`

| Typedef of a map.

## Constructor & Destructor Documentation

ACE_BEGIN_VERSIONED_NAMESPACE_DECL ACE_QtReactor::ACE_QtReactor | ( | QApplication * | qapp = `0`,
|  | ACE_Sig_Handler * | = `0`,
|  | ACE_Timer_Queue * | = `0`,
|  | int | disable_notify_pipe = `0`,
|  | ACE_Reactor_Notify * | notify = `0`,
|  | int | mask_signals = `1`,
|  | int | s_queue = `ACE_SELECT_TOKEN::FIFO`
| ) |

Constructor follows .

Parameters:

  | QApplication | *qapp, qapplication which runs events loop

ACE_QtReactor::ACE_QtReactor | ( | size_t | size,
|  | QApplication * | qapp = `0`,
|  | int | restart = `0`,
|  | ACE_Sig_Handler * | = `0`,
|  | ACE_Timer_Queue * | = `0`,
|  | int | disable_notify_pipe = `0`,
|  | ACE_Reactor_Notify * | notify = `0`,
|  | int | mask_signals = `1`,
|  | int | s_queue = `ACE_SELECT_TOKEN::FIFO`
| ) |

Constructor follows .

Parameters:

  | QApplication | *qapp, qapplication which runs events loop

ACE_QtReactor::~ACE_QtReactor | ( | void |  | ) | `[virtual]`

ACE_QtReactor::ACE_QtReactor | ( | const ACE_QtReactor & |  | ) | `[private]`

| Deny access since member-wise won't work...

## Member Function Documentation

int ACE_QtReactor::bit_ops | ( | ACE_HANDLE | handle,
|  | ACE_Reactor_Mask | mask,
|  | ACE_Select_Reactor_Handle_Set & | handle_set,
|  | int | ops
| ) | `[protected, virtual]`

| Allow manipulation of the <wait_set_> mask and <ready_set_> mask. Reimplemented from ACE_Select_Reactor_Impl.

int ACE_QtReactor::cancel_timer | ( | long | timer_id,
|  | const void ** | arg = `0`,
|  | int | dont_call_handle_close = `1`
| ) | `[virtual]`

Cancel the single ACE_Event_Handler that matches the <timer_id> value (which was returned from the <schedule> method). If arg is non-NULL then it will be set to point to the ``magic cookie'' argument passed in when the <event_handler> was registered. This makes it possible to free up the memory and avoid memory leaks. If <dont_call_handle_close> is 0 then the <handle_close> method of <event_handler> will be invoked. Returns 1 if cancellation succeeded and 0 if the <timer_id> wasn't found.

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

int ACE_QtReactor::cancel_timer | ( | ACE_Event_Handler * | handler,
|  | int | dont_call_handle_close = `1`
| ) | `[virtual]`

| Cancel all <event_handlers> that match the address of <event_handler>. If <dont_call_handle_close> is 0 then the <handle_close> method of <event_handler> will be invoked. Returns number of handler's cancelled. Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

void ACE_QtReactor::create_notifiers_for_handle | ( | ACE_HANDLE | handle | ) | `[protected]`

void ACE_QtReactor::destroy_notifiers_for_handle | ( | ACE_HANDLE | handle | ) | `[protected]`

void ACE_QtReactor::exception_event | ( | int | FD | ) | `[private, slot]`

| Dispatch an exception event.

ACE_QtReactor& ACE_QtReactor::operator= | ( | const ACE_QtReactor & |  | ) | `[private]`

void ACE_QtReactor::qapplication | ( | QApplication * | qapp | ) |

int ACE_QtReactor::QtWaitForMultipleEvents | ( | int | width,
|  | ACE_Select_Reactor_Handle_Set & | wait_set,
|  | ACE_Time_Value * | max_wait_time
| ) | `[protected, virtual]`

void ACE_QtReactor::read_event | ( | int | FD | ) | `[private, slot]`

| Dispatch a Read Event.

int ACE_QtReactor::register_handler_i | ( | const ACE_Handle_Set & | handles,
|  | ACE_Event_Handler * | handler,
|  | ACE_Reactor_Mask | mask
| ) | `[protected, virtual]`

| Register a set of <handlers> with Qt. Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

int ACE_QtReactor::register_handler_i | ( | ACE_HANDLE | handle,
|  | ACE_Event_Handler * | handler,
|  | ACE_Reactor_Mask | mask
| ) | `[protected, virtual]`

| Register a single <handler>. Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

int ACE_QtReactor::remove_handler_i | ( | const ACE_Handle_Set & | handles,
|  | ACE_Reactor_Mask | mask
| ) | `[protected, virtual]`

| Remove a set of <handles>. Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

int ACE_QtReactor::remove_handler_i | ( | ACE_HANDLE | handle,
|  | ACE_Reactor_Mask | mask
| ) | `[protected, virtual]`

| Remove the <handler> associated with this <handle>. Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

void ACE_QtReactor::reopen_notification_pipe | ( | void |  | ) | `[private]`

| reopens notification pipe to create SocketNotifier for it

void ACE_QtReactor::reset_timeout | ( | void |  | ) | `[private]`

| This method ensures there's an Qt timeout for the first timeout in the Reactor's Timer_Queue.

long ACE_QtReactor::schedule_timer | ( | ACE_Event_Handler * | handler,
|  | const void * | arg,
|  | const ACE_Time_Value & | delay_time,
|  | const ACE_Time_Value & | interval
| ) | `[virtual]`

Schedule an ACE_Event_Handler that will expire after an amount of time. The return value of this method, a timer_id value, uniquely identifies the event_handler in the ACE_Reactor's internal list of timers. This timer_id value can be used to cancel the timer with the cancel_timer() call.

See also:
  cancel_timer()

  reset_timer_interval()

Parameters:

  | event_handler | Event handler to schedule on reactor
  | arg | Argument passed to the handle_timeout() method of event_handler
  | delay | Time interval after which the timer will expire
  | interval | Time interval after which the timer will be automatically rescheduled

Returns:
  -1 on failure, a timer_id value on success

Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

int ACE_QtReactor::set_enable_flag_by_mask | ( | int | flag_value,
|  | ACE_HANDLE | handle,
|  | ACE_Reactor_Mask | mask
| ) | `[protected]`

void ACE_QtReactor::timeout_event | ( | void |  | ) | `[private, slot]`

| Dispach a timeout event.

int ACE_QtReactor::wait_for_multiple_events | ( | ACE_Select_Reactor_Handle_Set & | handle_set,
|  | ACE_Time_Value * | max_wait_time
| ) | `[protected, virtual]`

| Wait for events to occur. Reimplemented from ACE_Select_Reactor_T< ACE_SELECT_REACTOR_TOKEN >.

void ACE_QtReactor::write_event | ( | int | FD | ) | `[private, slot]`

| Dispatch a Write Event.

## Member Data Documentation

MAP ACE_QtReactor::exception_notifier_`[protected]`

| An exception notifier.

QApplication* ACE_QtReactor::qapp_`[protected]`

| Some Qt stuff that we need to have.

QTimer* ACE_QtReactor::qtime_`[protected]`

| The timer class that would provide timer-sgnals & single-shot timers.

MAP ACE_QtReactor::read_notifier_`[protected]`

| A notifier for a read.

MAP ACE_QtReactor::write_notifier_`[protected]`

| A write notifier.

The documentation for this class was generated from the following files:

- QtReactor.h
- QtReactor.cpp