2007 年 2 月 13 日 23 時 54 分

とりあえずメッセージクラスから


このアーカイブは同期化されません。 mixi の日記が更新されても、このアーカイブには反映されません。


とりあえず FramebufferUpdateMessage の枠組みを作る。

更新領域を UpdateRectangle クラスに分離すれば、
FramebufferUpdateMessage 自体はシンプルに書けそうだ。

========== FramebufferUpdateMessage.java ==========

package jp.loafer.rfb.message.server;

import java.io.IOException;

import jp.loafer.rfb.RFBContext;
import jp.loafer.rfb.io.RFBInputStream;
import jp.loafer.rfb.io.RFBOutputStream;
import jp.loafer.rfb.message.UpdateRectangle;

/**
* FramebufferUpdate サーバメッセージ。
* @author kes
*/
public class FramebufferUpdateMessage extends BaseServerMessage {

    /**
     * 永続化用既定コンストラクタ。
     */
    public FramebufferUpdateMessage() {
        super();
    }

    /**
     * {@link FramebufferUpdateMessage} のインスタンスを作成。
     * @param rectangles 更新領域情報配列。
     */
    public FramebufferUpdateMessage(UpdateRectangle[] rectangles) {
        super();
        this.rectangles = rectangles;
    }
   
    /**
     * 更新領域情報の配列を取得。
     * @return 更新領域情報の配列。
     */
    public UpdateRectangle[] getRectangles() {
        return rectangles.clone();
    }
    /**
     * 更新領域情報の要素を取得。
     * @param index 0 ベースのインデックス。
     * @return 更新領域情報。
     */
    public UpdateRectangle getRectangles(int index) {
        return rectangles[index];
    }

    /**
     * @see ServerMessage#getType()
     */
    public int getType() {
        return ServerMessage.FRAMEBUFFER_UPDATE;
    }

    /**
     * @see ServerMessage#read(RFBContext, RFBInputStream)
     */
    @Override
    public void read(RFBContext context, RFBInputStream in) throws IOException {

        // 未実装
        throw new UnsupportedOperationException();
    }

    /**
     * @see ServerMessage#write(RFBContext, RFBOutputStream)
     */
    @Override
    public void write(RFBContext context, RFBOutputStream out) throws IOException {
        super.write(context, out);

        out.writeU8(0);
        out.writeU16(rectangles.length);
        for (int i = 0; i < rectangles.length; ++i) {
            out.writeMessage(context, rectangles[i]);
        }
    }

    private UpdateRectangle[] rectangles;

}


========== end of FramebufferUpdateMessage.java ==========

今回は RFB サーバなので手を抜いて、
書き出しだけを実装することにした。

というのも、可変長のデータ構造を読み出すためには、
事前にデータの特徴を理解した上で先読みし、
メッセージの区切り位置を検出する処理が必要なのだが、
そこまでやるとかなり骨が折れるのでやめとこう。



Copyright (c) 1994-2007 Project Loafer. All rights reserved.