Пример #1
0
        internal bool AdvertiseService <MReq, MRes>(AdvertiseServiceOptions <MReq, MRes> ops) where MReq : RosMessage, new() where MRes : RosMessage, new()
        {
            lock (gate)
            {
                if (shuttingDown)
                {
                    return(false);
                }

                if (IsServiceAdvertised(ops.Service))
                {
                    logger.LogWarning($"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.ServiceCallback);
                }
                ServicePublication <MReq, MRes> pub = new ServicePublication <MReq, MRes>(ops.Service, ops.Md5Sum, ops.DataType, ops.RequestDataType, ops.ResponseDataType, ops.Helper, ops.CallbackQueue);
                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);
        }
Пример #2
0
 /// <summary>
 ///     Advertises a ServiceServer with specified OPTIONS
 /// </summary>
 /// <typeparam name="MReq">Request sub-srv type</typeparam>
 /// <typeparam name="MRes">Response sub-srv type</typeparam>
 /// <param name="ops">isn't it obvious?</param>
 /// <returns>The ServiceServer that will call the ServiceFunction on behalf of ServiceClients</returns>
 public ServiceServer AdvertiseService <MReq, MRes>(AdvertiseServiceOptions <MReq, MRes> ops)
     where MReq : RosMessage, new()
     where MRes : RosMessage, new()
 {
     ops.service = ResolveName(ops.service);
     if (ops.callback_queue == null)
     {
         ops.callback_queue = Callback;
     }
     if (ServiceManager.Instance.AdvertiseService(ops))
     {
         ServiceServer srv = new ServiceServer(ops.service, this);
         lock (gate)
         {
             collection.ServiceServers.Add(srv);
         }
         return(srv);
     }
     throw new InvalidOperationException("Could not advertise service");
 }
Пример #3
0
        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);
        }