summaryrefslogtreecommitdiffstats
path: root/krdc/vnc/threads.h
blob: 4bb77ef3bed527f9e79aae0425de2dd79b42879f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/***************************************************************************
                          threads.h  -  threads for kvncview
                             -------------------
    begin                : Thu May 09 16:01:42 CET 2002
    copyright            : (C) 2002 by Tim Jansen
    email                : tim@tjansen.de
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef THREADS_H
#define THREADS_H

#include <tqthread.h>
#include <tqregion.h>
#include <tqrect.h>
#include <tqmutex.h>
#include <tqwaitcondition.h>
#include <tqevent.h>
#include <tqvaluelist.h>
#include <tqdatetime.h>

#include <stdlib.h> 

#include "events.h"
#include "vnctypes.h"

class KVncView;

enum EventType {
	MouseEventType,
	KeyEventType
};


struct MouseEvent {
	int x, y, buttons;
};

struct KeyEvent {
	unsigned int k;
	bool down;
};

struct InputEvent {
	EventType type;
	union {
		MouseEvent m;
		KeyEvent k;
	} e;
};


class WriterThread : public TQThread {
private:
	TQMutex m_lock;
	TQWaitCondition m_waiter;
	volatile bool &m_quitFlag;
	KVncView *m_view;

	TQTime m_lastIncrUpdate; // start()ed when a incr update is sent
	bool m_lastIncrUpdatePostponed;

	// all things that can be send follow:
	bool m_incrementalUpdateRQ; // for sending an incremental request
	bool m_incrementalUpdateAnnounced; // set when a RQ will come soon
	TQRegion m_updateRegionRQ;  // for sending updates, null if it is done
	TQValueList<InputEvent> m_inputEvents; // list of unsent input events
	MouseEvent m_lastMouseEvent;
	int m_mouseEventNum, m_keyEventNum;
	TQString m_clientCut;

	void sendFatalError(ErrorCode s);

public:
	WriterThread(KVncView *v, volatile bool &quitFlag);
	
	void queueIncrementalUpdateRequest();
	void announceIncrementalUpdateRequest();
	void queueUpdateRequest(const TQRegion &r);
	void queueMouseEvent(int x, int y, int buttonMask);
	void queueKeyEvent(unsigned int k, bool down);
	void queueClientCut(const TQString &text);
	void kick();
	
protected:
	void run();
	bool sendIncrementalUpdateRequest();
	bool sendUpdateRequest(const TQRegion &r);
	bool sendInputEvents(const TQValueList<InputEvent> &events);
};



class ControllerThread : public TQThread { 
private:
	KVncView *m_view;
	enum RemoteViewtqStatus m_status;
	WriterThread &m_wthread;
	volatile bool &m_quitFlag;
	volatile bool m_desktopInitialized;
	TQWaitCondition m_waiter;

	void changetqStatus(RemoteViewtqStatus s);
	void sendFatalError(ErrorCode s);

public:
	ControllerThread(KVncView *v, WriterThread &wt, volatile bool &quitFlag);
	enum RemoteViewtqStatus status();	
	void desktopInit();
	void kick();

protected:
	void run();
};



#endif