view src/main/java/com/glavsoft/rfb/encoding/decoder/ZRLEESender.java @ 166:26bc52699cf3

send initData to lower node.
author oc
date Thu, 19 Jun 2014 17:19:59 +0900
parents ada4d850a820
children 34b7558aeffa
line wrap: on
line source

package com.glavsoft.rfb.encoding.decoder;

import jp.ac.u_ryukyu.treevnc.MyRfbProto;

import com.glavsoft.drawing.Renderer;
import com.glavsoft.exceptions.TransportException;
import com.glavsoft.rfb.encoding.EncodingType;
import com.glavsoft.transport.Reader;

public class ZRLEESender extends Decoder {

	private MyRfbProto rfb;

	public ZRLEESender(MyRfbProto rfb) {
		this.rfb = rfb;
	}

	public ZRLEESender() {
	}

	@Override
	public void decode(Reader reader, Renderer renderer,
			FramebufferUpdateRectangle rect) throws TransportException {
		int dataLen = getZrleLength(rect, reader);
		reader.reset();
		// TreeVNC handling
		rfb.readSendData(dataLen, reader);
		// reader is reseted read again

		if (! rfb.isRoot()) {
			reader.reset();
		    // decode data when it is a client
			reader.readBytes(8);
			reader.readByte();// message
			reader.readByte();// padding
			reader.readUInt16();// numberOfRectangle
			rect.fill(reader);// fill
			Decoder decoder = new ZRLEDecoder();
			if (!rfb.getCuiVersion())
				decoder.decode(reader, renderer, rect);
			else {
				reader.readBytes((int) reader.readUInt32());
			}
		}
	}

	private int getZrleLength(FramebufferUpdateRectangle rect, Reader reader)
			throws TransportException {
		int zrleLength = 0;
		if (rect.getEncodingType() == EncodingType.ZRLE
				|| rect.getEncodingType() == EncodingType.ZRLEE
				|| rect.getEncodingType() == EncodingType.ZLIB) {
			zrleLength = reader.readInt32();
		}
		return zrleLength + 20;
	}

	public void readCheckDelay(Reader reader) {
		try {
			reader.reset();
			rfb.readCheckDelay(reader);
		} catch (TransportException e) {
			e.printStackTrace();
		}
	}
}