Beispiel #1
0
        Task IParameter.InitializeAsync(string nodeId, string paramName, Uri slaveUri, ParameterServerClient client)
        {
            NodeId  = nodeId;
            _logger = RosOutLogManager.GetCurrentNodeLogger(NodeId);

            Name      = paramName;
            _slaveUri = slaveUri;

            _parameterServerClient = client;

            return(_parameterServerClient.HasParamAsync(NodeId, Name)
                   .ContinueWith(task =>
            {
                if (task.Result)
                {
                    return _parameterServerClient.GetParamAsync(NodeId, Name);
                }
                else
                {
                    return _parameterServerClient.SetParamAsync(NodeId, Name, new XmlRpcStruct());
                }
            })
                   .Unwrap());
        }
Beispiel #2
0
 public Task <TParam> GetAsync()
 {
     return(_parameterServerClient.GetParamAsync(NodeId, Name)
            .ContinueWith(res => _converter.ConvertTo(res.Result)));
 }
        public void GetParam_NotSet()
        {
            var result = new object[3]
            {
                -1,
                "Parameter [/aaa] is not set",
                0
            };

            MXmlRpcClientProtocol.AllInstances.UrlSetString = (t1, t2) => { };
            MParameterServerProxy.AllInstances.BeginGetParamStringStringAsyncCallbackObject = (t1, t2, t3, t4, t5) => { t4(null); return null; };
            MParameterServerProxy.AllInstances.EndGetParamIAsyncResult = (t1, t2) => result;

            var client = new ParameterServerClient(new Uri("http://localhost"));

            var ex = AssertEx.Throws<AggregateException>(
                () => client.GetParamAsync("test", "aaa").Wait());
            ex.InnerException.Message.Is("Parameter [/aaa] is not set");
        }
        public void GetParam_SuccessString()
        {
            var result = new object[3]
            {
                1,
                "Parameter [/rosversion]",
                "1.6.5"
            };

            MXmlRpcClientProtocol.AllInstances.UrlSetString = (t1, t2) => { };
            MParameterServerProxy.AllInstances.BeginGetParamStringStringAsyncCallbackObject = (t1, t2, t3, t4, t5) => { t4(null); return null; };
            MParameterServerProxy.AllInstances.EndGetParamIAsyncResult = (t1, t2) => result;

            var client = new ParameterServerClient(new Uri("http://localhost"));
            client.GetParamAsync("test", "rosversion").Result.Is("1.6.5");
        }
        public void GetParam_SuccessList()
        {
            // > rosparam set /foo "['1', 1, 1.0]"

            var result = new object[3]
            {
                1,
                "Parameter [/foo]",
                new object[3]
                {
                    "1",
                    1,
                    1.0
                }
            };

            MXmlRpcClientProtocol.AllInstances.UrlSetString = (t1, t2) => { };
            MParameterServerProxy.AllInstances.BeginGetParamStringStringAsyncCallbackObject = (t1, t2, t3, t4, t5) => { t4(null); return null; };
            MParameterServerProxy.AllInstances.EndGetParamIAsyncResult = (t1, t2) => result;

            var client = new ParameterServerClient(new Uri("http://localhost"));
            var ret = client.GetParamAsync("test", "foo").Result as object[];
            ret[0].Is("1");
            ret[1].Is(1);
            ret[2].Is(1.0);
        }
        public void GetParam_SuccessDictionary()
        {
            // rosparam set /gains "p: 1.0
            // i: 1.0
            // d: 1.0"

            var result = new object[3]
            {
                1,
                "Parameter [/gains]",
                new object[3]
                {
                    "1",
                    1,
                    1.0
                }
            };

            MXmlRpcClientProtocol.AllInstances.UrlSetString = (t1, t2) => { };
            MParameterServerProxy.AllInstances.BeginGetParamStringStringAsyncCallbackObject = (t1, t2, t3, t4, t5) => { t4(null); return null; };
            MParameterServerProxy.AllInstances.EndGetParamIAsyncResult = (t1, t2) => result;

            var client = new ParameterServerClient(new Uri("http://localhost"));
            client.GetParamAsync("test", "gains").Wait();
        }