コード例 #1
0
        public DebugAdapter(Type mmuType, int hostingPort = 8999, string registerAddress = "127.0.0.1", int registerPort = 9009)
        {
            RegisterAddress = new MIPAddress(registerAddress, registerPort);

            //Create a new logger instance
            Logger.Instance = new Logger
            {
                //Log everything
                Level = Log_level.L_DEBUG
            };

            MAdapterDescription adapterDescription = new MAdapterDescription()
            {
                ID         = Guid.NewGuid().ToString(),
                Language   = "C#",
                Name       = "Debug Adapter C#",
                Properties = new Dictionary <string, string>(),
                Addresses  = new List <MIPAddress>()
                {
                    new MIPAddress("127.0.0.1", hostingPort)
                }
            };

            adapterController = new AdapterController(SessionData, adapterDescription, RegisterAddress, new MMUProvider(mmuType), new MMUInstantiator(mmuType));
            adapterController.StartAsync();
        }
コード例 #2
0
 /// <summary>
 /// Basic constructor
 /// </summary>
 /// <param name="webserverAddress"></param>
 /// <param name="filepath"></param>
 public RemoteAdapter(MAdapterDescription description)
 {
     this.Name        = description.Name;
     this.Description = description;
     this.Address     = description.Addresses[0].Address;
     this.Port        = description.Addresses[0].Port;
 }
コード例 #3
0
        /// <summary>
        /// Adds a new adapter to the access.
        /// </summary>
        /// <param name="adapter"></param>
        public void AddAdapter(MAdapterDescription description, MMIAdapter.Iface adapter)
        {
            IAdapter newAdapter = new LocalAdapterAccess(description, adapter, this);

            //Check if the adapter is already available as a remote one
            if (this.Adapters.Exists(s => s.Description.Name == description.Name && description.Addresses[0] == description.Addresses[0] && s.Description.Addresses[0].Port == description.Addresses[0].Port))
            {
                //Find the old adapter
                IAdapter oldAdapter = this.Adapters.Find(s => s.Description.Name == description.Name && description.Addresses[0] == description.Addresses[0] && s.Description.Addresses[0].Port == description.Addresses[0].Port);

                //Find MMUs which utilize the old adapter
                List <Abstraction.MotionModelUnitAccess> mmusWithOldAdapter = this.MotionModelUnits.Where(s => ((Abstraction.MotionModelUnitAccess)s).Adapter == oldAdapter).Select(s => ((Abstraction.MotionModelUnitAccess)s)).ToList();

                //Change the adapter to the new one
                foreach (Abstraction.MotionModelUnitAccess mmu in mmusWithOldAdapter)
                {
                    mmu.ChangeAdapter(newAdapter);
                }

                //Disposes the adapter
                oldAdapter.Dispose();

                //Remove the old adapter
                this.Adapters.Remove(oldAdapter);
            }

            //Add the new adapter
            this.Adapters.Add(newAdapter);
        }
コード例 #4
0
 /// <summary>
 /// Main constructor
 /// </summary>
 /// <param name="address"></param>
 /// <param name="port"></param>
 /// <param name="mmuAccess"></param>
 public RemoteAdapterAccess(string address, int port, MAdapterDescription adapterDescription, MMUAccess mmuAccess)
 {
     this.Address     = address;
     this.Port        = port;
     this.mmuAccess   = mmuAccess;
     this.Description = adapterDescription;
 }
コード例 #5
0
        /// <summary>
        /// Method is utilized to register an external adapter
        /// </summary>
        /// <param name="adapterDescription"></param>
        /// <returns></returns>
        public virtual MBoolResponse RegisterAdapter(MAdapterDescription adapterDescription)
        {
            //Check if the adapter description is already available
            if (RuntimeData.AdapterInstances.ContainsKey(adapterDescription.ID))
            {
                Console.WriteLine($"Adapter: {adapterDescription.Name} already available -> nothing to do.");
                return(new MBoolResponse(true));
            }

            ////Add a new remote adapter
            RemoteAdapter remoteAdapter = new RemoteAdapter(adapterDescription);

            remoteAdapter.Start();

            //Add the newly generated adapter description
            if (!RuntimeData.AdapterInstances.TryAdd(adapterDescription.ID, remoteAdapter))
            {
                Console.WriteLine($"Cannot add adapter description {adapterDescription.Name}");
            }

            //Fire event
            this.OnAdapterRegistered?.Invoke(this, remoteAdapter);

            return(new MBoolResponse(true));
        }
