view src/main/java/jp/ac/u_ryukyu/alicevnc/ReceiveAliceVNCMessage.java @ 56:9f1289c78b22

update maven change compressed DSM to only pixelData
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Mon, 16 Nov 2015 23:19:26 +0900
parents 57ca704f86a3
children fe627049e289 4a8755a30aa8
line wrap: on
line source

package jp.ac.u_ryukyu.alicevnc;

import java.util.List;

import jp.ac.u_ryukyu.alicevnc.AliceVNCMessage.MessageType;
import alice.codesegment.CodeSegment;
import alice.datasegment.CommandType;
import alice.datasegment.Receiver;

public class ReceiveAliceVNCMessage extends CodeSegment {
    private Receiver info = ids.create(CommandType.TAKE);
    private Receiver info1 = ids.create(CommandType.PEEK); // connection list

    public ReceiveAliceVNCMessage() {
        info.setKey("AliceVNCMessage");
        info1.setKey("_CLIST");
    }

    @Override
    public void run() {
        AliceVNCMessage order = info.asClass(AliceVNCMessage.class);

        @SuppressWarnings("unchecked")
        List<String> clist = info1.asClass(List.class);
        if (order.messageID == MessageType.ChangeRequest.getId()||
                order.messageID == MessageType.CurrentVNCInfo.getId()) {
            if (clist.contains("parent")){
                order.route.add(info.from);
                ods.put("parent", "AliceVNCMessage", order);
                new ReceiveAliceVNCMessage();
            } else { // this node is root.
                order.route.add(info.from);
                if (order.messageID == MessageType.CurrentVNCInfo.getId()) {
                    ods.put("currentServer", order);
                    new ReceiveAliceVNCMessage();
                } else {
                    new CheckCurrentInfo(order); // check change Server flag.
                }
            }
        } else if (order.messageID == MessageType.StartNegotiate.getId()||
                   order.messageID == MessageType.StopProxy.getId()||
                   order.messageID == MessageType.DeniedRequest.getId()) {
            if (order.route.size() == 0) {
                // this node send ChangeVNCRequest
                if (order.messageID == MessageType.StartNegotiate.getId()){
                    // negotiate VNCServer by Viewer
                    ods.put("vncRight", true);
                    new NegotiateVNCServer();
                    new ReceiveAliceVNCMessage();
                } else if(order.messageID == MessageType.StopProxy.getId()) {
                    new StopProxy();
                } else if (order.messageID == MessageType.DeniedRequest.getId()) {
                    // pop up window or message
                }
            } else {
                String address = order.getNextAddress();
                ods.put(address, "AliceVNCMessage", order);
                new ReceiveAliceVNCMessage();
            }
        }
    }
}