Exemple #1
0
        public static XwtProvider Create(IUserInterfaceProvider uiProvider)
        {
            Emulator.UserInterfaceProvider = uiProvider;
            var xwtProvider = new XwtProvider();

            return((xwtProvider.StartXwtThreadOnMainThread())
                ? xwtProvider
                : null);
        }
Exemple #2
0
        public static XwtProvider Create(IUserInterfaceProvider uiProvider)
        {
#if GUI_DISABLED
            return(null);
#else
            Emulator.UserInterfaceProvider = uiProvider;
            var xwtProvider = new XwtProvider();
            return((xwtProvider.StartXwtThreadOnMainThread())
                ? xwtProvider
                : null);
#endif
        }
Exemple #3
0
        public static void Run(Options options, Action <ObjectCreator.Context> beforeRun = null)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) => CrashHandler.HandleCrash((Exception)e.ExceptionObject);

            if (options.Version)
            {
                Console.Out.WriteLine(EmulationManager.Instance.VersionString);
                return;
            }

            if (!options.HideLog)
            {
                Logger.AddBackend(ConsoleBackend.Instance, "console");
            }
            else
            {
                Logger.AddBackend(new DummyLoggerBackend(), "dummy");
            }

            Logger.AddBackend(new MemoryBackend(), "memory");
            Emulator.ShowAnalyzers = !options.HideAnalyzers;
            XwtProvider xwt = null;

            if (options.PidFile != null)
            {
                var pid = Process.GetCurrentProcess().Id;
                File.WriteAllText(options.PidFile, pid.ToString());
            }

            if (!options.DisableXwt || options.RobotDebug)
            {
                xwt = XwtProvider.Create(new WindowedUserInterfaceProvider());
            }

            if (xwt == null && options.RobotFrameworkRemoteServerPort == -1 && !options.Console)
            {
                if (options.Port == -1)
                {
                    options.Port = 1234;
                }

                if (!options.DisableXwt)
                {
                    Logger.Log(LogLevel.Warning, "Couldn't start UI - falling back to telnet mode");
                }
            }

            using (var context = ObjectCreator.Instance.OpenContext())
            {
                var monitor = new Antmicro.Renode.UserInterface.Monitor();
                context.RegisterSurrogate(typeof(Antmicro.Renode.UserInterface.Monitor), monitor);

                // we must initialize plugins AFTER registering monitor surrogate
                // as some plugins might need it for construction
                TypeManager.Instance.PluginManager.Init("CLI");

                EmulationManager.Instance.ProgressMonitor.Handler = new CLIProgressMonitor();

                var uartAnalyzerType  = (xwt == null || options.RobotDebug) ? typeof(LoggingUartAnalyzer) : typeof(ConsoleWindowBackendAnalyzer);
                var videoAnalyzerType = (xwt == null || options.RobotDebug) ? typeof(DummyVideoAnalyzer) : typeof(VideoAnalyzer);

                EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), uartAnalyzerType);
                EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(VideoBackend), videoAnalyzerType);
                EmulationManager.Instance.EmulationChanged += () =>
                {
                    EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), uartAnalyzerType);
                    EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(VideoBackend), videoAnalyzerType);
                };

                var shell = PrepareShell(options, monitor);
                new System.Threading.Thread(x => shell.Start(true))
                {
                    IsBackground = true,
                    Name         = "Shell thread"
                }.Start();

                Emulator.BeforeExit += () =>
                {
                    Emulator.DisposeAll();
                    xwt?.Dispose();
                    xwt = null;
                };

                if (beforeRun != null)
                {
                    beforeRun(context);
                }

                if (options.RobotDebug)
                {
                    ConsoleWindowBackendAnalyzer terminal = null;

                    Emulator.EnableGUI += () =>
                    {
                        Logger.AddBackend(ConsoleBackend.Instance, "console", true);
                        terminal = new ConsoleWindowBackendAnalyzer(true);
                        terminal.Show();
                        shell.Terminal = new NavigableTerminalEmulator(terminal.IO);
                        new System.Threading.Thread(x => shell.Start(true))
                        {
                            IsBackground = true,
                            Name         = "Shell thread"
                        }.Start();
                    };

                    Emulator.DisableGUI += () =>
                    {
                        if (options.HideLog)
                        {
                            Logger.RemoveBackend(ConsoleBackend.Instance);
                        }
                        terminal?.Hide();
                        terminal = null;
                    };
                }

                Emulator.WaitForExit();
            }
        }
Exemple #4
0
        public static void Run(Options options, Action <ObjectCreator.Context> beforeRun = null)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) => CrashHandler.HandleCrash((Exception)e.ExceptionObject);
            Emulator.ShowAnalyzers = !options.HideAnalyzers;
            XwtProvider xwt = null;

            try
            {
                if (!options.DisableXwt)
                {
                    xwt = new XwtProvider(new WindowedUserInterfaceProvider());
                }
                using (var context = ObjectCreator.Instance.OpenContext())
                {
                    var monitor = new Antmicro.Renode.UserInterface.Monitor();
                    context.RegisterSurrogate(typeof(Antmicro.Renode.UserInterface.Monitor), monitor);

                    // we must initialize plugins AFTER registering monitor surrogate
                    // as some plugins might need it for construction
                    TypeManager.Instance.PluginManager.Init("CLI");

                    if (!options.HideLog)
                    {
                        Logger.AddBackend(ConsoleBackend.Instance, "console");
                    }

                    EmulationManager.Instance.ProgressMonitor.Handler = new CLIProgressMonitor();

                    if (options.Port == -1)
                    {
                        EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), typeof(ConsoleWindowBackendAnalyzer));
                        EmulationManager.Instance.EmulationChanged += () =>
                        {
                            EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), typeof(ConsoleWindowBackendAnalyzer));
                        };
                    }

                    var shell = PrepareShell(options, monitor);
                    new System.Threading.Thread(x => shell.Start(true))
                    {
                        IsBackground = true,
                        Name         = "Shell thread"
                    }.Start();

                    Emulator.BeforeExit += () =>
                    {
                        Emulator.DisposeAll();
                    };

                    if (beforeRun != null)
                    {
                        beforeRun(context);
                    }

                    Emulator.WaitForExit();
                }
            }
            finally
            {
                if (xwt != null)
                {
                    xwt.Dispose();
                }
            }
        }