コード例 #6
0
        /// <summary>
        /// Basic constructor
        /// </summary>
        /// <param name="registerAddress"></param>
        /// <param name="description"></param>
        public AdapterRegistrationHandler(MIPAddress registerAddress, MAdapterDescription description, bool autoStart = true)
        {
            this.address     = registerAddress;
            this.description = description;
            this.thread      = new Thread(new ThreadStart(this.HandleRegistration));
            this.cts         = new CancellationTokenSource();

            if (autoStart)
            {
                this.Start();
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            MAdapterDescription adapterDescription = new MAdapterDescription()
            {
                ID         = Guid.NewGuid().ToString(),
                Language   = "C#",
                Name       = "Debug Adapter C#",
                Properties = new Dictionary <string, string>(),
                Addresses  = new List <MIPAddress>()
                {
                    new MIPAddress("127.0.0.1", 8999)
                }
            };


            using (AdapterController adapterController = new AdapterController(SessionData, adapterDescription, RegisterAddress, new MMUProvider(), new MMUInstantiator()))
            {
                adapterController.Start();
                Console.ReadLine();
            }
        }
コード例 #8
0
        /// <summary>
        /// Checks whether the registration is already available at the register
        /// </summary>
        /// <param name="adapterDescription"></param>
        /// <returns></returns>
        private bool RegistrationAvailable(MAdapterDescription adapterDescription)
        {
            try
            {
                using (MMIRegisterServiceClient client = new MMIRegisterServiceClient(this.address.Address, this.address.Port))
                {
                    client.Start();

                    List <MAdapterDescription> adapterDescriptions = client.Access.GetRegisteredAdapters("");

                    if (adapterDescriptions.Exists(s => s.ID == adapterDescription.ID && s.Addresses.Exists(x => x.Address == adapterDescription.Addresses[0].Address && x.Port == adapterDescription.Addresses[0].Port)))
                    {
                        return(true);
                    }
                }
            }
            catch (Exception)
            {
            }

            return(false);
        }
コード例 #9
0
        /// <summary>
        /// Method is called if an adapter should be unregistered
        /// </summary>
        /// <param name="adapterDescription"></param>
        /// <returns></returns>
        public MBoolResponse UnregisterAdapter(MAdapterDescription adapterDescription)
        {
            if (!RuntimeData.AdapterInstances.ContainsKey(adapterDescription.ID))
            {
                //Nothing to do no adapter available
                return(new MBoolResponse(true));
            }


            if (RuntimeData.AdapterInstances.ContainsKey(adapterDescription.ID))
            {
                RemoteAdapter adapter = null;

                RuntimeData.AdapterInstances.TryGetValue(adapterDescription.ID, out adapter);

                //Dispose the adapter
                adapter.Dispose();

                //Remove the adapter
                RuntimeData.AdapterInstances.TryRemove(adapterDescription.ID, out adapter);

                //Fire event
                this.OnAdapterUnregistered?.Invoke(this, adapter);

                return(new MBoolResponse(true));
            }


            Console.WriteLine("No matching adapter to unregister found");
            return(new MBoolResponse(false)
            {
                LogData = new List <string>()
                {
                    "No matching adapter found"
                }
            });
        }
コード例 #10
0
        /// <summary>
        /// Basic constructor
        /// </summary>
        /// <param name="description">The adapter description. The first address in  the Addressed field is used for hosting the server.</param>
        /// <param name="mmiRegisterAddress">The address of the register (where all services, adapters and mmus are registered)</param>
        /// <param name="mmuPath">The path where the MMUs are located</param>
        /// <param name="mmuProvider">A class which provides information regarding the available MMUs</param>
        /// <param name="mmuInstantiatior">A class which can instantiate MMUs based on the file and description</param>
        /// <param name="customAdapterImplementation">An optionally specified customAdapterImplementation which is utilized instead of the default one</param>
        public AdapterController(SessionData sessionData, MAdapterDescription description, MIPAddress mmiRegisterAddress, IMMUProvider mmuProvider, IMMUInstantiation mmuInstantiatior, MMIAdapter.Iface customAdapterImplementation = null)
        {
            //Assign the session data
            this.SessionData = sessionData;

            //Is the default implementation if not explicitly set
            if (customAdapterImplementation == null)
            {
                this.adapterImplementation = new ThriftAdapterImplementation(sessionData, mmuInstantiatior);
            }
            else
            {
                this.adapterImplementation = customAdapterImplementation;
            }

            //Assign the adapter implementation instance
            SessionData.AdapterInstance = this.adapterImplementation;

            //Assign the mmu instantiator
            this.mmuInstantiator = mmuInstantiatior;
            this.mmuProvider     = mmuProvider;

            //Assign the adapter description
            this.adapterDescription        = description;
            SessionData.AdapterDescription = description;

            //Assign the addresses
            this.address            = description.Addresses[0];
            this.mmiRegisterAddress = mmiRegisterAddress;

            //Assign the MMI register address
            SessionData.MMIRegisterAddress = mmiRegisterAddress;

            //Register on changed event
            this.mmuProvider.MMUsChanged += MmuProvider_MMUsChanged;
        }
コード例 #11
0
        /// <summary>
        /// Entry routine
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            //Create a new logger instance
            Logger.Instance = new Logger
            {
                //Log everything
                Level = Log_level.L_DEBUG
            };

            //Register for unhandled exceptions in the application
            AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;



            Console.WriteLine(@"   ______  __ __     ___       __            __           ");
            Console.WriteLine(@"  / ____/_/ // /_   /   | ____/ /___ _____  / /____  _____");
            Console.WriteLine(@" / /   /_  _  __/  / /| |/ __  / __ `/ __ \/ __/ _ \/ ___/");
            Console.WriteLine(@"/ /___/_  _  __/  / ___ / /_/ / /_/ / /_/ / /_/  __/ /    ");
            Console.WriteLine(@"\____/ /_//_/    /_/  |_\__,_/\__,_/ .___/\__/\___/_/     ");
            Console.WriteLine(@"                                  /_/                     ");
            Console.WriteLine(@"_________________________________________________________________");



            //Parse the command line arguments
            if (!ParseCommandLineArguments(args))
            {
                Logger.Log(Log_level.L_ERROR, "Cannot parse the command line arguments. Closing the adapter!");
                return;
            }

            Console.WriteLine($"Adapter is reachable at: {address.Address}:{address.Port}");
            Console.WriteLine($"Register is reachable at: {mmiRegisterAddress.Address}:{mmiRegisterAddress.Port}");
            Console.WriteLine($"MMUs will be loaded from: {mmuPath}");
            Console.WriteLine(@"_________________________________________________________________");


            //Create the adapter description -> To do load from file in future
            MAdapterDescription adapterDescription = new MAdapterDescription()
            {
                Name      = "CSharpAdapter",
                Addresses = new List <MIPAddress>()
                {
                    address
                },
                ID         = "438543643-436436435-2354235",
                Language   = "C#",
                Parameters = new List <MParameter>(),
                Properties = new Dictionary <string, string>()
            };


            //Create a session cleaner for the utilized session data
            sessionCleaner = new SessionCleaner(sessionData)
            {
                //Session shoould be cleaned after 60 minutes
                Timeout = TimeSpan.FromMinutes(60),

                //The session cleaner should check every minute
                UpdateTime = TimeSpan.FromMinutes(1)
            };

            //Start the session cleaner
            sessionCleaner.Start();

            //Create a new adapter controller which scans the filesystem and checks for MMUs there
            using (AdapterController adapterController = new AdapterController(sessionData, adapterDescription, mmiRegisterAddress, new FileBasedMMUProvider(sessionData, new List <string>()
            {
                mmuPath
            }, new List <string>()
            {
                "C#", "C++CLR"
            }), new CSharpMMUInstantiator()))
            {
                //Start the adapter controller
                adapterController.Start();

                Console.ReadLine();
            }
        }
