mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
CLOUDSTACK-61 Console proxy has plenty of files with CRLF line ending.
This commit is contained in:
parent
f03d438c4c
commit
0bf8c5a18f
@ -30,8 +30,8 @@ import com.cloud.consoleproxy.util.ImageHelper;
|
||||
import com.cloud.consoleproxy.util.TileInfo;
|
||||
|
||||
/**
|
||||
* A <code>BuffereImageCanvas</code> component represents frame buffer image on the
|
||||
* screen. It also notifies its subscribers when screen is repainted.
|
||||
* A <code>BuffereImageCanvas</code> component represents frame buffer image on
|
||||
* the screen. It also notifies its subscribers when screen is repainted.
|
||||
*/
|
||||
public class BufferedImageCanvas extends Canvas implements FrameBufferCanvas {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@ -75,7 +75,7 @@ public class BufferedImageCanvas extends Canvas implements FrameBufferCanvas {
|
||||
public void paint(Graphics g) {
|
||||
// Only part of image, requested with repaint(Rectangle), will be
|
||||
// painted on screen.
|
||||
synchronized(offlineImage) {
|
||||
synchronized (offlineImage) {
|
||||
g.drawImage(offlineImage, 0, 0, this);
|
||||
}
|
||||
// Notify server that update is painted on screen
|
||||
@ -91,15 +91,14 @@ public class BufferedImageCanvas extends Canvas implements FrameBufferCanvas {
|
||||
}
|
||||
|
||||
public void copyTile(Graphics2D g, int x, int y, Rectangle rc) {
|
||||
synchronized(offlineImage) {
|
||||
g.drawImage(offlineImage, x, y, x + rc.width, y + rc.height,
|
||||
rc.x, rc.y, rc.x + rc.width, rc.y + rc.height, null);
|
||||
synchronized (offlineImage) {
|
||||
g.drawImage(offlineImage, x, y, x + rc.width, y + rc.height, rc.x, rc.y, rc.x + rc.width, rc.y + rc.height, null);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Image getFrameBufferScaledImage(int width, int height) {
|
||||
if(offlineImage != null)
|
||||
if (offlineImage != null)
|
||||
return offlineImage.getScaledInstance(width, height, Image.SCALE_DEFAULT);
|
||||
return null;
|
||||
}
|
||||
@ -112,10 +111,9 @@ public class BufferedImageCanvas extends Canvas implements FrameBufferCanvas {
|
||||
width = offlineImage.getWidth();
|
||||
height = offlineImage.getHeight();
|
||||
|
||||
BufferedImage bufferedImage = new BufferedImage(width, height,
|
||||
BufferedImage.TYPE_3BYTE_BGR);
|
||||
BufferedImage bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR);
|
||||
Graphics2D g = bufferedImage.createGraphics();
|
||||
synchronized(offlineImage) {
|
||||
synchronized (offlineImage) {
|
||||
g.drawImage(offlineImage, 0, 0, width, height, 0, 0, width, height, null);
|
||||
}
|
||||
|
||||
@ -129,17 +127,15 @@ public class BufferedImageCanvas extends Canvas implements FrameBufferCanvas {
|
||||
|
||||
@Override
|
||||
public byte[] getTilesMergedJpeg(List<TileInfo> tileList, int tileWidth, int tileHeight) {
|
||||
int width = Math.max(tileWidth, tileWidth*tileList.size());
|
||||
BufferedImage bufferedImage = new BufferedImage(width, tileHeight,
|
||||
BufferedImage.TYPE_3BYTE_BGR);
|
||||
int width = Math.max(tileWidth, tileWidth * tileList.size());
|
||||
BufferedImage bufferedImage = new BufferedImage(width, tileHeight, BufferedImage.TYPE_3BYTE_BGR);
|
||||
Graphics2D g = bufferedImage.createGraphics();
|
||||
|
||||
synchronized(offlineImage) {
|
||||
synchronized (offlineImage) {
|
||||
int i = 0;
|
||||
for(TileInfo tile : tileList) {
|
||||
for (TileInfo tile : tileList) {
|
||||
Rectangle rc = tile.getTileRect();
|
||||
g.drawImage(offlineImage, i*tileWidth, 0, i*tileWidth + rc.width, rc.height,
|
||||
rc.x, rc.y, rc.x + rc.width, rc.y + rc.height, null);
|
||||
g.drawImage(offlineImage, i * tileWidth, 0, i * tileWidth + rc.width, rc.height, rc.x, rc.y, rc.x + rc.width, rc.y + rc.height, null);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,6 +23,8 @@ import com.cloud.consoleproxy.util.TileInfo;
|
||||
|
||||
public interface FrameBufferCanvas {
|
||||
Image getFrameBufferScaledImage(int width, int height);
|
||||
|
||||
public byte[] getFrameBufferJpeg();
|
||||
|
||||
public byte[] getTilesMergedJpeg(List<TileInfo> tileList, int tileWidth, int tileHeight);
|
||||
}
|
||||
|
||||
@ -19,8 +19,8 @@ package com.cloud.consoleproxy.vnc;
|
||||
public interface FrameBufferUpdateListener {
|
||||
|
||||
/**
|
||||
* Notify listener, that frame buffer update packet is received, so client is
|
||||
* permitted (but not obligated) to ask server to send another update.
|
||||
* Notify listener, that frame buffer update packet is received, so client
|
||||
* is permitted (but not obligated) to ask server to send another update.
|
||||
*/
|
||||
void frameBufferPacketReceived();
|
||||
}
|
||||
|
||||
@ -19,8 +19,8 @@ package com.cloud.consoleproxy.vnc;
|
||||
public interface PaintNotificationListener {
|
||||
|
||||
/**
|
||||
* Notify subscriber that screen is updated, so client can send another frame
|
||||
* buffer update request to server.
|
||||
* Notify subscriber that screen is updated, so client can send another
|
||||
* frame buffer update request to server.
|
||||
*/
|
||||
void imagePaintedOnScreen();
|
||||
|
||||
|
||||
@ -21,7 +21,7 @@ import java.nio.charset.Charset;
|
||||
public interface RfbConstants {
|
||||
|
||||
public static final String RFB_PROTOCOL_VERSION_MAJOR = "RFB 003.";
|
||||
// public static final String VNC_PROTOCOL_VERSION_MINOR = "003";
|
||||
// public static final String VNC_PROTOCOL_VERSION_MINOR = "003";
|
||||
public static final String VNC_PROTOCOL_VERSION_MINOR = "003";
|
||||
public static final String RFB_PROTOCOL_VERSION = RFB_PROTOCOL_VERSION_MAJOR + VNC_PROTOCOL_VERSION_MINOR;
|
||||
|
||||
@ -33,8 +33,8 @@ public interface RfbConstants {
|
||||
/**
|
||||
* Client message types.
|
||||
*/
|
||||
public static final int CLIENT_SET_PIXEL_FORMAT = 0, CLIENT_FIX_COLOURMAP_ENTRIES = 1, CLIENT_SET_ENCODINGS = 2, CLIENT_FRAMEBUFFER_UPDATE_REQUEST = 3,
|
||||
CLIENT_KEYBOARD_EVENT = 4, CLIENT_POINTER_EVENT = 5, CLIENT_CUT_TEXT = 6;
|
||||
public static final int CLIENT_SET_PIXEL_FORMAT = 0, CLIENT_FIX_COLOURMAP_ENTRIES = 1, CLIENT_SET_ENCODINGS = 2, CLIENT_FRAMEBUFFER_UPDATE_REQUEST = 3, CLIENT_KEYBOARD_EVENT = 4,
|
||||
CLIENT_POINTER_EVENT = 5, CLIENT_CUT_TEXT = 6;
|
||||
|
||||
/**
|
||||
* Server authorization type
|
||||
@ -54,7 +54,7 @@ public interface RfbConstants {
|
||||
/**
|
||||
* Pseudo-encodings.
|
||||
*/
|
||||
public final static int ENCODING_CURSOR = -239 /*0xFFFFFF11*/, ENCODING_DESKTOP_SIZE = -223 /*0xFFFFFF21*/;
|
||||
public final static int ENCODING_CURSOR = -239 /* 0xFFFFFF11 */, ENCODING_DESKTOP_SIZE = -223 /* 0xFFFFFF21 */;
|
||||
|
||||
/**
|
||||
* Encodings, which we support.
|
||||
@ -62,7 +62,8 @@ public interface RfbConstants {
|
||||
public final static int[] SUPPORTED_ENCODINGS_ARRAY = { ENCODING_RAW, ENCODING_COPY_RECT, ENCODING_DESKTOP_SIZE };
|
||||
|
||||
/**
|
||||
* Frame buffer update request type: update of whole screen or partial update.
|
||||
* Frame buffer update request type: update of whole screen or partial
|
||||
* update.
|
||||
*/
|
||||
public static final int FRAMEBUFFER_FULL_UPDATE_REQUEST = 0, FRAMEBUFFER_INCREMENTAL_UPDATE_REQUEST = 1;
|
||||
|
||||
|
||||
@ -90,8 +90,7 @@ public class VncClient {
|
||||
this.clientListener = clientListener;
|
||||
}
|
||||
|
||||
public VncClient(String host, int port, String password, boolean noUI, ConsoleProxyClientListener clientListener)
|
||||
throws UnknownHostException, IOException {
|
||||
public VncClient(String host, int port, String password, boolean noUI, ConsoleProxyClientListener clientListener) throws UnknownHostException, IOException {
|
||||
|
||||
this.noUI = noUI;
|
||||
this.clientListener = clientListener;
|
||||
@ -99,27 +98,27 @@ public class VncClient {
|
||||
}
|
||||
|
||||
public void shutdown() {
|
||||
if(sender != null)
|
||||
if (sender != null)
|
||||
sender.closeConnection();
|
||||
|
||||
if(receiver != null)
|
||||
if (receiver != null)
|
||||
receiver.closeConnection();
|
||||
|
||||
if(is != null) {
|
||||
if (is != null) {
|
||||
try {
|
||||
is.close();
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
|
||||
if(os != null) {
|
||||
if (os != null) {
|
||||
try {
|
||||
os.close();
|
||||
} catch (Throwable e) {
|
||||
}
|
||||
}
|
||||
|
||||
if(socket != null) {
|
||||
if (socket != null) {
|
||||
try {
|
||||
socket.close();
|
||||
} catch (Throwable e) {
|
||||
@ -131,10 +130,9 @@ public class VncClient {
|
||||
return clientListener;
|
||||
}
|
||||
|
||||
public void connectTo(String host, int port, String path,
|
||||
String session, boolean useSSL, String sid) throws UnknownHostException, IOException {
|
||||
if(port < 0) {
|
||||
if(useSSL)
|
||||
public void connectTo(String host, int port, String path, String session, boolean useSSL, String sid) throws UnknownHostException, IOException {
|
||||
if (port < 0) {
|
||||
if (useSSL)
|
||||
port = 443;
|
||||
else
|
||||
port = 80;
|
||||
@ -175,7 +173,7 @@ public class VncClient {
|
||||
canvas.addKeyListener(sender);
|
||||
|
||||
Frame frame = null;
|
||||
if(!noUI)
|
||||
if (!noUI)
|
||||
frame = createVncClientMainWindow(canvas, screen.getDesktopName());
|
||||
|
||||
new Thread(sender).start();
|
||||
@ -185,7 +183,7 @@ public class VncClient {
|
||||
try {
|
||||
receiver.run();
|
||||
} finally {
|
||||
if(frame != null) {
|
||||
if (frame != null) {
|
||||
frame.setVisible(false);
|
||||
frame.dispose();
|
||||
}
|
||||
@ -355,7 +353,8 @@ public class VncClient {
|
||||
* bit. E.g. 01001100 will become 00110010.
|
||||
*
|
||||
* See also: http://www.vidarholen.net/contents/junk/vnc.html ,
|
||||
* http://bytecrafter .blogspot.com/2010/09/des-encryption-as-used-in-vnc.html
|
||||
* http://bytecrafter
|
||||
* .blogspot.com/2010/09/des-encryption-as-used-in-vnc.html
|
||||
*
|
||||
* @param b
|
||||
* a byte
|
||||
@ -388,7 +387,7 @@ public class VncClient {
|
||||
int framebufferWidth = is.readUnsignedShort();
|
||||
int framebufferHeight = is.readUnsignedShort();
|
||||
screen.setFramebufferSize(framebufferWidth, framebufferHeight);
|
||||
if(clientListener != null)
|
||||
if (clientListener != null)
|
||||
clientListener.onFramebufferSizeChange(framebufferWidth, framebufferHeight);
|
||||
}
|
||||
|
||||
@ -425,14 +424,14 @@ public class VncClient {
|
||||
}
|
||||
|
||||
public FrameBufferCanvas getFrameBufferCanvas() {
|
||||
if(receiver != null)
|
||||
if (receiver != null)
|
||||
return receiver.getCanvas();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public void requestUpdate(boolean fullUpdate) {
|
||||
if(fullUpdate)
|
||||
if (fullUpdate)
|
||||
sender.requestFullScreenUpdate();
|
||||
else
|
||||
sender.imagePaintedOnScreen();
|
||||
|
||||
@ -97,16 +97,14 @@ public class VncClientPacketSender implements Runnable, PaintNotificationListene
|
||||
}
|
||||
|
||||
public void requestFullScreenUpdate() {
|
||||
queue.add(new FramebufferUpdateRequestPacket(RfbConstants.FRAMEBUFFER_FULL_UPDATE_REQUEST, 0, 0, screen.getFramebufferWidth(), screen
|
||||
.getFramebufferHeight()));
|
||||
queue.add(new FramebufferUpdateRequestPacket(RfbConstants.FRAMEBUFFER_FULL_UPDATE_REQUEST, 0, 0, screen.getFramebufferWidth(), screen.getFramebufferHeight()));
|
||||
updateRequestSent = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void imagePaintedOnScreen() {
|
||||
if (!updateRequestSent) {
|
||||
queue.add(new FramebufferUpdateRequestPacket(RfbConstants.FRAMEBUFFER_INCREMENTAL_UPDATE_REQUEST, 0, 0, screen.getFramebufferWidth(), screen
|
||||
.getFramebufferHeight()));
|
||||
queue.add(new FramebufferUpdateRequestPacket(RfbConstants.FRAMEBUFFER_INCREMENTAL_UPDATE_REQUEST, 0, 0, screen.getFramebufferWidth(), screen.getFramebufferHeight()));
|
||||
updateRequestSent = true;
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,13 +41,12 @@ public class VncScreenDescription {
|
||||
/**
|
||||
* Store information about server pixel format.
|
||||
*/
|
||||
public void setPixelFormat(int bitsPerPixel, int depth, int bigEndianFlag, int trueColorFlag, int redMax, int greenMax, int blueMax, int redShift,
|
||||
int greenShift, int blueShift) {
|
||||
public void setPixelFormat(int bitsPerPixel, int depth, int bigEndianFlag, int trueColorFlag, int redMax, int greenMax, int blueMax, int redShift, int greenShift, int blueShift) {
|
||||
|
||||
bytesPerPixel = (bitsPerPixel + 7) / 8;
|
||||
|
||||
rgb888_32_le = (depth == 24 && bitsPerPixel == 32 && redShift == 16 && greenShift == 8 && blueShift == 0 && redMax == 255 && greenMax == 255
|
||||
&& blueMax == 255 && bigEndianFlag == RfbConstants.LITTLE_ENDIAN && trueColorFlag == RfbConstants.TRUE_COLOR);
|
||||
rgb888_32_le = (depth == 24 && bitsPerPixel == 32 && redShift == 16 && greenShift == 8 && blueShift == 0 && redMax == 255 && greenMax == 255 && blueMax == 255
|
||||
&& bigEndianFlag == RfbConstants.LITTLE_ENDIAN && trueColorFlag == RfbConstants.TRUE_COLOR);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@ -38,8 +38,8 @@ public class VncServerPacketReceiver implements Runnable {
|
||||
private final FrameBufferUpdateListener fburListener;
|
||||
private final ConsoleProxyClientListener clientListener;
|
||||
|
||||
public VncServerPacketReceiver(DataInputStream is, BufferedImageCanvas canvas, VncScreenDescription screen, VncClient vncConnection,
|
||||
FrameBufferUpdateListener fburListener, ConsoleProxyClientListener clientListener) {
|
||||
public VncServerPacketReceiver(DataInputStream is, BufferedImageCanvas canvas, VncScreenDescription screen, VncClient vncConnection, FrameBufferUpdateListener fburListener,
|
||||
ConsoleProxyClientListener clientListener) {
|
||||
this.screen = screen;
|
||||
this.canvas = canvas;
|
||||
this.is = is;
|
||||
@ -118,6 +118,6 @@ public class VncServerPacketReceiver implements Runnable {
|
||||
StringSelection contents = new StringSelection(clipboardContent.getContent());
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null);
|
||||
|
||||
s_logger.info("Server clipboard buffer: "+clipboardContent.getContent());
|
||||
s_logger.info("Server clipboard buffer: " + clipboardContent.getContent());
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,7 +39,6 @@ public class FramebufferUpdateRequestPacket implements ClientPacket {
|
||||
this.height = height;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream os) throws IOException {
|
||||
os.writeByte(RfbConstants.CLIENT_FRAMEBUFFER_UPDATE_REQUEST);
|
||||
|
||||
@ -25,22 +25,19 @@ public class SetEncodingsPacket implements ClientPacket {
|
||||
|
||||
private final int[] encodings;
|
||||
|
||||
public SetEncodingsPacket(int[] encodings)
|
||||
{
|
||||
public SetEncodingsPacket(int[] encodings) {
|
||||
this.encodings = encodings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream os) throws IOException
|
||||
{
|
||||
public void write(DataOutputStream os) throws IOException {
|
||||
os.writeByte(RfbConstants.CLIENT_SET_ENCODINGS);
|
||||
|
||||
os.writeByte(0);//padding
|
||||
os.writeByte(0);// padding
|
||||
|
||||
os.writeShort(encodings.length);
|
||||
|
||||
for(int i=0;i<encodings.length;i++)
|
||||
{
|
||||
for (int i = 0; i < encodings.length; i++) {
|
||||
os.writeInt(encodings[i]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,8 +28,8 @@ public class SetPixelFormatPacket implements ClientPacket {
|
||||
|
||||
private final VncScreenDescription screen;
|
||||
|
||||
public SetPixelFormatPacket(VncScreenDescription screen, int bitsPerPixel, int depth, int bigEndianFlag, int trueColorFlag, int redMax, int greenMax,
|
||||
int blueMax, int redShift, int greenShift, int blueShift) {
|
||||
public SetPixelFormatPacket(VncScreenDescription screen, int bitsPerPixel, int depth, int bigEndianFlag, int trueColorFlag, int redMax, int greenMax, int blueMax, int redShift, int greenShift,
|
||||
int blueShift) {
|
||||
this.screen = screen;
|
||||
this.bitsPerPixel = bitsPerPixel;
|
||||
this.depth = depth;
|
||||
|
||||
@ -33,8 +33,7 @@ public class FramebufferUpdatePacket {
|
||||
private final BufferedImageCanvas canvas;
|
||||
private final ConsoleProxyClientListener clientListener;
|
||||
|
||||
public FramebufferUpdatePacket(BufferedImageCanvas canvas, VncScreenDescription screen, DataInputStream is,
|
||||
ConsoleProxyClientListener clientListener) throws IOException {
|
||||
public FramebufferUpdatePacket(BufferedImageCanvas canvas, VncScreenDescription screen, DataInputStream is, ConsoleProxyClientListener clientListener) throws IOException {
|
||||
|
||||
this.screen = screen;
|
||||
this.canvas = canvas;
|
||||
@ -75,7 +74,7 @@ public class FramebufferUpdatePacket {
|
||||
|
||||
case RfbConstants.ENCODING_DESKTOP_SIZE: {
|
||||
rect = new FrameBufferSizeChangeRequest(canvas, width, height);
|
||||
if(this.clientListener != null)
|
||||
if (this.clientListener != null)
|
||||
this.clientListener.onFramebufferSizeChange(width, height);
|
||||
break;
|
||||
}
|
||||
@ -86,7 +85,7 @@ public class FramebufferUpdatePacket {
|
||||
|
||||
paint(rect, canvas);
|
||||
|
||||
if(this.clientListener != null)
|
||||
if (this.clientListener != null)
|
||||
this.clientListener.onFramebufferUpdate(rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
|
||||
}
|
||||
|
||||
|
||||
@ -69,8 +69,7 @@ public class RawRect extends AbstractRect {
|
||||
}
|
||||
|
||||
default:
|
||||
throw new RuntimeException("Unsupported data buffer in buffered image: expected data buffer of type int (DataBufferInt). Actual data buffer type: "
|
||||
+ dataBuf.getClass().getSimpleName());
|
||||
throw new RuntimeException("Unsupported data buffer in buffered image: expected data buffer of type int (DataBufferInt). Actual data buffer type: " + dataBuf.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -24,7 +24,10 @@ public interface Rect {
|
||||
void paint(BufferedImage offlineImage, Graphics2D graphics);
|
||||
|
||||
int getX();
|
||||
|
||||
int getY();
|
||||
|
||||
int getWidth();
|
||||
|
||||
int getHeight();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user