Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

QtReactor.h

Go to the documentation of this file.
00001 /* -*- C++ -*- */
00002 
00003 //=============================================================================
00004 /**
00005  *  @file    QtReactor.h
00006  *
00007  *  $Id: QtReactor.h,v 1.1.1.4 2003/02/21 18:36:32 chad Exp $
00008  *
00009  *  @author Hamish Friedlander <ullexco@wave.co.nz>
00010  *  @author Balachandran Natarajan <bala@cs.wustl.edu>
00011  */
00012 //=============================================================================
00013 
00014 #ifndef ACE_QTREACTOR_H
00015 #define ACE_QTREACTOR_H
00016 #include "ace/pre.h"
00017 
00018 #include "ace/config-all.h"
00019 
00020 #if !defined (ACE_LACKS_PRAGMA_ONCE)
00021 # pragma once
00022 #endif /* ACE_LACKS_PRAGMA_ONCE */
00023 
00024 #if defined (ACE_HAS_QT)
00025 
00026 #include "ace/Select_Reactor.h"
00027 #include "ace/Map_Manager.h"
00028 
00029 // Qttoolkit specific includes.
00030 #include /**/ <qapplication.h>
00031 #include /**/ <qobject.h>
00032 #include /**/ <qsocketnotifier.h>
00033 #include /**/ <qtimer.h>
00034 
00035 /**
00036  * @class ACE_QtReactor
00037  *
00038  * @brief An object-oriented event demultiplexor and event handler
00039  * dispatcher that uses the Qt Library. This class declaration
00040  * also uses the extension facilities  provided by the Qt. So,
00041  * readers  of the class declaration should not be upset with
00042  * the appearence of the Keywords like Q_OBJECT, private slots
00043  * etc. They are specific to Qt which uses these as a call back
00044  * methods implementation mechanism.
00045  */
00046 class ACE_Export ACE_QtReactor : public QObject, public ACE_Select_Reactor
00047 {
00048 
00049   Q_OBJECT
00050 
00051  public:
00052   // = Initialization and termination methods.
00053   ACE_QtReactor (QApplication *qapp  = NULL,
00054                  size_t size = DEFAULT_SIZE,
00055                  int restart = 0,
00056                  ACE_Sig_Handler *handler = 0);
00057 
00058   virtual ~ACE_QtReactor (void);
00059 
00060   void qapplication (QApplication *qapp);
00061 
00062   // = Timer operations.
00063   virtual long schedule_timer (ACE_Event_Handler *event_handler,
00064                                const void *arg,
00065                                const ACE_Time_Value &delay,
00066                                const ACE_Time_Value &interval);
00067 
00068   virtual int  cancel_timer (ACE_Event_Handler *handler,
00069                                int dont_call_handle_close = 1);
00070 
00071   virtual int  cancel_timer (long timer_id,
00072                              const void **arg = 0,
00073                              int dont_call_handle_close = 1);
00074 
00075  protected:
00076 
00077    // = Register timers/handles with Qt
00078 
00079   /// Register a single <handler>.
00080   virtual int register_handler_i (ACE_HANDLE handle,
00081                                   ACE_Event_Handler *handler,
00082                                   ACE_Reactor_Mask mask);
00083 
00084   /// Register a set of <handlers> with Qt.
00085   virtual int register_handler_i (const ACE_Handle_Set &handles,
00086                                   ACE_Event_Handler *handler,
00087                                   ACE_Reactor_Mask mask);
00088 
00089 
00090   /// Remove the <handler> associated with this <handle>.
00091   virtual int remove_handler_i (ACE_HANDLE handle,
00092                                 ACE_Reactor_Mask mask);
00093 
00094   /// Remove a set of <handles>.
00095   virtual int remove_handler_i (const ACE_Handle_Set &handles,
00096                                 ACE_Reactor_Mask mask);
00097 
00098   /// Wait for events to occur.
00099   virtual int wait_for_multiple_events (ACE_Select_Reactor_Handle_Set &handle_set,
00100                                         ACE_Time_Value *max_wait_time);
00101 
00102   virtual int QtWaitForMultipleEvents (int width,
00103                                        ACE_Select_Reactor_Handle_Set &wait_set,
00104                                        ACE_Time_Value *max_wait_time);
00105 
00106   // Wait for Qt events to occur
00107 
00108   /// Some Qt stuff that we need to have
00109   QApplication *qapp_ ;
00110 
00111   /// Typedef of a map.
00112   typedef ACE_Map_Manager<ACE_HANDLE, QSocketNotifier *, ACE_Null_Mutex> MAP;
00113 
00114   /// A notifier for a read
00115   MAP read_notifier_;
00116 
00117   /// A write notifier
00118   MAP write_notifier_;
00119 
00120   /// An exception notifier
00121   MAP exception_notifier_;
00122 
00123   /// The timer class that would provide timer-sgnals & single-shot timers
00124   QTimer *qtime_ ;
00125 
00126  private:
00127   /// This method ensures there's an Qt timeout for the first timeout
00128   /// in the Reactor's Timer_Queue.
00129   void reset_timeout (void);
00130 
00131   /// Deny access since member-wise won't work...
00132   ACE_QtReactor (const ACE_QtReactor &);
00133   ACE_QtReactor &operator= (const ACE_QtReactor &);
00134 
00135  private slots:
00136 
00137     // These are all part of the communication mechanism adopted in Qt.
00138   /// Dispatch a Read Event
00139   void read_event (int FD);
00140 
00141   /// Dispatch a Write Event
00142   void write_event (int FD);
00143 
00144   /// Dispatch an exception event
00145   void exception_event (int FD);
00146 
00147   /// Dispach a timeout event
00148   void timeout_event (void);
00149 };
00150 
00151 #endif /*ACE_HAS_QT */
00152 
00153 #include "ace/post.h"
00154 #endif /* ACE_QTREACTOR_H */

Generated on Mon Jun 16 11:20:57 2003 for ACE by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002