WvStreams
wvqtstreamclone.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  */
00006 #ifndef __WVQTSTREAMCLONE_H
00007 #define __WVQTSTREAMCLONE_H
00008 
00009 #include <qobject.h>
00010 #include <qintdict.h>
00011 #include <qsocketnotifier.h>
00012 #include <qtimer.h>
00013 #include <qmetaobject.h>
00014 #include "wvstreamclone.h"
00015 
00033 class WvQtStreamClone : public QObject, public WvStreamClone
00034 {
00035     Q_OBJECT
00036     int msec_timeout;
00037     
00038     SelectInfo si;
00039     bool pending_callback;
00040     bool first_time;
00041     bool select_in_progress;
00042     int last_max_fd;
00043     QIntDict<QSocketNotifier> notify_readable;
00044     QIntDict<QSocketNotifier> notify_writable;
00045     QIntDict<QSocketNotifier> notify_exception;
00046     QTimer select_timer;
00047 
00048 public:
00056     WvQtStreamClone(IWvStream *_cloned = NULL, int msec_timeout = -1);
00057     virtual ~WvQtStreamClone();
00058 
00059     // Call this to stop managing this stream via the Qt event loop.
00060     // Afterwards you may run a normal WvStream event loop based
00061     // on this object.
00062     void qt_detach();
00063 
00064     // Call this to resume managing this stream via the Qt event loop.
00065     // This is the default state when the object is constructed.
00066     void qt_attach();
00067 
00068     // Changes the timeout
00069     // You may need to adjust the timeout when using badly behaved streams
00070     void set_timeout(int msec_timeout);
00071 
00072 private:
00073     // Called before the Qt event loop does its select()
00074     void pre_poll();
00075     // Called after the Qt event loop has finished its notifications
00076     void post_poll();
00077 
00078 private slots:
00080     // Qt event loop hook (happens before each iteration)
00081     void qt_begin_event_loop_hook();
00082 
00084     // Qt select timeout expired
00085     void select_timer_expired();
00086     // Called when a file descriptor has been marked readable
00087     void fd_readable(int fd);
00088     // Called when a file descriptor has been marked writable
00089     void fd_writable(int fd);
00090     // Called when a file descriptor has been marked with an exception
00091     void fd_exception(int fd);
00092 
00093     // Needed or certain assertions fail ;)
00094     virtual void execute();
00095 
00096 public:
00097     virtual void setclone(IWvStream *clone);
00098 };
00099 
00100 #endif // __WVQTSTREAMCLONE_H