001: ///////////////////////////////////////////////////////////////////////////////
002: //
003: // This program is free software; you can redistribute it and/or modify
004: // it under the terms of the GNU General Public License and GNU Library
005: // General Public License as published by the Free Software Foundation;
006: // either version 2, or (at your option) any later version.
007: //
008: // This program is distributed in the hope that it will be useful,
009: // but WITHOUT ANY WARRANTY; without even the implied warranty of
010: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
011: // GNU General Public License and GNU Library General Public License
012: // for more details.
013: //
014: // You should have received a copy of the GNU General Public License
015: // and GNU Library General Public License along with this program; if
016: // not, write to the Free Software Foundation, 675 Mass Ave, Cambridge,
017: // MA 02139, USA.
018: //
019: ///////////////////////////////////////////////////////////////////////////////
020:
021: package org.rdesktop.server.rdp;
022:
023: import java.io.*;
024: import java.net.*;
025:
026: import java.awt.*;
027: import java.awt.image.*;
028:
029: import org.rdesktop.server.rdp.crypto.*;
030: import org.rdesktop.server.rdp.rdp5.VChannels;
031:
032: public class RdpClient extends RdpProto {
033: public static final int SEND_QUEUE_DEPTH = 10;
034: public static final int SEND_QUEUE_HOLD_OFF_TIME = 100;
035:
036: public static final int CLIENT_HOLD_COUNT = 3;
037: public static final int CLIENT_MIN_QUEUE_SIZE = 1;
038: public static final int CLIENT_MAX_QUEUE_SIZE = 15;
039: public static final int CLIENT_QUEUE_OFFSET = 2500;
040: public static final int CLIENT_QUEUE_MAX_BUFFER_SIZE = 2500;
041:
042: private java.util.LinkedList m_sendQueue = null;
043: private java.util.LinkedList m_receiveQueue = null;
044: private org.rdesktop.objects.RdpDesktopExchange m_exchange;
045:
046: public RdpClient(org.rdesktop.objects.RdpDesktopExchange exchange) {
047: m_exchange = exchange;
048: }
049:
050: public void connect(String host, int port, String username,
051: String password, int flags, String domain, int width,
052: int height, int bitsPerPixel) throws RdpDesktopException,
053: RdpConnectionException {
054: m_exchange.connect(host, port, username, password, flags,
055: domain, width, height, bitsPerPixel);
056: m_connected = true;
057: }
058:
059: public void disconnect() {
060: m_exchange.disconnect();
061: m_connected = false;
062: }
063:
064: public RdpPacket receive(int[] type) throws IOException,
065: RdpDesktopException, CryptoException, RdpOrderException {
066: while ((m_receiveQueue == null) || (m_receiveQueue.size() == 0)) {
067: m_receiveQueue = m_exchange.receiveQueue();
068:
069: if ((m_receiveQueue == null)
070: || (m_receiveQueue.size() == 0)) {
071: return null;
072: }
073: }
074:
075: Object[] tuple = (Object[]) m_receiveQueue.removeFirst();
076: RdpPacket data = (RdpPacket) tuple[0];
077: type[0] = ((Integer) tuple[1]).intValue();
078: m_next_packet = ((Integer) tuple[2]).intValue();
079:
080: return data;
081: }
082:
083: public void sendLogonInfo(int flags, String domain,
084: String username, String password, String command,
085: String directory) throws RdpDesktopException, IOException,
086: CryptoException {
087: m_exchange.sendLogonInfo(flags, domain, username, password,
088: command, directory);
089: }
090:
091: public void sendConfirmActive(int rdp_shareid)
092: throws RdpDesktopException, IOException, CryptoException {
093: m_exchange.sendConfirmActive(rdp_shareid);
094: }
095:
096: public void sendSynchronize() throws RdpDesktopException,
097: IOException, CryptoException {
098: m_exchange.sendSynchronize();
099: }
100:
101: public void sendControl(int action) throws RdpDesktopException,
102: IOException, CryptoException {
103: m_exchange.sendControl(action);
104: }
105:
106: public void sendInput(int time, int message_type, int device_flags,
107: int param1, int param2) {
108: if (m_sendQueue == null) {
109: m_sendQueue = new java.util.LinkedList();
110:
111: Runnable drain = new Runnable() {
112: public void run() {
113: try {
114: while (m_sendQueue != null) {
115: if (m_sendQueue.size() < SEND_QUEUE_DEPTH) {
116: Thread.sleep(SEND_QUEUE_HOLD_OFF_TIME);
117: }
118:
119: synchronized (m_sendQueue) {
120: if (m_sendQueue.size() != 0) {
121: m_exchange
122: .sendInputQueue(m_sendQueue);
123: m_sendQueue.clear();
124: }
125: }
126: }
127: } catch (Exception e) {
128: e.printStackTrace();
129: }
130: }
131: };
132:
133: Thread thread = new Thread(drain, "Send Drain");
134: thread.setDaemon(true);
135: thread.start();
136: }
137:
138: synchronized (m_sendQueue) {
139: m_sendQueue.add(new Object[] { new Integer(time),
140: new Integer(message_type),
141: new Integer(device_flags), new Integer(param1),
142: new Integer(param2) });
143: }
144: }
145:
146: public void sendFonts(int seq) throws RdpDesktopException,
147: IOException, CryptoException {
148: m_exchange.sendFonts(seq);
149: }
150: }
|