コード例 #12
0
        /// <summary>
        /// Basic awake method
        /// </summary>
        private void Awake()
        {
            //Determine if server build
            isServerBuild = IsHeadlessMode();

            //Set the logger to a unity specific one (using debug log)
            MMICSharp.Adapter.Logger.Instance = new UnityLogger(isServerBuild)
            {
                //Log everything
                Level = Log_level.L_DEBUG
            };

            //Assign the instance
            Instance = this;


            //Only visualizes the text if server build
            if (isServerBuild)
            {
                Console.WriteLine(@"   __  __      _ __           ___       __            __           ");
                Console.WriteLine(@"  / / / /___  (_) /___  __   /   | ____/ /___ _____  / /____  _____");
                Console.WriteLine(@" / / / / __ \/ / __ / / / /  / /| |/ __ / __ `/ __ \/ __ / _ \/ ___ / ");
                Console.WriteLine(@"/ /_/ / / / / / /_/ /_/ /  / ___ / /_/ / /_/ / /_/ / /_/  __/ /    ");
                Console.WriteLine(@"\____/_/ /_/_/\__/\__, /  /_/  |_\__,_/\__,_/ .___/\__/\___/_/     ");
                Console.WriteLine(@"                 /____/                    /_/                     ");
                Console.WriteLine(@"_________________________________________________________________");
            }



            //Only use this if self_hosted and within edit mode -> Otherwise the launcher which starts the service assigns the address and port
#if UNITY_EDITOR
            this.address.Address = "127.0.0.1";
            this.address.Port    = 8950;

            this.registerAddress.Port    = 9009;
            this.registerAddress.Address = "127.0.0.1";
#else
            //Parse the command line arguments
            if (!this.ParseCommandLineArguments(System.Environment.GetCommandLineArgs()))
            {
                MMICSharp.Adapter.Logger.Log(Log_level.L_ERROR, "Cannot parse the command line arguments. The adapter is meant to be started with specified arguments only.");
                return;
            }
#endif


            //Create a new session data
            this.sessionData = new SessionData();

            //Create a session cleaner for the utilized session data
            this.sessionCleaner = new SessionCleaner(sessionData)
            {
                //Session shoould be cleaned after 60 minutes
                Timeout = TimeSpan.FromMinutes(60),

                //The session cleaner should check every minute
                UpdateTime = TimeSpan.FromMinutes(1)
            };


            //Set the quality properties
            Application.targetFrameRate = 30;
            QualitySettings.SetQualityLevel(0, true);

            //Create an adapter description -> to do in future load properties such as the ID from file
            MAdapterDescription adapterDescription = new MAdapterDescription()
            {
                ID        = "14456546241413414",
                Addresses = new List <MIPAddress>()
                {
                    this.address
                },
                Name       = "UnityAdapter",
                Language   = "UnityC#",
                Parameters = new List <MParameter>(),
                Properties = new Dictionary <string, string>()
            };

            //Create a new adapter controller which listens on the file system and scans for MMUs
            this.adapterController = new AdapterController(this.sessionData, adapterDescription, mmiRegisterAddress, new FileBasedMMUProvider(sessionData, mmuPath, "UnityC#", "Unity"), new UnityMMUInstantiator());


            //Log the startup info text
            MMICSharp.Adapter.Logger.Log(Log_level.L_INFO, $"Hosting thrift server at {this.address.Address} {this.address.Port}: ");
        }
コード例 #13
0
 /// <summary>
 /// Basic constructor
 /// </summary>
 /// <param name="description"></param>
 /// <param name="instance"></param>
 public LocalAdapterAccess(MAdapterDescription description, MMIAdapter.Iface instance, MMUAccess mmuAccess)
 {
     this.Description = description;
     this.instance    = instance;
     this.mmuAccess   = mmuAccess;
 }