wvdbusserver: implement NameHasOwner request.
[wvstreams.git] / include / wvqtstreamclone.h
blob4bbdc991ad9a83b5dac7fe04c026bf540277c45b
1 /* -*- Mode: C++ -*-
2 * Worldvisions Weaver Software:
3 * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
5 */
6 #ifndef __WVQTSTREAMCLONE_H
7 #define __WVQTSTREAMCLONE_H
9 #include <qobject.h>
10 #include <qintdict.h>
11 #include <qsocketnotifier.h>
12 #include <qtimer.h>
13 #include <qmetaobject.h>
14 #include "wvstreamclone.h"
16 /**
17 * Wraps another WvStream and attaches it to the normal Qt event loop.
19 * If you are using this object exclusively to manage all of your
20 * streams, then you do not need to have a normal WvStreams
21 * select()/callback() loop in your application at all.
23 * However, should you leave the Qt event loop and wish to continue
24 * using this WvStream, call qt_detach() first, then run a normal
25 * WvStreams event loop. If you do not do this, events may be
26 * lost! Later, you may resume the Qt event loop at any time
27 * by leaving your WvStreams event loop and calling qt_attach().
29 * Multiple instances of this object may coexist to wrap different
30 * WvStream's or WvStreamList's.
33 class WvQtStreamClone : public QObject, public WvStreamClone
35 Q_OBJECT
36 int msec_timeout;
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;
48 public:
49 /**
50 * WvQtStreamClone takes ownership of the stream you give it
51 * just like WvStreamClone. See comments there.
53 * Timeout sets the time between polls with select().
54 * A value less than zero is regarded as an infinite timeout.
56 WvQtStreamClone(IWvStream *_cloned = NULL, int msec_timeout = -1);
57 virtual ~WvQtStreamClone();
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();
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();
68 // Changes the timeout
69 // You may need to adjust the timeout when using badly behaved streams
70 void set_timeout(int msec_timeout);
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();
78 private slots:
79 /** These things mark the beginning of a select pass **/
80 // Qt event loop hook (happens before each iteration)
81 void qt_begin_event_loop_hook();
83 /** These things mark the end of a select pass **/
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);
93 // Needed or certain assertions fail ;)
94 virtual void execute();
96 public:
97 virtual void setclone(IWvStream *clone);
100 #endif // __WVQTSTREAMCLONE_H