internal static XmlRpcClient clientForNode(string nodename) { var args = new XmlRpcValue(ThisNode.Name, nodename); var resp = new XmlRpcValue(); var payl = new XmlRpcValue(); if (!execute("lookupNode", args, resp, payl, true)) { return(null); } if (!XmlRpcManager.Instance.ValidateXmlRpcResponse("lookupNode", resp, payl)) { return(null); } string nodeUri = payl.GetString(); if (!Network.SplitUri(nodeUri, out string nodeHost, out int nodePort) || nodeHost == null || nodePort <= 0) { return(null); } return(new XmlRpcClient(nodeHost, nodePort)); }
internal static CachedXmlRpcClient clientForNode(string nodename) { XmlRpcValue args = new XmlRpcValue(); args.Set(0, this_node.Name); args.Set(1, nodename); XmlRpcValue resp = new XmlRpcValue(); XmlRpcValue payl = new XmlRpcValue(); if (!execute("lookupNode", args, ref resp, ref payl, true)) { return(null); } if (!XmlRpcManager.Instance.validateXmlrpcResponse("lookupNode", resp, ref payl)) { return(null); } string nodeuri = payl.GetString(); string nodehost = null; int nodeport = 0; if (!network.splitURI(nodeuri, ref nodehost, ref nodeport) || nodehost == null || nodeport <= 0) { return(null); } return(XmlRpcManager.Instance.getXMLRPCClient(nodehost, nodeport, nodeuri)); }
internal async Task <(string host, int port)> LookupServiceAsync(string name) { XmlRpcValue args = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); args.Set(0, ThisNode.Name); args.Set(1, name); if (!await Master.ExecuteAsync("lookupService", args, result, payload, false).ConfigureAwait(false)) { throw new Exception($"The Service '{name}' is not available at ROS master."); } string uri = payload.GetString(); if (string.IsNullOrWhiteSpace(uri)) { throw new Exception("An Empty server URI was returned from ROS master."); } if (!Network.SplitUri(uri, out string host, out int port)) { throw new Exception($"Bad service URI received: '{uri}]"); } return(host, port); }
internal bool LookupService(string name, ref string serviceHost, ref int servicePort) { XmlRpcValue args = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); args.Set(0, ThisNode.Name); args.Set(1, name); if (!Master.Execute("lookupService", args, result, payload, false)) { logger.LogWarning("Service [{0}]: Not available at ROS master", name); return(false); } string serviceUri = payload.GetString(); if (serviceUri.Length == 0) { logger.LogError("Service [{0}]: Empty server URI returned from master", name); return(false); } if (!Network.SplitUri(serviceUri, out serviceHost, out servicePort)) { logger.LogError("Service [{0}]: Bad service uri [{0}]", name, serviceUri); return(false); } return(true); }
internal bool LookupService(string name, ref string serv_host, ref int serv_port) { XmlRpcValue args = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); args.Set(0, ThisNode.Name); args.Set(1, name); if (!Master.execute("lookupService", args, result, payload, false)) { ROS.Warn()($"[{ThisNode.Name}] Service [{name}]: Not available at ROS master"); return(false); } string serv_uri = payload.GetString(); if (serv_uri.Length == 0) { ROS.Error()($"[{ThisNode.Name}] Service [{name}]: Empty server URI returned from master"); return(false); } if (!Network.SplitUri(serv_uri, out serv_host, out serv_port)) { ROS.Error()($"[{ThisNode.Name}] Service [{name}]: Bad service uri [{serv_uri}]"); return(false); } return(true); }
internal bool lookupService(string name, ref string serv_host, ref int serv_port) { XmlRpcValue args = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); args.Set(0, this_node.Name); args.Set(1, name); if (!master.execute("lookupService", args, ref result, ref payload, false)) { EDB.WriteLine("lookupService: Service unknown."); return(false); } string serv_uri = payload.GetString(); if (serv_uri.Length == 0) { EDB.WriteLine("lookupService: Empty server URI returned from master"); return(false); } if (!network.splitURI(serv_uri, ref serv_host, ref serv_port)) { EDB.WriteLine("lookupService: Bad service uri [{0}]", serv_uri); return(false); } return(true); }
public void set_param(String key, XmlRpcValue value, Func <Dictionary <String, Tuple <String, XmlRpcValue> >, int> notify_task = null) { if (key == "/") //create root { parameters = new Param(value); } else //add branch { String[] namespaces = key.Split('/'); String value_key = namespaces.Last(); namespaces = namespaces.Take(namespaces.Length - 1).ToArray(); Dictionary <String, Param> d = parameters; foreach (String ns in namespaces) //descend tree to the node we are setting { if (ns != "") { if (!d.ContainsKey(ns)) { Param new_parameters = new Param(); d.Add(ns, new_parameters); d = new_parameters; } else { var val = d[ns]; if (val.isNotANamespace) { d[ns] = val = new Param(); } d = val; } } } if (value.Type == XmlRpcValue.ValueType.TypeString) { d[value_key] = new Param(value.GetString()); } else if (value.Type == XmlRpcValue.ValueType.TypeInt) { d[value_key] = new Param(value.GetInt()); } else if (value.Type == XmlRpcValue.ValueType.TypeDouble) { d[value_key] = new Param(value.GetDouble()); } else { d[value_key] = new Param(value); } } if (notify_task != null) { //Boolean updates = compute_param_updates(reg_manager.param_subscribers, key, value) //if(updates) //notify_task(updates); // TODO : ADD NOTIFY TASK DEALY } }
internal async Task <bool> RegisterSubscriber(Subscription s, string datatype) { string uri = XmlRpcManager.Instance.Uri; var args = new XmlRpcValue(ThisNode.Name, s.Name, datatype, uri); var result = new XmlRpcValue(); var payload = new XmlRpcValue(); if (!await Master.ExecuteAsync("registerSubscriber", args, result, payload, true)) { logger.LogError("RPC \"registerSubscriber\" for service " + s.Name + " failed."); return(false); } var pub_uris = new List <string>(); for (int i = 0; i < payload.Count; i++) { XmlRpcValue load = payload[i]; string pubed = load.GetString(); if (pubed != uri && !pub_uris.Contains(pubed)) { pub_uris.Add(pubed); } } bool self_subscribed = false; Publication pub = null; string sub_md5sum = s.Md5Sum; lock (gate) { foreach (Publication p in advertisedTopics) { pub = p; string pub_md5sum = pub.Md5Sum; if (pub.Name == s.Name && Md5SumsMatch(pub_md5sum, sub_md5sum) && !pub.Dropped) { self_subscribed = true; break; } } } await s.PubUpdate(pub_uris); if (self_subscribed) { s.AddLocalConnection(pub); } return(true); }
private static bool SafeGetDefault <T>(string key, out T dest, T def = default(T), bool useCache = false) { try { XmlRpcValue v = GetParam(key, useCache); if (v == null || !v.IsEmpty) { if (def == null) { dest = default(T); return(false); } dest = def; return(true); } if (typeof(T) == typeof(int)) { dest = (T)(object)v.GetInt(); } else if (typeof(T) == typeof(string)) { dest = (T)(object)v.GetString(); } else if (typeof(T) == typeof(bool)) { dest = (T)(object)v.GetBool(); } else if (typeof(T) == typeof(int)) { dest = (T)(object)v.GetInt(); } else if (typeof(T) == typeof(XmlRpcValue)) { dest = (T)(object)v; } else { // unsupported type dest = default(T); return(false); } return(true); } catch { dest = default(T); return(false); } }
public bool registerSubscriber(Subscription s, string datatype) { string uri = XmlRpcManager.Instance.Uri; var args = new XmlRpcValue(ThisNode.Name, s.name, datatype, uri); var result = new XmlRpcValue(); var payload = new XmlRpcValue(); if (!Master.execute("registerSubscriber", args, result, payload, true)) { ROS.Error()($"[{ThisNode.Name}] RPC \"registerSubscriber\" for service {s.name} failed."); return(false); } var pub_uris = new List <string>(); for (int i = 0; i < payload.Count; i++) { XmlRpcValue load = payload[i]; string pubed = load.GetString(); if (pubed != uri && !pub_uris.Contains(pubed)) { pub_uris.Add(pubed); } } bool self_subscribed = false; Publication pub = null; string sub_md5sum = s.md5sum; lock ( advertisedTopicsMutex ) { foreach (Publication p in advertisedTopics) { pub = p; string pub_md5sum = pub.Md5sum; if (pub.Name == s.name && md5sumsMatch(pub_md5sum, sub_md5sum) && !pub.Dropped) { self_subscribed = true; break; } } } s.pubUpdate(pub_uris); if (self_subscribed) { s.addLocalConnection(pub); } return(true); }
internal static CachedXmlRpcClient clientForNode(string nodename) { XmlRpcValue args = new XmlRpcValue(); args.Set(0, this_node.Name); args.Set(1, nodename); XmlRpcValue resp = new XmlRpcValue(); XmlRpcValue payl = new XmlRpcValue(); if (!execute("lookupNode", args, resp, payl, true)) return null; if (!XmlRpcManager.Instance.validateXmlrpcResponse("lookupNode", resp, payl)) return null; string nodeuri = payl.GetString(); string nodehost = null; int nodeport = 0; if (!network.splitURI(nodeuri, ref nodehost, ref nodeport) || nodehost == null || nodeport <= 0) return null; return XmlRpcManager.Instance.getXMLRPCClient(nodehost, nodeport, nodeuri); }