Пример #1
0
        public void ParseAssemblyAndRegisterRosServices(Assembly assembly)
        {
            foreach (Type type in assembly.GetTypes())
            {
                var typeInfo = type.GetTypeInfo();
                if (type == typeof(RosService) || !typeInfo.IsSubclassOf(typeof(RosService)))
                {
                    continue;
                }

                RosService service = Activator.CreateInstance(type) as RosService;
                if (service.ServiceType == "undefined/unknown")
                {
                    throw new Exception("Invalid servive type. Service type field (srvtype) was not initialized correctly.");
                }

                var packageName = service.ServiceType.Split('/')[0];
                if (!PackageNames.Contains(packageName))
                {
                    PackageNames.Add(packageName);
                }

                Logger.LogDebug($"Register {service.ServiceType}");
                if (!TypeRegistry.ContainsKey(service.ServiceType))
                {
                    TypeRegistry.Add(service.ServiceType, service.GetType());
                }
            }
        }
Пример #2
0
        public async Task <bool> Call(RosService srv)
        {
            (bool result, RosMessage response) = await Call(srv.RequestMessage).ConfigureAwait(false);

            srv.ResponseMessage = response;
            return(result);
        }
Пример #3
0
 public AdvertiseServiceOptions(string service, ServiceFunction <MReq, MRes> serviceCallback)
 {
     this.Service     = service;
     ServiceCallback  = serviceCallback;
     Helper           = new ServiceCallbackHelper <MReq, MRes>(serviceCallback);
     RequestDataType  = new MReq().MessageType.Replace("/Request", "__Request");
     ResponseDataType = new MRes().MessageType.Replace("/Response", "__Response");
     SrvType          = RequestDataType.Replace("__Request", "");
     Md5Sum           = RosService.Generate(SrvType).MD5Sum();
 }
Пример #4
0
 public AdvertiseServiceOptions(string service, ServiceFunction <MReq, MRes> serviceCallback)
 {
     this.service = service;
     srv_func     = serviceCallback;
     helper       = new ServiceCallbackHelper <MReq, MRes>(serviceCallback);
     req_datatype = new MReq().MessageType.Replace("/Request", "__Request");
     res_datatype = new MRes().MessageType.Replace("/Response", "__Response");
     SrvType      = req_datatype.Replace("__Request", "");
     datatype     = SrvType;
     md5sum       = RosService.Generate(SrvType).MD5Sum();
 }
Пример #5
0
        private async Task WriteHeader()
        {
            var header = new Dictionary <string, string>
            {
                ["service"]    = name,
                ["md5sum"]     = RosService.Generate(RequestType.Replace("__Request", "").Replace("__Response", "")).MD5Sum(),
                ["callerid"]   = ThisNode.Name,
                ["persistent"] = persistent ? "1" : "0"
            };

            if (headerValues != null)
            {
                foreach (string o in headerValues.Keys)
                {
                    header[o] = headerValues[o];
                }
            }

            await this.connection.WriteHeader(header, cancel).ConfigureAwait(false);
        }
Пример #6
0
        internal void initialize(Connection connection)
        {
            this.connection          = connection;
            connection.DroppedEvent += onConnectionDropped;
            connection.setHeaderReceivedCallback(onHeaderReceived);

            IDictionary <string, string> header = new Dictionary <string, string>
            {
                ["service"]    = name,
                ["md5sum"]     = RosService.Generate(RequestType.Replace("__Request", "").Replace("__Response", "")).MD5Sum(),
                ["callerid"]   = ThisNode.Name,
                ["persistent"] = persistent ? "1" : "0"
            };

            if (header_values != null)
            {
                foreach (string o in header_values.Keys)
                {
                    header[o] = header_values[o];
                }
            }
            connection.writeHeader(header, onHeaderWritten);
        }
Пример #7
0
 public bool call(RosService srv)
 {
     return(call(srv.RequestMessage, ref srv.ResponseMessage));
 }