public static UpNetworkInterface FromJSON(object json) { IDictionary <string, object> dict = json as IDictionary <string, object>; UpNetworkInterface ni = new UpNetworkInterface(); ni.networkAddress = dict["networkAddress"] as string; ni.netType = dict["netType"] as string; return(ni); }
public static UpNetworkInterface FromJSON(object json) { IDictionary<string, object> dict = json as IDictionary<string, object>; UpNetworkInterface ni = new UpNetworkInterface(); ni.networkAddress = dict["networkAddress"] as string; ni.netType = dict["netType"] as string; return ni; }
public override bool Equals(object obj) { if ((obj == null) || (!(obj is UpNetworkInterface))) { return(false); } UpNetworkInterface d = (UpNetworkInterface)obj; return (Util.Compare(this.networkAddress, d.networkAddress) && Util.Compare(this.netType, d.netType)); }
private string SendMessage(string msg, UpDevice target, bool waitForResponse = true) { UpNetworkInterface netInt = GetAppropriateInterface(target); string networkAddress = netInt.networkAddress; string networkType = netInt.netType; ClientConnection con = OpenActiveConnection(networkAddress, networkType); if (con == null) { logger.LogWarning("Not possible to stablish a connection with '" + networkAddress + "' of type '" + networkType + "'."); return(null); } try { byte[] data = Encoding.UTF8.GetBytes(msg); con.Write(data, 0, data.Length); // Gets response. string response = null; if (waitForResponse) { data = con.Read(); if (data != null) { response = Encoding.UTF8.GetString(data); if (response.Trim().Length == 0) { response = null; } } } con.Close(); return(response); } catch (System.Exception) { if (con.connected) { con.Close(); } throw; } }
private static List <UpNetworkInterface> FromNetworks(IDictionary <string, object> json) { object obj = Util.JsonOptField(json, "networks"); if (obj != null) { List <object> j_networks = obj as List <object>; List <UpNetworkInterface> networks = new List <UpNetworkInterface>(); foreach (var j_network in j_networks) { networks.Add(UpNetworkInterface.FromJSON(j_network)); } return(networks); } return(null); }
private StreamConnectionThreadData[] OpenStreamChannel(UpDevice device, Call serviceCall, CallContext messageContext) { StreamConnectionThreadData[] data = null; //Channel type decision string netType = null; if (serviceCall.channelType != null) { netType = serviceCall.channelType; } else { UpNetworkInterface network = GetAppropriateInterface(device); netType = network.netType; } int channels = serviceCall.channels; data = new StreamConnectionThreadData[channels]; string[] channelIDs = new string[channels]; for (int i = 0; i < channels; i++) { NetworkDevice networkDevice = GetAvailableNetworkDevice(netType); channelIDs[i] = Util.GetPort(networkDevice.networkDeviceName); StreamConnectionThreadData thread = new StreamConnectionThreadData(this, messageContext, networkDevice); thread.thread.Start(); data[i] = thread; } serviceCall.channelIDs = channelIDs; serviceCall.channelType = netType; return(data); }
private static string GenerateInterfaceKey(UpNetworkInterface ni) { return ni.networkAddress + "@" + ni.netType; }
private static string GenerateInterfaceKey(UpNetworkInterface ni) { return(ni.networkAddress + "@" + ni.netType); }
private void PrepareDeviceAndDrivers() { UpDevice currentDevice = new UpDevice(); if (settings.deviceName != null) { string name = settings.deviceName.Trim(); if (name.Length > 0) currentDevice.name = name; } else currentDevice.name = Dns.GetHostName(); if ((currentDevice.name == null) || (currentDevice.name.ToLower() == "localhost")) currentDevice.name = SystemInfo.deviceName; if ((currentDevice.name == null) || currentDevice.name.ToLower().Contains("unknown")) currentDevice.name = System.Environment.UserName; currentDevice.AddProperty("platform", "unity-" + Application.platform.ToString().ToLower()); var networks = new List<UpNetworkInterface>(); foreach (ChannelManager cm in channelManagers.Values) { foreach (var host in cm.ListHosts()) { var nInf = new UpNetworkInterface(); nInf.netType = cm.GetNetworkDeviceType(); nInf.networkAddress = host; networks.Add(nInf); } } currentDevice.networks = networks; driverManager = new DriverManager(settings, this, currentDevice); deviceManager = new DeviceManager(settings, this, currentDevice); foreach (var driver in settings.drivers) { System.Type type = null; try { type = Util.GetType(driver); } catch (System.Exception) { } string error = null; object instance = null; if ((type == null) || (type.GetInterface("UOS.UOSDriver") == null) || (!type.IsClass) || (type.IsAbstract)) error = driver + " is not a valid concrete type which implements UOSDriver interface"; else { if (type.IsSubclassOf(typeof(MonoBehaviour))) { object[] components = UnityEngine.Object.FindObjectsOfType(type); if (components.Length == 0) error = "no instance of MonoBehaviour " + driver + " was found in the scene"; else if (components.Length > 1) error = "multiple instances of MonoBehaviour " + driver + " were found in the scene"; else instance = components[0]; } else { try { instance = System.Activator.CreateInstance(type); } catch (System.Reflection.TargetInvocationException e) { error = "constructor exception: " + e.InnerException; } catch (System.Exception) { error = "couldn't instantiate " + driver + " using default constructor"; } } } if (error != null) logger.LogError("Driver initialisation failure: " + error + "."); else { var driverInstance = (UOSDriver)instance; driverManager.DeployDriver(driverInstance); } } driverManager.InitDrivers(); }
private void PrepareDeviceAndDrivers() { UpDevice currentDevice = new UpDevice(); if (settings.deviceName != null) { string name = settings.deviceName.Trim(); if (name.Length > 0) { currentDevice.name = name; } } else { currentDevice.name = Dns.GetHostName(); } if ((currentDevice.name == null) || (currentDevice.name.ToLower() == "localhost")) { currentDevice.name = SystemInfo.deviceName; } if ((currentDevice.name == null) || currentDevice.name.ToLower().Contains("unknown")) { currentDevice.name = System.Environment.UserName; } currentDevice.AddProperty("platform", "unity-" + Application.platform.ToString().ToLower()); var networks = new List <UpNetworkInterface>(); foreach (ChannelManager cm in channelManagers.Values) { foreach (var host in cm.ListHosts()) { var nInf = new UpNetworkInterface(); nInf.netType = cm.GetNetworkDeviceType(); nInf.networkAddress = host; networks.Add(nInf); } } currentDevice.networks = networks; driverManager = new DriverManager(settings, this, currentDevice); deviceManager = new DeviceManager(settings, this, currentDevice); foreach (var driver in settings.drivers) { System.Type type = null; try { type = Util.GetType(driver); } catch (System.Exception) { } string error = null; object instance = null; if ((type == null) || (type.GetInterface("UOS.UOSDriver") == null) || (!type.IsClass) || (type.IsAbstract)) { error = driver + " is not a valid concrete type which implements UOSDriver interface"; } else { if (type.IsSubclassOf(typeof(MonoBehaviour))) { object[] components = UnityEngine.Object.FindObjectsOfType(type); if (components.Length == 0) { error = "no instance of MonoBehaviour " + driver + " was found in the scene"; } else if (components.Length > 1) { error = "multiple instances of MonoBehaviour " + driver + " were found in the scene"; } else { instance = components[0]; } } else { try { instance = System.Activator.CreateInstance(type); } catch (System.Reflection.TargetInvocationException e) { error = "constructor exception: " + e.InnerException; } catch (System.Exception) { error = "couldn't instantiate " + driver + " using default constructor"; } } } if (error != null) { logger.LogError("Driver initialisation failure: " + error + "."); } else { var driverInstance = (UOSDriver)instance; driverManager.DeployDriver(driverInstance); } } driverManager.InitDrivers(); }