示例#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
 public ServiceCallback(ServicePublication <MReq, MRes> sp, ServiceCallbackHelper <MReq, MRes> _helper, byte[] buf, IServiceClientLink link)
 {
     this.isp = sp;
     if (this.isp != null && _helper != null)
     {
         this.isp.helper = _helper;
     }
     this.buffer = buf;
     this.link   = link;
 }
示例#3
0
 public ServiceCallback(ServicePublication <MReq, MRes> sp, ServiceCallbackHelper <MReq, MRes> _helper, byte[] buf, int num_bytes, IServiceClientLink link, bool has_tracked_object, object tracked_object)
 {
     this.isp = sp;
     if (this.isp != null && _helper != null)
     {
         this.isp.helper = _helper;
     }
     this.buffer            = buf;
     this._numBytes         = num_bytes;
     this.link              = link;
     this._hasTrackedObject = has_tracked_object;
     this._trackedObject    = tracked_object;
 }
示例#4
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);
        }