view src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveUpdateRectangle.java @ 34:aace9df1462e

refactor
author sugi
date Thu, 13 Nov 2014 16:09:09 +0900
parents 6f5986d8ecd5
children 1fa4b7b8d19f
line wrap: on
line source

package jp.ac.u_ryukyu.alicevnc;

import java.util.ArrayList;

import jp.ac.u_ryukyu.ie.cr.DecodeInfomation;

import com.glavsoft.exceptions.TransportException;
import com.glavsoft.rfb.encoding.EncodingType;
import com.glavsoft.rfb.encoding.decoder.FramebufferUpdateRectangle;
import com.glavsoft.rfb.encoding.decoder.RichCursorDecoder;
import com.glavsoft.rfb.encoding.decoder.ZRLEDecoder;

import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;

public class ReceiveUpdateRectangle extends CodeSegment{

    private Receiver info = ids.create(CommandType.PEEK);
    private Receiver info1 = ids.create(CommandType.TAKE); // AliceVNC Message
    private Receiver info2 = ids.create(CommandType.TAKE);
    private Receiver info3 = ids.create(CommandType.PEEK);

    public ReceiveUpdateRectangle(){
        info.setKey("holder");
        info1.setKey("updateRectangle");
        info2.setKey("pixelData");
        info3.setKey("_CLIST");
    }

    @Override
    public void run() {
        // send other node
        @SuppressWarnings("unchecked")
        ArrayList<String> clist = info3.asClass(ArrayList.class);
        for (String node : clist){
            if (!info1.from.equals(node)) {
                // not need send data comes from
                // Data Segment from other node is already serialized
                ods.put(node, "updateRectangle", info1.getReceiveData());
                //ods.setCompressFlag(true);
                ods.put(node, "pixelData",  info2.getReceiveData());
                ods.setCompressFlag(false);
            }

        }

        try {
            RenderAndControllerHolder holder = info.asClass(RenderAndControllerHolder.class);
            DecodeInfomation message = info1.asClass(DecodeInfomation.class);

            if (message.getEncodingType() == EncodingType.ZRLEE){
                ZRLEDecoder decoder = new ZRLEDecoder();
                FramebufferUpdateRectangle rect = new FramebufferUpdateRectangle(
                        message.x, message.y, message.width, message.height);
                rect.encodingType = message.getEncodingType();
                byte[] buf = info2.asClass(byte[].class);

                // this method name is wrong.
                decoder.decode(holder.getRenderer(), rect, buf, 0);
                holder.getRepaintController().repaintBitmap(rect);

            } else if (message.getEncodingType() == EncodingType.DESKTOP_SIZE) {
                holder.setRenderer(
                        holder.getRepaintController().createRenderer(null, message.width,
                                message.height, message.getPixelFormat())
                                );
                boolean visible = true;
                if ("local".equals(info2.from)) {
                    visible = false;
                }
                holder.getViewerWindow().setVisible(visible);
            } else if (message.getEncodingType() == EncodingType.RICH_CURSOR) {
                byte[] buf = info2.asClass(byte[].class);
                RichCursorDecoder.getInstance().decode(holder.getRenderer(), message, buf);
                holder.getRepaintController().repaintCursor();

            }
            this.recycle();

        } catch (TransportException e) {
            e.printStackTrace();
        }
    }

}