merge in my changes from soc-krdc branch
[kdenetwork.git] / krdc / vnc / threads.h
blob6f2cac1297e2c3e02e89f18931fdddf8926b212c
1 /***************************************************************************
2 threads.h - threads for kvncview
3 -------------------
4 begin : Thu May 09 16:01:42 CET 2002
5 copyright : (C) 2002 by Tim Jansen
6 email : tim@tjansen.de
7 ***************************************************************************/
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
18 #ifndef THREADS_H
19 #define THREADS_H
21 #include <QThread>
22 #include <QRegion>
23 #include <QRect>
24 #include <QMutex>
25 #include <QWaitCondition>
26 #include <QList>
27 #include <QTime>
29 #include <stdlib.h>
31 #include "events.h"
32 #include "vnctypes.h"
34 class KVncView;
36 enum EventType {
37 MouseEventType,
38 KeyEventType
42 struct MouseEvent {
43 int x, y, buttons;
46 struct KeyEvent {
47 unsigned int k;
48 bool down;
51 struct InputEvent {
52 EventType type;
53 union {
54 MouseEvent m;
55 KeyEvent k;
56 } e;
60 class WriterThread : public QThread {
61 private:
62 QMutex m_lock;
63 QWaitCondition m_waiter;
64 volatile bool &m_quitFlag;
65 KVncView *m_view;
67 QTime m_lastIncrUpdate; // start()ed when a incr update is sent
68 bool m_lastIncrUpdatePostponed;
70 // all things that can be send follow:
71 bool m_incrementalUpdateRQ; // for sending an incremental request
72 bool m_incrementalUpdateAnnounced; // set when a RQ will come soon
73 QRegion m_updateRegionRQ; // for sending updates, null if it is done
74 QList<InputEvent> m_inputEvents; // list of unsent input events
75 MouseEvent m_lastMouseEvent;
76 int m_mouseEventNum, m_keyEventNum;
77 QString m_clientCut;
79 void sendFatalError(KRemoteView::ErrorCode s);
81 public:
82 WriterThread(KVncView *v, volatile bool &quitFlag);
84 void queueIncrementalUpdateRequest();
85 void announceIncrementalUpdateRequest();
86 void queueUpdateRequest(const QRegion &r);
87 void queueMouseEvent(int x, int y, int buttonMask);
88 void queueKeyEvent(unsigned int k, bool down);
89 void queueClientCut(const QString &text);
90 void kick();
92 protected:
93 void run();
94 bool sendIncrementalUpdateRequest();
95 bool sendUpdateRequest(const QRegion &r);
96 bool sendInputEvents(const QList<InputEvent> &events);
101 class ControllerThread : public QThread {
102 private:
103 KVncView *m_view;
104 KRemoteView::RemoteStatus m_status;
105 WriterThread &m_wthread;
106 volatile bool &m_quitFlag;
107 volatile bool m_desktopInitialized;
108 QWaitCondition m_waiter;
110 void changeStatus(KRemoteView::RemoteStatus s);
111 void sendFatalError(KRemoteView::ErrorCode s);
113 public:
114 ControllerThread(KVncView *v, WriterThread &wt, volatile bool &quitFlag);
115 KRemoteView::RemoteStatus status();
116 void desktopInit();
117 void kick();
119 protected:
120 void run();
125 #endif