public List<String> publisher_update_task( String api, String topic, List<string> pub_uris) { XmlRpcValue l = new XmlRpcValue(); l.Set(0, api); l.Set(1, ""); //XmlRpcValue ll = new XmlRpcValue(); //l.Set(0, ll); for(int i = 0; i < pub_uris.Count; i++) { XmlRpcValue ll = new XmlRpcValue(pub_uris[i]); l.Set(i + 1, ll); } XmlRpcValue args = new XmlRpcValue(); args.Set(0, "master"); args.Set(1, topic); args.Set(2, l); XmlRpcValue result = new XmlRpcValue(new XmlRpcValue(), new XmlRpcValue(), new XmlRpcValue(new XmlRpcValue())), payload = new XmlRpcValue(); Ros_CSharp.master.host = api.Replace("http://","").Replace("/","").Split(':')[0]; Ros_CSharp.master.port = int.Parse( api.Replace("http://", "").Replace("/", "").Split(':')[1]); Ros_CSharp.master.execute("publisherUpdate", args, result, payload, false ); return new List<string>(new []{"http://ERIC:1337"}); }
public void service_update_task(String api, String service, String uri) { XmlRpcValue args = new XmlRpcValue(); args.Set(0, "master"); args.Set(1, service); args.Set(2, uri); XmlRpcValue result = new XmlRpcValue(new XmlRpcValue(), new XmlRpcValue(), new XmlRpcValue(new XmlRpcValue())), payload = new XmlRpcValue(); Ros_CSharp.master.host = api.Replace("http://", "").Replace("/", "").Split(':')[0]; Ros_CSharp.master.port = int.Parse(api.Replace("http://", "").Replace("/", "").Split(':')[1]); Ros_CSharp.master.execute("publisherUpdate", args, result, payload, false); }
/// <summary> /// Gets all currently published and subscribed topics and adds them to the topic list /// </summary> /// <param name="topics"> List to store topics</param> /// <returns></returns> public static bool getTopics(ref TopicInfo[] topics) { List<TopicInfo> topicss = new List<TopicInfo>(); XmlRpcValue args = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); args.Set(0, this_node.Name); args.Set(1, ""); if (!execute("getPublishedTopics", args, result, payload, true)) return false; topicss.Clear(); for (int i = 0; i < payload.Size; i++) topicss.Add(new TopicInfo(payload[i][0].Get<string>(), payload[i][1].Get<string>())); topics = topicss.ToArray(); return true; }
/// <summary> /// Returns list of all publications /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public void getPublications([In][Out] IntPtr parms, [In][Out] IntPtr result) { XmlRpcValue res = XmlRpcValue.Create(ref result); res.Set(0, 1); //length res.Set(1, "publications"); //response too XmlRpcValue response = new XmlRpcValue(); //guts, new value here //response.Size = 0; List <List <String> > current = handler.getPublishedTopics("", ""); for (int i = 0; i < current.Count; i += 2) { XmlRpcValue pub = new XmlRpcValue(); pub.Set(0, current[0]); current.RemoveAt(0); pub.Set(1, current[0]); current.RemoveAt(0); response.Set(i, pub); } res.Set(2, response); }
public static bool kill(string node) { var cl = clientForNode(node); if (cl == null) { return(false); } XmlRpcValue req = new XmlRpcValue(), resp = new XmlRpcValue(), payl = new XmlRpcValue(); req.Set(0, ThisNode.Name); req.Set(1, $"Node '{ThisNode.Name}' requests shutdown."); var respose = cl.Execute("shutdown", req); if (!respose.Success || !XmlRpcManager.Instance.ValidateXmlRpcResponse("shutdown", respose.Value, payl)) { return(false); } return(true); }
/// <summary> /// Get a list of all published topics /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public XmlRpcValue getPublishedTopics() { XmlRpcValue res = new XmlRpcValue(); List <List <String> > publishedtopics = handler.getPublishedTopics("", ""); res.Set(0, 1); res.Set(1, "current system state"); XmlRpcValue listofvalues = new XmlRpcValue(); int index = 0; foreach (List <String> l in publishedtopics) { XmlRpcValue value = new XmlRpcValue(); value.Set(0, l[0]); //Topic Name value.Set(1, l[1]); // Topic type listofvalues.Set(index, value); index++; } res.Set(2, listofvalues); return(res); }
public bool requestTopic(string topic, XmlRpcValue protos, ref XmlRpcValue ret) { for (int proto_idx = 0; proto_idx < protos.Size; proto_idx++) { XmlRpcValue proto = protos[proto_idx]; if (proto.Type != XmlRpcValue.ValueType.TypeArray) { EDB.WriteLine("requestTopic protocol list was not a list of lists"); return(false); } if (proto[0].Type != XmlRpcValue.ValueType.TypeString) { EDB.WriteLine( "requestTopic received a protocol list in which a sublist did not start with a string"); return(false); } string proto_name = proto[0].Get <string>(); if (proto_name == "TCPROS") { XmlRpcValue tcp_ros_params = new XmlRpcValue("TCPROS", network.host, ConnectionManager.Instance.TCPPort); ret.Set(0, 1); ret.Set(1, ""); ret.Set(2, tcp_ros_params); return(true); } if (proto_name == "UDPROS") { EDB.WriteLine("IGNORING UDP GIZNARBAGE"); } else { EDB.WriteLine("an unsupported protocol was offered: [{0}]", proto_name); } } EDB.WriteLine("The caller to requestTopic has NO IDEA WHAT'S GOING ON!"); return(false); }
/// <summary> /// Unregister an existing subscriber /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public void unregisterSubscriber([In][Out] IntPtr parms, [In][Out] IntPtr result) { XmlRpcValue res = XmlRpcValue.Create(ref result), parm = XmlRpcValue.Create(ref parms); String caller_id = parm[0].GetString(); String topic = parm[1].GetString(); String caller_api = parm[2].GetString(); Console.WriteLine("UNSUBSCRIBING: " + caller_id + " : " + caller_api); int ret = handler.unregisterSubscriber(caller_id, topic, caller_api); res.Set(0, ret); res.Set(1, "unregistered " + caller_id + "as provder of " + topic); //throw new Exception("NOT IMPLEMENTED YET!"); //XmlRpcValue args = new XmlRpcValue(this_node.Name, topic, XmlRpcManager.Instance.uri), // result = new XmlRpcValue(), // payload = new XmlRpcValue(); //master.execute("unregisterSubscriber", args, ref result, ref payload, false); //return true; }
public bool NegotiateConnection(string xmlrpc_uri) { int protos = 0; XmlRpcValue tcpros_array = new XmlRpcValue(), protos_array = new XmlRpcValue(), Params = new XmlRpcValue(); tcpros_array.Set(0, "TCPROS"); protos_array.Set(protos++, tcpros_array); Params.Set(0, this_node.Name); Params.Set(1, name); Params.Set(2, protos_array); string peer_host = ""; int peer_port = 0; if (!network.splitURI(xmlrpc_uri, ref peer_host, ref peer_port)) { EDB.WriteLine("Bad xml-rpc URI: [" + xmlrpc_uri + "]"); return(false); } XmlRpcClient c = new XmlRpcClient(peer_host, peer_port); if (!c.IsConnected || !c.ExecuteNonBlock("requestTopic", Params)) { EDB.WriteLine("Failed to contact publisher [" + peer_host + ":" + peer_port + "] for topic [" + name + "]"); c.Dispose(); return(false); } #if DEBUG EDB.WriteLine("Began asynchronous xmlrpc connection to http://" + peer_host + ":" + peer_port + "/ for topic [" + name + "]"); #endif PendingConnection conn = new PendingConnection(c, this, xmlrpc_uri, Params); lock (pending_connections_mutex) { pending_connections.Add(conn); } XmlRpcManager.Instance.addAsyncConnection(conn); return(true); }
/// <summary> /// Returns list of all, publishers, subscribers, and services /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public XmlRpcValue getSystemState() { XmlRpcValue res = new XmlRpcValue(); res.Set(0, 1); res.Set(1, "getSystemState"); List <List <List <String> > > systemstatelist = handler.getSystemState("");//parm.GetString() XmlRpcValue listoftypes = new XmlRpcValue(); XmlRpcValue listofvalues = new XmlRpcValue(); int index = 0; foreach (List <List <String> > types in systemstatelist) //publisher, subscriber, services { int bullshitindex = 0; XmlRpcValue typelist; XmlRpcValue bullshit = new XmlRpcValue(); if (types.Count > 0) { foreach (List <String> l in types) { int typeindex = 0; typelist = new XmlRpcValue(); //XmlRpcValue value = new XmlRpcValue(); typelist.Set(typeindex++, l[0]); XmlRpcValue payload = new XmlRpcValue(); for (int i = 1; i < l.Count; i++) { payload.Set(i - 1, l[i]); } typelist.Set(typeindex++, payload); //typelist.Set(typeindex++, value); bullshit.Set(bullshitindex++, typelist); } } else { typelist = new XmlRpcValue(); bullshit.Set(bullshitindex++, typelist); } listoftypes.Set(index++, bullshit); } res.Set(2, listoftypes); return(res); }
public XmlRpcValue getBusStats() { var publish_stats = new XmlRpcValue(); var subscribe_stats = new XmlRpcValue(); var service_stats = new XmlRpcValue(); int pidx = 0; lock ( advertisedTopicsMutex ) { publish_stats.SetArray(advertisedTopics.Count); foreach (Publication t in advertisedTopics) { publish_stats.Set(pidx++, t.GetStats()); } } int sidx = 0; lock ( subcriptionsMutex ) { subscribe_stats.SetArray(subscriptions.Count); foreach (Subscription t in subscriptions) { subscribe_stats.Set(sidx++, t.getStats()); } } // TODO: fix for services service_stats.SetArray(0); //service_stats.Size = 0; var stats = new XmlRpcValue(); stats.Set(0, publish_stats); stats.Set(1, subscribe_stats); stats.Set(2, service_stats); return(stats); }
/// <summary> /// Returns list of all publications /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public XmlRpcValue getPublications() { XmlRpcValue res = new XmlRpcValue(); res.Set(0, 1); //length res.Set(1, "publications"); //response too XmlRpcValue response = new XmlRpcValue(); //guts, new value here //response.Size = 0; List <List <String> > current = handler.getPublishedTopics("", ""); for (int i = 0; i < current.Count; i += 2) { XmlRpcValue pub = new XmlRpcValue(); pub.Set(0, current[0]); current.RemoveAt(0); pub.Set(1, current[0]); current.RemoveAt(0); response.Set(i, pub); } res.Set(2, response); return(res); }
public bool NegotiateConnection(string xmlRpcUri) { int protos = 0; XmlRpcValue tcpros_array = new XmlRpcValue(), protos_array = new XmlRpcValue(), Params = new XmlRpcValue(); tcpros_array.Set(0, "TCPROS"); protos_array.Set(protos++, tcpros_array); Params.Set(0, ThisNode.Name); Params.Set(1, name); Params.Set(2, protos_array); if (!Network.SplitUri(xmlRpcUri, out string peerHost, out int peerPort)) { ROS.Error()($"[{ThisNode.Name}] Bad xml-rpc URI: [{xmlRpcUri}]"); return(false); } var client = new XmlRpcClient(peerHost, peerPort); var requestTopicTask = client.ExecuteAsync("requestTopic", Params); if (requestTopicTask.IsFaulted) { ROS.Error()($"[{ThisNode.Name}] Failed to contact publisher [{peerHost}:{peerPort}for topic [{name}]"); return(false); } ROS.Debug()($"[{ThisNode.Name}] Began asynchronous xmlrpc connection to http://{peerHost}:{peerPort}/ for topic [{name}]"); var conn = new PendingConnection(client, requestTopicTask, xmlRpcUri); lock ( pendingConnections ) { pendingConnections.Add(conn); requestTopicTask.ContinueWith(t => PendingConnectionDone(conn, t)); } return(true); }
public void getTopicTypes([In][Out] IntPtr parms, [In][Out] IntPtr result) { XmlRpcValue res = XmlRpcValue.Create(ref result), parm = XmlRpcValue.Create(ref parms); String topic = parm[0].GetString(); String caller_id = parm[1].GetString(); Dictionary <String, String> types = handler.getTopicTypes(topic); XmlRpcValue value = new XmlRpcValue(); int index = 0; foreach (KeyValuePair <String, String> pair in types) { XmlRpcValue payload = new XmlRpcValue(); payload.Set(0, pair.Key); payload.Set(1, pair.Value); value.Set(index, payload); } res.Set(0, 1); res.Set(1, "getTopicTypes"); res.Set(2, value); }
internal bool AdvertiseService <MReq, MRes>(AdvertiseServiceOptions <MReq, MRes> ops) where MReq : RosMessage, new() where MRes : RosMessage, new() { lock ( shuttingDownMutex ) { if (shuttingDown) { return(false); } } lock ( servicePublicationsMutex ) { if (IsServiceAdvertised(ops.service)) { ROS.Warn()($"[{ThisNode.Name}] Tried to advertise a service that is already advertised in this node [{ops.service}]"); return(false); } if (ops.helper == null) { ops.helper = new ServiceCallbackHelper <MReq, MRes>(ops.srv_func); } ServicePublication <MReq, MRes> pub = new ServicePublication <MReq, MRes>(ops.service, ops.md5sum, ops.datatype, ops.req_datatype, ops.res_datatype, ops.helper, ops.callback_queue, ops.tracked_object); servicePublications.Add(pub); } XmlRpcValue args = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); args.Set(0, ThisNode.Name); args.Set(1, ops.service); args.Set(2, string.Format("rosrpc://{0}:{1}", Network.host, connectionManager.TCPPort)); args.Set(3, xmlrpcManager.Uri); if (!Master.execute("registerService", args, result, payload, true)) { throw new RosException("RPC \"registerService\" for service " + ops.service + " failed."); } return(true); }
public void GetPublications(XmlRpcValue pubs) { pubs.SetArray(0); lock (gate) { int i = 0; foreach (Publication t in advertisedTopics) { XmlRpcValue pub = new XmlRpcValue(); pub.Set(0, t.Name); pub.Set(1, t.DataType); pubs.Set(i++, pub); } } }
/// <summary> /// Retrieve a value for an existing parameter, if it exists /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public XmlRpcValue getParam(String caller_id, String topic) { XmlRpcValue res = new XmlRpcValue();//XmlRpcValue.Create(ref result), parm = XmlRpcValue.Create(ref parms); res.Set(0, 1); res.Set(1, "getParam"); //String caller_id = parm[0].GetString(); //String topic = parm[1].GetString(); // value = new XmlRpcValue(); XmlRpcValue value = handler.getParam(caller_id, topic); //value // String vi = v.getString(); if (value == null) { res.Set(0, 0); res.Set(1, "Parameter " + topic + " is not set"); value = new XmlRpcValue(""); } res.Set(2, value); return(res); }
public static bool GetImpl(string key, out XmlRpcValue value, bool useCache) { string mappepKey = Names.Resolve(key); value = new XmlRpcValue(); if (useCache) { lock (gate) { if (cachedValues.TryGetValue(mappepKey, out var cachedValue) && !cachedValue.IsEmpty) { value = cachedValue; return(true); } } } XmlRpcValue parm2 = new XmlRpcValue(), result2 = new XmlRpcValue(); parm2.Set(0, ThisNode.Name); parm2.Set(1, mappepKey); value.SetArray(0); bool ret = Master.Execute("getParam", parm2, result2, value, false); if (ret && useCache) { lock (gate) { cachedValues[mappepKey] = value; } } return(ret); }
public void getPublications(ref XmlRpcValue pubs) { pubs.SetArray(0); lock ( advertisedTopicsMutex ) { int sidx = 0; foreach (Publication t in advertisedTopics) { XmlRpcValue pub = new XmlRpcValue(); pub.Set(0, t.Name); pub.Set(1, t.DataType); pubs.Set(sidx++, pub); } } }
public void getInfo(XmlRpcValue info) { lock (subscriber_links_mutex) { foreach (SubscriberLink c in subscriber_links) { XmlRpcValue curr_info = new XmlRpcValue(); curr_info.Set(0, (int)c.connection_id); curr_info.Set(1, c.destination_caller_id); curr_info.Set(2, "o"); curr_info.Set(3, "TCPROS"); curr_info.Set(4, Name); info.Set(info.Size, curr_info); } } }
public void GetInfo(XmlRpcValue info) { lock (gate) { foreach (SubscriberLink c in subscriberLinks) { var curr_info = new XmlRpcValue(); curr_info.Set(0, (int)c.connectionId); curr_info.Set(1, c.DestinationCallerId); curr_info.Set(2, "o"); curr_info.Set(3, "TCPROS"); curr_info.Set(4, Name); info.Set(info.Count, curr_info); } } }
public XmlRpcValue getParamNames(String caller_id) { XmlRpcValue res = new XmlRpcValue();//XmlRpcValue.Create(ref result), parm = XmlRpcValue.Create(ref parms); res.Set(0, 1); res.Set(1, "getParamNames"); //String caller_id = parm[0].GetString(); List <String> list = handler.getParamNames(caller_id); XmlRpcValue response = new XmlRpcValue(); int index = 0; foreach (String s in list) { response.Set(index++, s); } res.Set(2, response); return(res); }
public void getInfo(XmlRpcValue info) { lock ( publisher_links_mutex ) { //ROS.Debug()( $"[{ThisNode.Name}] SUB: getInfo with {publisher_links.Count} publinks in list" ); foreach (PublisherLink c in publisher_links) { //ROS.Debug()( $"[{ThisNode.Name}] PUB: adding a curr_info to info!" ); var curr_info = new XmlRpcValue(); curr_info.Set(0, (int)c.ConnectionID); curr_info.Set(1, c.XmlRpcUri); curr_info.Set(2, "i"); curr_info.Set(3, c.TransportType); curr_info.Set(4, name); //ROS.Debug()( $"[{ThisNode.Name}] PUB curr_info DUMP:\n\t" ); //curr_info.Dump(); info.Set(info.Count, curr_info); } //ROS.Debug()( $"[{ThisNode.Name}] SUB: outgoing info is of type: {info.Type} and has size: {info.Size}" ); } }
public void getInfo(XmlRpcValue info) { lock (publisher_links_mutex) { //EDB.WriteLine("SUB: getInfo with " + publisher_links.Count + " publinks in list"); foreach (PublisherLink c in publisher_links) { //EDB.WriteLine("PUB: adding a curr_info to info!"); XmlRpcValue curr_info = new XmlRpcValue(); curr_info.Set(0, (int)c.ConnectionID); curr_info.Set(1, c.XmlRpc_Uri); curr_info.Set(2, "i"); curr_info.Set(3, c.TransportType); curr_info.Set(4, name); //EDB.Write("PUB curr_info DUMP:\n\t"); //curr_info.Dump(); info.Set(info.Size, curr_info); } //EDB.WriteLine("SUB: outgoing info is of type: " + info.Type + " and has size: " + info.Size); } }
public static List <string> list() { List <string> ret = new List <string>(); XmlRpcValue parm = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); parm.Set(0, this_node.Name); if (!master.execute("getParamNames", parm, ref result, ref payload, false)) { return(ret); } if (result.Size != 3 || result[0].GetInt() != 1 || result[2].Type != TypeEnum.TypeArray) { Console.WriteLine("Expected a return code, a description, and a list!"); return(ret); } for (int i = 0; i < payload.Size; i++) { ret.Add(payload[i].GetString()); } return(ret); }
/// <summary> /// Get a list of all published topics /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public void getPublishedTopics([In][Out] IntPtr parms, [In][Out] IntPtr result) { XmlRpcValue res = XmlRpcValue.Create(ref result), parm = XmlRpcValue.Create(ref parms); List <List <String> > publishedtopics = handler.getPublishedTopics("", ""); res.Set(0, 1); res.Set(1, "current system state"); XmlRpcValue listofvalues = new XmlRpcValue(); int index = 0; foreach (List <String> l in publishedtopics) { XmlRpcValue value = new XmlRpcValue(); value.Set(0, l[0]); //Topic Name value.Set(1, l[1]); // Topic type listofvalues.Set(index, value); index++; } res.Set(2, listofvalues); }
public XmlRpcValue getTopicTypes(String topic, String caller_id) { XmlRpcValue res = new XmlRpcValue(); Dictionary <String, String> types = handler.getTopicTypes(topic); XmlRpcValue value = new XmlRpcValue(); int index = 0; foreach (KeyValuePair <String, String> pair in types) { XmlRpcValue payload = new XmlRpcValue(); payload.Set(0, pair.Key); payload.Set(1, pair.Value); value.Set(index++, payload); } res.Set(0, 1); res.Set(1, "getTopicTypes"); res.Set(2, value); return(res); }
public void GetInfo(XmlRpcValue info) { lock (gate) { //Logger.LogDebug("SUB: getInfo with " + publisher_links.Count + " publinks in list"); foreach (PublisherLink c in publisherLinks) { //Logger.LogDebug("PUB: adding a curr_info to info!"); var curr_info = new XmlRpcValue(); curr_info.Set(0, (int)c.ConnectionId); curr_info.Set(1, c.XmlRpcUri); curr_info.Set(2, "i"); curr_info.Set(3, c.TransportType); curr_info.Set(4, Name); //Logger.LogDebug("PUB curr_info DUMP:\n\t"); //curr_info.Dump(); info.Set(info.Count, curr_info); } //Logger.LogDebug("SUB: outgoing info is of type: " + info.Type + " and has size: " + info.Size); } }
public static List <string> List() { var ret = new List <string>(); var parm = new XmlRpcValue(); var result = new XmlRpcValue(); var payload = new XmlRpcValue(); parm.Set(0, ThisNode.Name); if (!Master.execute("getParamNames", parm, result, payload, false)) { return(ret); } if (result.Count != 3 || result[0].GetInt() != 1 || result[2].Type != XmlRpcType.Array) { ROS.Warn()("Expected a return code, a description, and a list!"); return(ret); } for (int i = 0; i < payload.Count; i++) { ret.Add(payload[i].GetString()); } return(ret); }
public static async Task <IList <string> > List() { var ret = new List <string>(); var parm = new XmlRpcValue(); var result = new XmlRpcValue(); var payload = new XmlRpcValue(); parm.Set(0, ThisNode.Name); if (!await Master.ExecuteAsync("getParamNames", parm, result, payload, false).ConfigureAwait(false)) { return(ret); } if (result.Count != 3 || result[0].GetInt() != 1 || result[2].Type != XmlRpcType.Array) { logger.LogWarning("Expected a return code, a description, and a list!"); return(ret); } for (int i = 0; i < payload.Count; i++) { ret.Add(payload[i].GetString()); } return(ret); }
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); }
public static bool kill(string node) { CachedXmlRpcClient cl = clientForNode(node); if (cl == null) return false; XmlRpcValue req = new XmlRpcValue(), resp = new XmlRpcValue(), payl = new XmlRpcValue(); req.Set(0, this_node.Name); req.Set(1, "Out of respect for Mrs. " + this_node.Name); if (!cl.Execute("shutdown", req, resp) || !XmlRpcManager.Instance.validateXmlrpcResponse("lookupNode", resp, payl)) return false; payl.Dump(); XmlRpcManager.Instance.releaseXMLRPCClient(cl); return true; }
/// <summary> /// Checks if master is running? I think. /// </summary> /// <returns></returns> public static bool check() { XmlRpcValue args = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); args.Set(0, this_node.Name); return execute("getPid", args, result, payload, false); }
// Execute a named method with the specified params. public bool executeMethod(string methodName, XmlRpcValue parms, XmlRpcValue result) { XmlRpcServerMethod method = FindMethod(methodName); if (method == null) return false; method.Execute(parms, result); // Ensure a valid result value if (!result.Valid) result.Set(""); return true; }
public bool validateXmlrpcResponse(string method, XmlRpcValue response, XmlRpcValue payload) { if (response.Type != XmlRpcValue.ValueType.TypeArray) { return(validateFailed(method, "didn't return an array -- {0}", response)); } if (response.Size != 3) { return(validateFailed(method, "didn't return a 3-element array -- {0}", response)); } if (response[0].Type != XmlRpcValue.ValueType.TypeInt) { return(validateFailed(method, "didn't return an int as the 1st element -- {0}", response)); } int status_code = response[0].Get <int>(); if (response[1].Type != XmlRpcValue.ValueType.TypeString) { return(validateFailed(method, "didn't return a string as the 2nd element -- {0}", response)); } string status_string = response[1].Get <string>(); if (status_code != 1) { return(validateFailed(method, "returned an error ({0}): [{1}] -- {2}", status_code, status_string, response)); } switch (response[2].Type) { case XmlRpcValue.ValueType.TypeArray: { payload.SetArray(0); for (int i = 0; i < response[2].Length; i++) { payload.Set(i, response[2][i]); } } break; case XmlRpcValue.ValueType.TypeInt: payload.asInt = response[2].asInt; break; case XmlRpcValue.ValueType.TypeDouble: payload.asDouble = response[2].asDouble; break; case XmlRpcValue.ValueType.TypeString: payload.asString = response[2].asString; break; case XmlRpcValue.ValueType.TypeBoolean: payload.asBool = response[2].asBool; break; case XmlRpcValue.ValueType.TypeInvalid: break; default: throw new Exception("Unhandled valid xmlrpc payload type: " + response[2].Type); } return(true); }
/// <summary> /// Get a list of all published topics /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public void getPublishedTopics([In] [Out] IntPtr parms, [In] [Out] IntPtr result) { XmlRpcValue res = XmlRpcValue.Create(ref result), parm = XmlRpcValue.Create(ref parms); List<List<String>> publishedtopics = handler.getPublishedTopics("",""); res.Set(0, 1); res.Set(1, "current system state"); XmlRpcValue listofvalues = new XmlRpcValue(); int index = 0; foreach (List<String> l in publishedtopics) { XmlRpcValue value = new XmlRpcValue(); value.Set(0, l[0]); //Topic Name value.Set(1, l[1]); // Topic type listofvalues.Set(index, value); index++; } res.Set(2, listofvalues); }
public void getTopicTypes([In] [Out] IntPtr parms, [In] [Out] IntPtr result) { XmlRpcValue res = XmlRpcValue.Create(ref result), parm = XmlRpcValue.Create(ref parms); String topic = parm[0].GetString(); String caller_id = parm[1].GetString(); Dictionary<String, String> types = handler.getTopicTypes(topic); XmlRpcValue value = new XmlRpcValue(); int index = 0; foreach (KeyValuePair<String, String> pair in types) { XmlRpcValue payload = new XmlRpcValue(); payload.Set(0, pair.Key); payload.Set(1, pair.Value); value.Set(index, payload); } res.Set(0, 1); res.Set(1, "getTopicTypes"); res.Set(2, value); }
public void getInfo(XmlRpcValue info) { lock (subscriber_links_mutex) { foreach (SubscriberLink c in subscriber_links) { XmlRpcValue curr_info = new XmlRpcValue(); curr_info.Set(0, (int) c.connection_id); curr_info.Set(1, c.destination_caller_id); curr_info.Set(2, "o"); curr_info.Set(3, "TCPROS"); curr_info.Set(4, Name); info.Set(info.Size, curr_info); } } }
private void listMethods(XmlRpcValue result) { int i = 0; result.SetArray(_methods.Count + 1); foreach (var rec in _methods) { result.Set(i++, rec.Key); } // Multicall support is built into XmlRpcServerConnection result.Set(i, MULTICALL); }
/// <summary> /// Returns list of all publications /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public void getPublications([In] [Out] IntPtr parms, [In] [Out] IntPtr result) { XmlRpcValue res = XmlRpcValue.Create(ref result); res.Set(0, 1); //length res.Set(1, "publications"); //response too XmlRpcValue response = new XmlRpcValue(); //guts, new value here //response.Size = 0; List<List<String>> current = handler.getPublishedTopics("",""); for (int i = 0; i < current.Count; i += 2) { XmlRpcValue pub = new XmlRpcValue(); pub.Set(0, current[0]); current.RemoveAt(0); pub.Set(1, current[0]); current.RemoveAt(0); response.Set(i, pub); } res.Set(2, response); }
public bool validateXmlrpcResponse(string method, XmlRpcValue response, XmlRpcValue payload) { if (response.Type != XmlRpcValue.ValueType.TypeArray) return validateFailed(method, "didn't return an array -- {0}", response); if (response.Size != 3) return validateFailed(method, "didn't return a 3-element array -- {0}", response); if (response[0].Type != XmlRpcValue.ValueType.TypeInt) return validateFailed(method, "didn't return an int as the 1st element -- {0}", response); int status_code = response[0].Get<int>(); if (response[1].Type != XmlRpcValue.ValueType.TypeString) return validateFailed(method, "didn't return a string as the 2nd element -- {0}", response); string status_string = response[1].Get<string>(); if (status_code != 1) return validateFailed(method, "returned an error ({0}): [{1}] -- {2}", status_code, status_string, response); switch (response[2].Type) { case XmlRpcValue.ValueType.TypeArray: { payload.SetArray(0); for (int i = 0; i < response[2].Length; i++) { payload.Set(i, response[2][i]); } } break; case XmlRpcValue.ValueType.TypeInt: payload.asInt = response[2].asInt; break; case XmlRpcValue.ValueType.TypeDouble: payload.asDouble = response[2].asDouble; break; case XmlRpcValue.ValueType.TypeString: payload.asString = response[2].asString; break; case XmlRpcValue.ValueType.TypeBoolean: payload.asBool = response[2].asBool; break; case XmlRpcValue.ValueType.TypeInvalid: break; default: throw new Exception("Unhandled valid xmlrpc payload type: " + response[2].Type); } return true; }
/// <summary> /// Execute a remote procedure call on the ROS master. /// </summary> /// <param name="method"></param> /// <param name="request">Full request to send to the master </param> /// <param name="waitForMaster">If you recieve an unseccessful status code, keep retrying.</param> /// <param name="response">Full response including status code and status message. Initially empty.</param> /// <param name="payload">Location to store the actual data requested, if any.</param> /// <returns></returns> public static async Task <bool> ExecuteAsync(string method, XmlRpcValue request, XmlRpcValue response, XmlRpcValue payload, bool waitForMaster) { bool supprressWarning = false; var startTime = DateTime.UtcNow; try { var client = new XmlRpcClient(host, port); while (true) { // check if we are shutting down if (XmlRpcManager.Instance.IsShuttingDown) { return(false); } try { var result = await client.ExecuteAsync(method, request); // execute the RPC call response.Set(result.Value); if (result.Success) { // validateXmlrpcResponse logs error in case of validation error // So we don't need any logging here. if (XmlRpcManager.Instance.ValidateXmlRpcResponse(method, result.Value, payload)) { return(true); } else { return(false); } } else { if (response.IsArray && response.Count >= 2) { ROS.Error()($"[{ThisNode.Name}] Execute failed: return={response[0].GetInt()}, desc={response[1].GetString()}"); } else { ROS.Error()($"[{ThisNode.Name}] response type: {response.Type.ToString()}"); } } } catch (Exception ex) { // no connection to ROS Master if (waitForMaster) { if (!supprressWarning) { ROS.Warn()($"[{ThisNode.Name}] [{method}] Could not connect to master at [{host}:{port}]. Retrying for the next {retryTimeout.TotalSeconds} seconds."); supprressWarning = true; } // timeout expired, throw exception if (retryTimeout.TotalSeconds > 0 && DateTime.UtcNow.Subtract(startTime) > retryTimeout) { ROS.Error()($"[{ThisNode.Name}] [{method}] Timed out trying to connect to the master [{host}:{port}] after [{retryTimeout.TotalSeconds}] seconds"); throw new RosException($"Cannot connect to ROS Master at {host}:{port}", ex); } } else { throw new RosException($"Cannot connect to ROS Master at {host}:{port}", ex); } } await Task.Delay(250); // recreate the client and reinitiate master connection client = new XmlRpcClient(host, port); } } catch (ArgumentNullException e) { ROS.Error()($"[{ThisNode.Name}] {e.ToString()}"); } ROS.Error()($"[{ThisNode.Name}] Master API call: {method} failed!\n\tRequest:\n{request}"); return(false); }
public void CheckStructRoundTrip() { var today = DateTime.Today; var v = new XmlRpcValue(); v.Set("memberInt", 789); v.Set("memberBool", true); v.Set("memberDouble", 765.678); v.Set("memberBinary", new byte[] { 0, 2, 4, 6, 8, 10, 12 }); v.Set("memberString", "qwerty"); v.Set("memberDate", today); var innerArray = new XmlRpcValue(1, 2.0, "three", today); v.Set("memberArray", innerArray); var innerStruct = new XmlRpcValue(); innerStruct.Copy(v); v.Set("memberStruct", innerStruct); var xml = v.ToXml(); var w = new XmlRpcValue(); w.FromXml(xml); Assert.Equal(8, w.Count); Assert.Equal(XmlRpcType.Struct, w.Type); Assert.True(w.HasMember("memberInt")); Assert.True(w.HasMember("memberBool")); Assert.True(w.HasMember("memberDouble")); Assert.True(w.HasMember("memberBinary")); Assert.True(w.HasMember("memberString")); Assert.True(w.HasMember("memberDate")); Assert.True(w.HasMember("memberArray")); Assert.True(w.HasMember("memberStruct")); Assert.Equal(XmlRpcType.Int, w["memberInt"].Type); Assert.Equal(XmlRpcType.Boolean, w["memberBool"].Type); Assert.Equal(XmlRpcType.Double, w["memberDouble"].Type); Assert.Equal(XmlRpcType.Base64, w["memberBinary"].Type); Assert.Equal(XmlRpcType.String, w["memberString"].Type); Assert.Equal(XmlRpcType.DateTime, w["memberDate"].Type); Assert.Equal(XmlRpcType.Array, w["memberArray"].Type); Assert.Equal(XmlRpcType.Struct, w["memberStruct"].Type); Assert.Equal(4, w["memberArray"].Count); Assert.Equal(7, w["memberStruct"].Count); Action <XmlRpcValue> checkValueOneLevel = (XmlRpcValue value) => { Assert.Equal(789, value["memberInt"].GetInt()); Assert.True(value["memberBool"].GetBool()); Assert.Equal(765.678, value["memberDouble"].GetDouble(), 3); Assert.Equal(new byte[] { 0, 2, 4, 6, 8, 10, 12 }, value["memberBinary"].GetBinary()); Assert.Equal("qwerty", value["memberString"].GetString()); Assert.True(Math.Abs((today - value["memberDate"].GetDateTime()).TotalSeconds) < 1); var a = value["memberArray"]; Assert.Equal(4, a.Count); Assert.Equal(XmlRpcType.Array, a.Type); Assert.Equal(1, a[0].GetInt()); Assert.Equal(2.0, a[1].GetDouble()); Assert.Equal("three", a[2].GetString()); Assert.True(Math.Abs((today - a[3].GetDateTime()).TotalSeconds) < 1); }; checkValueOneLevel(w); checkValueOneLevel(w["memberStruct"]); }
public string generateFaultResponse(string errorMsg, int errorCode = -1) { string RESPONSE_1 = "<?xml version=\"1.0\"?>\r\n<methodResponse><fault>\r\n\t"; string RESPONSE_2 = "\r\n</fault></methodResponse>\r\n"; XmlRpcValue faultStruct = new XmlRpcValue(); faultStruct.Set(FAULTCODE, errorCode); faultStruct.Set(FAULTSTRING, errorMsg); string body = RESPONSE_1 + faultStruct.toXml() + RESPONSE_2; string header = generateHeader(body); return header + body; }
public XmlRpcValue GetStats() { XmlRpcValue stats = new XmlRpcValue(); stats.Set(0, Name); XmlRpcValue conn_data = new XmlRpcValue(); conn_data.SetArray(0); lock (subscriber_links_mutex) { int cidx = 0; foreach (SubscriberLink sub_link in subscriber_links) { SubscriberLink.Stats s = sub_link.stats; XmlRpcValue inside = new XmlRpcValue(); inside.Set(0, sub_link.connection_id); inside.Set(1, s.bytes_sent); inside.Set(2, s.message_data_sent); inside.Set(3, s.messages_sent); inside.Set(4, 0); conn_data.Set(cidx++, inside); } } stats.Set(1, conn_data); return stats; }
private void execute(XmlRpcValue parms, XmlRpcValue result) { if (parms[0].Type != XmlRpcValue.ValueType.TypeString) throw new XmlRpcException(METHOD_HELP + ": Invalid argument type"); XmlRpcServerMethod m = server.FindMethod(parms[0].GetString()); if (m == null) throw new XmlRpcException(METHOD_HELP + ": Unknown method name"); result.Set(m.Help()); }
/// <summary> /// Gets all currently existing nodes and adds them to the nodes list /// </summary> /// <param name="nodes">List to store nodes</param> /// <returns></returns> public static bool getNodes(ref string[] nodes) { List<string> names = new List<string>(); XmlRpcValue args = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); args.Set(0, this_node.Name); if (!execute("getSystemState", args, result, payload, true)) { return false; } for (int i = 0; i < payload.Size; i++) { for (int j = 0; j < payload[i].Size; j++) { XmlRpcValue val = payload[i][j][1]; for (int k = 0; k < val.Size; k++) { string name = val[k].Get<string>(); names.Add(name); } } } nodes = names.ToArray(); return true; }
/// <summary> /// Returns list of all, publishers, subscribers, and services /// </summary> /// <param name="parms"></param> /// <param name="result"></param> public void getSystemState([In] [Out] IntPtr parms, [In] [Out] IntPtr result) { XmlRpcValue res = XmlRpcValue.Create(ref result), parm = XmlRpcValue.Create(ref parms); res.Set(0, 1); res.Set(1, "getSystemState"); List<List<List<String>>> systemstatelist = handler.getSystemState("");//parm.GetString() XmlRpcValue listoftypes = new XmlRpcValue(); XmlRpcValue listofvalues = new XmlRpcValue(); int index = 0; foreach (List<List<String>> types in systemstatelist) //publisher, subscriber, services { int bullshitindex = 0; XmlRpcValue typelist; XmlRpcValue bullshit = new XmlRpcValue(); if (types.Count > 0) { foreach (List<String> l in types) { int typeindex = 0; typelist = new XmlRpcValue(); //XmlRpcValue value = new XmlRpcValue(); typelist.Set(typeindex++, l[0]); XmlRpcValue payload = new XmlRpcValue(); for (int i = 1; i < l.Count; i++) { payload.Set(i - 1, l[i]); } typelist.Set(typeindex++, payload); //typelist.Set(typeindex++, value); bullshit.Set(bullshitindex++, typelist); } } else { typelist = new XmlRpcValue(); bullshit.Set(bullshitindex++, typelist); } listoftypes.Set(index++,bullshit); } res.Set(2,listoftypes); }
public void getParamNames([In] [Out] IntPtr parms, [In] [Out] IntPtr result) { XmlRpcValue res = XmlRpcValue.Create(ref result), parm = XmlRpcValue.Create(ref parms); res.Set(0, 1); res.Set(1, "getParamNames"); String caller_id = parm[0].GetString(); List<String> list = handler.getParamNames(caller_id); XmlRpcValue response = new XmlRpcValue(); int index = 0; foreach (String s in list) { response.Set(index++, s); } res.Set(2, response); //throw new Exception("NOT IMPLEMENTED YET!"); //XmlRpcValue parm = new XmlRpcValue(), result = new XmlRpcValue(), payload = new XmlRpcValue(); //parm.Set(0, this_node.Name); //parm.Set(1, mapped_key); //if (!master.execute("deleteParam", parm, ref result, ref payload, false)) // return false; //return true; }