Esempio n. 1
0
 public static string Sum(SrvTypes m)
 {
     if (!srvmd5memo.ContainsKey(m))
     {
         IRosService irm = IRosService.generate(m);
         string req = PrepareToHash(irm.RequestMessage);
         string res = PrepareToHash(irm.ResponseMessage);
         srvmd5memo.Add(m,Sum(req, res));
     }
     return srvmd5memo[m];
 }
Esempio n. 2
0
 public void init(string service, ServiceFunction <MReq, MRes> callback)
 {
     this.service = service;
     srv_func     = callback;
     helper       = new ServiceCallbackHelper <MReq, MRes>(callback);
     req_datatype = new MReq().msgtype.ToString().Replace("__", "/").Replace("/Request", "__Request");
     res_datatype = new MRes().msgtype.ToString().Replace("__", "/").Replace("/Response", "__Response");
     srvtype      = (SrvTypes)Enum.Parse(typeof(SrvTypes), req_datatype.Replace("__Request", "").Replace("/", "__"));
     datatype     = srvtype.ToString().Replace("__", "/");
     md5sum       = IRosService.generate(srvtype).MD5Sum;
 }
Esempio n. 3
0
 public static string Sum(SrvTypes m)
 {
     if (!srvmd5memo.ContainsKey(m))
     {
         IRosService irm = IRosService.generate(m);
         string      req = PrepareToHash(irm.RequestMessage);
         string      res = PrepareToHash(irm.ResponseMessage);
         srvmd5memo.Add(m, Sum(req, res));
     }
     return(srvmd5memo[m]);
 }
Esempio n. 4
0
        public static IRosService generate <RequestType> (SrvTypes t) where RequestType : IRosMessage
        {
            lock ( constructors )
            {
                if (constructors.ContainsKey(t))
                {
                    return(constructors [t].Invoke(t));
                }
                Type thistype = typeof(IRosService);
                foreach (Type othertype in Assembly.GetAssembly(typeof(RequestType)).GetTypes())
                {
                    if (thistype == othertype || !othertype.IsSubclassOf(thistype) || othertype.IsAbstract || othertype.Name.Contains("Decorator"))
                    {
                        continue;
                    }
                    IRosService srv = Activator.CreateInstance(othertype) as IRosService;
                    if (srv != null)
                    {
                        if (srv.srvtype() == SrvTypes.Unknown)
                        {
                            throw new Exception("OH NOES IRosService.generate is borked!");
                        }
                        if (!_typeregistry.ContainsKey(srv.srvtype()))
                        {
                            _typeregistry.Add(srv.srvtype(), srv.GetType());
                        }
                        if (!constructors.ContainsKey(srv.srvtype()))
                        {
                            constructors.Add(srv.srvtype(), T => Activator.CreateInstance(_typeregistry [T]) as IRosService);
                        }
                        srv.RequestMessage  = IRosMessage.generate <RequestType> ((MsgTypes)Enum.Parse(typeof(MsgTypes), srv.srvtype().ToString() + "__Request"));
                        srv.ResponseMessage = IRosMessage.generate <RequestType> ((MsgTypes)Enum.Parse(typeof(MsgTypes), srv.srvtype().ToString() + "__Response"));
                    }
                }

                if (constructors.ContainsKey(t))
                {
                    return(constructors [t].Invoke(t));
                }
                else
                {
                    throw new Exception("OH NOES IRosService.generate is borked!");
                }
            }
        }
Esempio n. 5
0
        public static IRosService generate(SrvTypes t)
        {
            if (constructors.ContainsKey(t))
            {
                return(constructors[t].Invoke(t));
            }
            Type thistype = typeof(IRosService);

            foreach (Type othertype in thistype.Assembly.GetTypes())
            {
                if (thistype == othertype || !othertype.IsSubclassOf(thistype))
                {
                    continue;
                }
                IRosService srv = Activator.CreateInstance(othertype) as IRosService;
                if (srv != null)
                {
                    if (srv.srvtype == SrvTypes.Unknown)
                    {
                        throw new Exception("OH NOES IRosMessage.generate is borked!");
                    }
                    if (!_typeregistry.ContainsKey(srv.srvtype))
                    {
                        _typeregistry.Add(srv.srvtype, srv.GetType());
                    }
                    if (!constructors.ContainsKey(srv.srvtype))
                    {
                        constructors.Add(srv.srvtype, T => Activator.CreateInstance(_typeregistry[T]) as IRosService);
                    }
                }
            }
            if (constructors.ContainsKey(t))
            {
                return(constructors[t].Invoke(t));
            }
            else
            {
                throw new Exception("OH NOES IRosMessage.generate is borked!");
            }
        }
Esempio n. 6
0
        public static IRosService generate(SrvTypes t)
        {
            lock (constructors)
            {
                if (constructors.ContainsKey(t))
                    return constructors[t].Invoke(t);
                Type thistype = typeof (IRosService);
                foreach (Type othertype in thistype.Assembly.GetTypes())
                {
                    if (thistype == othertype || !othertype.IsSubclassOf(thistype))
                    {
                        continue;
                    }
                    IRosService srv = Activator.CreateInstance(othertype) as IRosService;
                    if (srv != null)
                    {
                        if (srv.srvtype() == SrvTypes.Unknown)
                            throw new Exception("OH NOES IRosService.generate is borked!");
                        if (!_typeregistry.ContainsKey(srv.srvtype()))
                            _typeregistry.Add(srv.srvtype(), srv.GetType());
                        if (!constructors.ContainsKey(srv.srvtype()))
                            constructors.Add(srv.srvtype(), T => Activator.CreateInstance(_typeregistry[T]) as IRosService);
                        srv.RequestMessage = IRosMessage.generate((MsgTypes) Enum.Parse(typeof (MsgTypes), srv.srvtype() + "__Request"));
                        srv.ResponseMessage = IRosMessage.generate((MsgTypes) Enum.Parse(typeof (MsgTypes), srv.srvtype() + "__Response"));
                    }
                }

                if (constructors.ContainsKey(t))
                    return constructors[t].Invoke(t);
                else
                    throw new Exception("OH NOES IRosService.generate is borked!");
            }
        }
Esempio n. 7
0
 public IRosService(SrvTypes t, string def, string md5)
 {
     srvtype = t;
     ServiceDefinition = def;
     MD5Sum = md5;
 }
Esempio n. 8
0
 public IRosService(SrvTypes t, string def, string md5)
 {
     srvtype           = t;
     ServiceDefinition = def;
     MD5Sum            = md5;
 }