view datagear/command/CommandType.cs @ 8:e6f5b7d14dd1

update DataGears
author riono <e165729@ie.u-ryukyu.ac.jp>
date Mon, 12 Oct 2020 00:49:32 +0900
parents 5c334a1fbc5e
children ce6906edcbf4
line wrap: on
line source

using System;
using System.Collections.Generic;

namespace Christie_net.datagear.command {
public enum CommandType {
    PUT,
    TAKE,
    PEEK,
    REMOTETAKE,
    REMOTEPEEK,
    REPLY,
    CLOSE,
    FINISH
}

public static class CommandTypeEtx {
    public static int id; // command ID
    public static Dictionary<int, CommandType> hash = new Dictionary<int, CommandType>();
    private static int lastID; // total command number

    static CommandTypeEtx() {
        StoreValues();
        id = IncrementLastID();
    }

    private static int IncrementLastID() {
        return ++lastID;
    }

    public static CommandType GetCommandTypeFromID(int id) {
        return hash[id];
    }

    public static void StoreValues() {
        foreach (CommandType value in Enum.GetValues(typeof(CommandType))) hash.Add(Convert.ToInt32(value), value);
    }
}
}