WvStreams
wvqtstreamclone.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Weaver Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  */
6 #ifndef __WVQTSTREAMCLONE_H
7 #define __WVQTSTREAMCLONE_H
8 
9 #include <qobject.h>
10 #include <qintdict.h>
11 #include <qsocketnotifier.h>
12 #include <qtimer.h>
13 #include <qmetaobject.h>
14 #include "wvstreamclone.h"
15 
33 class WvQtStreamClone : public QObject, public WvStreamClone
34 {
35  Q_OBJECT
36  int msec_timeout;
37 
38  SelectInfo si;
39  bool pending_callback;
40  bool first_time;
41  bool select_in_progress;
42  int last_max_fd;
43  QIntDict<QSocketNotifier> notify_readable;
44  QIntDict<QSocketNotifier> notify_writable;
45  QIntDict<QSocketNotifier> notify_exception;
46  QTimer select_timer;
47 
48 public:
56  WvQtStreamClone(IWvStream *_cloned = NULL, int msec_timeout = -1);
57  virtual ~WvQtStreamClone();
58 
59  // Call this to stop managing this stream via the Qt event loop.
60  // Afterwards you may run a normal WvStream event loop based
61  // on this object.
62  void qt_detach();
63 
64  // Call this to resume managing this stream via the Qt event loop.
65  // This is the default state when the object is constructed.
66  void qt_attach();
67 
68  // Changes the timeout
69  // You may need to adjust the timeout when using badly behaved streams
70  void set_timeout(int msec_timeout);
71 
72 private:
73  // Called before the Qt event loop does its select()
74  void pre_poll();
75  // Called after the Qt event loop has finished its notifications
76  void post_poll();
77 
78 private slots:
80  // Qt event loop hook (happens before each iteration)
81  void qt_begin_event_loop_hook();
82 
84  // Qt select timeout expired
85  void select_timer_expired();
86  // Called when a file descriptor has been marked readable
87  void fd_readable(int fd);
88  // Called when a file descriptor has been marked writable
89  void fd_writable(int fd);
90  // Called when a file descriptor has been marked with an exception
91  void fd_exception(int fd);
92 
93  // Needed or certain assertions fail ;)
94  virtual void execute();
95 
96 public:
97  virtual void setclone(IWvStream *clone);
98 };
99 
100 #endif // __WVQTSTREAMCLONE_H
WvQtStreamClone::setclone
virtual void setclone(IWvStream *clone)
WvStreamClone takes ownership of the given stream; it will WVRELEASE() the stream when you setclone()...
Definition: wvqtstreamclone.cc:225
IWvStream
Definition: iwvstream.h:24
WvQtStreamClone
Wraps another WvStream and attaches it to the normal Qt event loop.
Definition: wvqtstreamclone.h:33
IWvStream::SelectInfo
the data structure used by pre_select()/post_select() and internally by select().
Definition: iwvstream.h:50
WvQtStreamClone::WvQtStreamClone
WvQtStreamClone(IWvStream *_cloned=NULL, int msec_timeout=-1)
WvQtStreamClone takes ownership of the stream you give it just like WvStreamClone.
Definition: wvqtstreamclone.cc:28
WvStreamClone
WvStreamClone simply forwards all requests to the "cloned" stream.
Definition: wvstreamclone.h:23