blob: 10c377a762101dcf3122766fec56c61f54f4ee68 [file] [log] [blame]
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +00001/* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
Brian Hinzaf15db22012-02-12 20:44:29 +00002 * Copyright 2009-2011 Pierre Ossman for Cendio AB
Brian Hinzb213da62012-04-11 22:00:55 +00003 * Copyright (C) 2011 Brian P. Hinz
Brian Hinzc0a36092013-05-12 15:46:09 +00004 *
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +00005 * This is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
Brian Hinzc0a36092013-05-12 15:46:09 +00009 *
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000010 * This software is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Brian Hinzc0a36092013-05-12 15:46:09 +000014 *
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000015 * You should have received a copy of the GNU General Public License
16 * along with this software; if not, write to the Free Software
Brian Hinzb213da62012-04-11 22:00:55 +000017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000018 * USA.
19 */
20
DRCc5dc0382011-05-13 21:42:14 +000021package com.tigervnc.rfb;
Constantin Kaplinsky90d8a502008-04-14 09:45:50 +000022
DRCc5dc0382011-05-13 21:42:14 +000023import com.tigervnc.rdr.*;
Brian Hinze7681412011-05-17 21:00:34 +000024import java.util.*;
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000025
DRCc5dc0382011-05-13 21:42:14 +000026public class CMsgWriterV3 extends CMsgWriter {
27
28 public CMsgWriterV3(ConnParams cp_, OutStream os_) { super(cp_, os_); }
29
Brian Hinz28aa3a82012-04-05 02:08:49 +000030 synchronized public void writeClientInit(boolean shared) {
DRCc5dc0382011-05-13 21:42:14 +000031 os.writeU8(shared?1:0);
32 endMsg();
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000033 }
34
Brian Hinz28aa3a82012-04-05 02:08:49 +000035 synchronized public void startMsg(int type) {
DRCc5dc0382011-05-13 21:42:14 +000036 os.writeU8(type);
37 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000038
Brian Hinz28aa3a82012-04-05 02:08:49 +000039 synchronized public void endMsg() {
DRCc5dc0382011-05-13 21:42:14 +000040 os.flush();
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +000041 }
Brian Hinze7681412011-05-17 21:00:34 +000042
Brian Hinz28aa3a82012-04-05 02:08:49 +000043 synchronized public void writeSetDesktopSize(int width, int height,
Brian Hinze7681412011-05-17 21:00:34 +000044 ScreenSet layout)
45 {
46 if (!cp.supportsSetDesktopSize)
47 throw new Exception("Server does not support SetDesktopSize");
Brian Hinzc0a36092013-05-12 15:46:09 +000048
Brian Hinze7681412011-05-17 21:00:34 +000049 startMsg(MsgTypes.msgTypeSetDesktopSize);
50 os.pad(1);
Brian Hinzc0a36092013-05-12 15:46:09 +000051
Brian Hinze7681412011-05-17 21:00:34 +000052 os.writeU16(width);
53 os.writeU16(height);
Brian Hinzc0a36092013-05-12 15:46:09 +000054
Brian Hinze7681412011-05-17 21:00:34 +000055 os.writeU8(layout.num_screens());
56 os.pad(1);
Brian Hinzc0a36092013-05-12 15:46:09 +000057
Brian Hinzd93a26d2012-12-14 22:40:02 +000058 for (Iterator<Screen> iter = layout.screens.iterator(); iter.hasNext(); ) {
Brian Hinze7681412011-05-17 21:00:34 +000059 Screen refScreen = (Screen)iter.next();
60 os.writeU32(refScreen.id);
61 os.writeU16(refScreen.dimensions.tl.x);
62 os.writeU16(refScreen.dimensions.tl.y);
63 os.writeU16(refScreen.dimensions.width());
64 os.writeU16(refScreen.dimensions.height());
65 os.writeU32(refScreen.flags);
66 }
Brian Hinzc0a36092013-05-12 15:46:09 +000067
Brian Hinze7681412011-05-17 21:00:34 +000068 endMsg();
69 }
Brian Hinzaf15db22012-02-12 20:44:29 +000070
Brian Hinz28aa3a82012-04-05 02:08:49 +000071 synchronized public void writeFence(int flags, int len, byte[] data)
Brian Hinzaf15db22012-02-12 20:44:29 +000072 {
73 if (!cp.supportsFence)
74 throw new Exception("Server does not support fences");
75 if (len > 64)
76 throw new Exception("Too large fence payload");
77 if ((flags & ~fenceTypes.fenceFlagsSupported) != 0)
78 throw new Exception("Unknown fence flags");
Brian Hinzc0a36092013-05-12 15:46:09 +000079
Brian Hinzaf15db22012-02-12 20:44:29 +000080 startMsg(MsgTypes.msgTypeClientFence);
81 os.pad(3);
Brian Hinzc0a36092013-05-12 15:46:09 +000082
Brian Hinzaf15db22012-02-12 20:44:29 +000083 os.writeU32(flags);
Brian Hinzc0a36092013-05-12 15:46:09 +000084
Brian Hinzaf15db22012-02-12 20:44:29 +000085 os.writeU8(len);
86 os.writeBytes(data, 0, len);
Brian Hinzc0a36092013-05-12 15:46:09 +000087
Brian Hinzaf15db22012-02-12 20:44:29 +000088 endMsg();
89 }
Brian Hinzc0a36092013-05-12 15:46:09 +000090
Brian Hinz28aa3a82012-04-05 02:08:49 +000091 synchronized public void writeEnableContinuousUpdates(boolean enable,
Brian Hinzaf15db22012-02-12 20:44:29 +000092 int x, int y, int w, int h)
93 {
94 if (!cp.supportsContinuousUpdates)
95 throw new Exception("Server does not support continuous updates");
Brian Hinzc0a36092013-05-12 15:46:09 +000096
Brian Hinzaf15db22012-02-12 20:44:29 +000097 startMsg(MsgTypes.msgTypeEnableContinuousUpdates);
Brian Hinzc0a36092013-05-12 15:46:09 +000098
Brian Hinzaf15db22012-02-12 20:44:29 +000099 os.writeU8((enable?1:0));
Brian Hinzc0a36092013-05-12 15:46:09 +0000100
Brian Hinzaf15db22012-02-12 20:44:29 +0000101 os.writeU16(x);
102 os.writeU16(y);
103 os.writeU16(w);
104 os.writeU16(h);
Brian Hinzc0a36092013-05-12 15:46:09 +0000105
Brian Hinzaf15db22012-02-12 20:44:29 +0000106 endMsg();
107 }
Constantin Kaplinsky2844fd52008-04-14 08:02:25 +0000108}