changeset 9:ce6906edcbf4

fix DataGear<Type> to DataGear<object>
author riono <e165729@ie.u-ryukyu.ac.jp>
date Tue, 17 Nov 2020 18:46:22 +0900
parents e6f5b7d14dd1
children 5f726dc31874
files codegear/InputDataGear.cs datagear/DataGears.cs datagear/command/Command.cs datagear/command/CommandBuilder.cs datagear/command/CommandType.cs datagear/dg/DataGear.cs
diffstat 6 files changed, 80 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/codegear/InputDataGear.cs	Mon Oct 12 00:49:32 2020 +0900
+++ b/codegear/InputDataGear.cs	Tue Nov 17 18:46:22 2020 +0900
@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Concurrent;
 using System.Collections.Generic;
+using Christie_net.datagear.command;
 using Christie_net.datagear.dg;
 
 namespace Christie_net.codegear {
--- a/datagear/DataGears.cs	Mon Oct 12 00:49:32 2020 +0900
+++ b/datagear/DataGears.cs	Tue Nov 17 18:46:22 2020 +0900
@@ -5,8 +5,8 @@
 
 namespace Christie_net.datagear.dg {
 public class DataGears {
-    protected SortedDictionary<string, ConcurrentQueue<DataGear<Type>>> dataGears =
-        new SortedDictionary<string, ConcurrentQueue<DataGear<Type>>>();
+    protected SortedDictionary<string, ConcurrentQueue<DataGear<object>>> dataGears =
+        new SortedDictionary<string, ConcurrentQueue<DataGear<object>>>();
 
     private readonly object syncObject = new object();
 
@@ -15,12 +15,12 @@
     /// </summary>
     /// <param name="key"></param>
     /// <param name="dg"></param>
-    public void Put(string key, DataGear<Type> dg) {
+    public void Put(string key, DataGear<object> dg) {
         lock (syncObject) {
             if (dataGears.ContainsKey(key)) {
                 dataGears[key].Enqueue(dg);
             } else {
-                var queue = new ConcurrentQueue<DataGear<Type>>();
+                var queue = new ConcurrentQueue<DataGear<object>>();
                 queue.Enqueue(dg);
                 dataGears.Add(key, queue);
             }
@@ -35,7 +35,7 @@
     public object Take(string key) {
         object data = null;
         // Queueからの取得は参照渡し
-        DataGear<Type> dataGear;
+        DataGear<object> dataGear;
         if (dataGears[key].TryDequeue(out dataGear)) {
             data = dataGear.GetData();
         }
@@ -55,7 +55,7 @@
     /// <returns></returns>
     public object Peek(string key) {
         object data = null;
-        DataGear<Type> dataGear;
+        DataGear<object> dataGear;
         if (dataGears[key].TryPeek(out dataGear)) {
             data = dataGear.GetData();
         }
@@ -70,7 +70,7 @@
     /// <returns></returns>
     public object GetData(Command cm) {
         lock (syncObject) {
-            switch (cm.type) {
+            switch (cm.type.commandType) {
                 case CommandType.TAKE:
                 case CommandType.REMOTETAKE:
                     return Take(cm.key);
--- a/datagear/command/Command.cs	Mon Oct 12 00:49:32 2020 +0900
+++ b/datagear/command/Command.cs	Tue Nov 17 18:46:22 2020 +0900
@@ -1,36 +1,52 @@
 using System;
+using System.IO;
 using Christie_net.codegear;
 using Christie_net.datagear.dg;
 
 namespace Christie_net.datagear.command {
 public abstract class Command {
-    public CodeGear cg; // for localtake
-    public int cgmID = -1; // for localtake
-    public Type clazz; // for remote
-    public Connection connection = null; // for reply
-    public DataGear<Type> dg; // for put/localtake/reply
-    public string fromDgmName = "local"; // for remotetake/reply
+    public CommandTypeEtx type;
     public string key;
     public string toDgmName; // for take
-    public CommandType type;
+    public string fromDgmName = "local"; // for remotetake/reply
+    public int? cgmID = -1; // for localtake
+    public CodeGear cg; // for localtake
+    public DataGear<object> dg; // for put/localtake/reply
+    public Type clazz; // for remote
+    public Connection connection = null; // for reply
 
     public Command(CommandBuilder cb) {
-        type = type;
-        key = null;
-        toDgmName = null;
-        fromDgmName = "local";
-        cgmID = null;
-        cg = null;
-        dg = null;
-        clazz = null;
-        connection = null;
+        this.type = cb.type;
+        this.key = cb.key;
+        this.toDgmName = cb.toDgmName;
+        this.fromDgmName = cb.fromDgmname;
+        this.cgmID = cb.cgmID;
+        this.cg = cb.cg;
+        this.dg = cb.dg;
+        this.clazz = cb.clazz;
+        this.connection = cb.connection;
     }
 
     // instead of any Constoractor args
-    protected void CheckNeedParam(ComanndBuilder cb) { }
+    protected void CheckNeedParam(CommandBuilder cb) { }
 
     public abstract void Execute();
 
-    public abstract
+    // for remote
+    public abstract MemoryStream Convert();
+
+    public RemoteMassage CreateRemoteMessage() {
+        return new RemoteMassage(type.id);
+    }
+
+    public void SetDg(Object obj) {
+        this.dg.SetData(obj);
+    }
+
+    public override string ToString() {
+        return "Command : type = " + type.commandType + ", key = " + key + "toDgmName = " + toDgmName +
+               " fromDgmName = " + fromDgmName + " cgmID = " + cgmID + " cg = " + cg + " dg = " + dg + " clazz = " +
+               clazz + "connection = " + connection;
+    }
 }
 }
\ No newline at end of file
--- a/datagear/command/CommandBuilder.cs	Mon Oct 12 00:49:32 2020 +0900
+++ b/datagear/command/CommandBuilder.cs	Tue Nov 17 18:46:22 2020 +0900
@@ -1,15 +1,34 @@
 using System;
+using Christie_net.codegear;
+using Christie_net.datagear.dg;
 
 namespace Christie_net.datagear.command {
 public class CommandBuilder {
-    protected CodeGear cg = null; // for localtake
-    protected int? cgmID = null; // for local meta
-    protected Type clazz = null; // for remote
-    protected Connection connection = null; // for reply
-    protected DataGear dg = null; // for put/localtake/reply
-    protected string fromDgmname = "local"; // for remotetake/reply
-    protected string kye = null;
-    protected string toDgmName = null; // for take
-    protected CommandType type; // need
+    protected internal CommandTypeEtx type;
+    protected internal string key = null;
+    protected internal string toDgmName = null; // for take
+    protected internal string fromDgmname = "local"; // for remotetake/reply
+    protected internal int? cgmID = null; // for local meta
+    protected internal CodeGear cg = null; // for localtake
+    protected internal DataGear<object> dg = null; // for put/localtake/reply
+    protected internal Type clazz = null; // for remote
+    protected internal Connection connection = null; // for reply
+    
+    private CommandFactory factory = new CommandFactory();
+
+    public CommandBuilder init(CommandTypeEtx type) {
+        this.type = type;
+        this.key = null;
+        this.toDgmName = null;
+        this.fromDgmname = "local";
+        this.cgmID = null;
+        this.cg = null;
+        this.dg = null;
+        this.clazz = null;
+        this.connection = null;
+        return this;
+    }
+    
+    
 }
 }
\ No newline at end of file
--- a/datagear/command/CommandType.cs	Mon Oct 12 00:49:32 2020 +0900
+++ b/datagear/command/CommandType.cs	Tue Nov 17 18:46:22 2020 +0900
@@ -13,12 +13,13 @@
     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
+public class CommandTypeEtx {
+    public CommandType commandType;
+    public int id; // command ID
+    public static Dictionary<int, CommandType> hash = new Dictionary<int, CommandType>();  // コマンド対応表
+    private static int lastID = 0; // total command number
 
-    static CommandTypeEtx() {
+    public CommandTypeEtx() {
         StoreValues();
         id = IncrementLastID();
     }
@@ -32,7 +33,9 @@
     }
 
     public static void StoreValues() {
-        foreach (CommandType value in Enum.GetValues(typeof(CommandType))) hash.Add(Convert.ToInt32(value), value);
+        foreach (CommandType value in Enum.GetValues(typeof(CommandType))) {
+            hash.Add(Convert.ToInt32(value), value);
+        }
     }
 }
 }
\ No newline at end of file
--- a/datagear/dg/DataGear.cs	Mon Oct 12 00:49:32 2020 +0900
+++ b/datagear/dg/DataGear.cs	Tue Nov 17 18:46:22 2020 +0900
@@ -2,8 +2,8 @@
 
 namespace Christie_net.datagear.dg {
 public class DataGear<T> {
-    protected Type clazz;
     protected T data;
+    protected Type clazz = null;
 
     public DataGear(T data) {
         SetClazz(data.GetType());
@@ -16,7 +16,6 @@
 
     public void SetData(T data) {
         var dataClazz = data.GetType();
-
         if (dataClazz == clazz) {
             this.data = data;
             return;