예제 #1
0
 public Emul8Keywords()
 {
     interaction = new CommandInteractionEater();
     monitor = new Monitor();
     testers = new Dictionary<string, TerminalTester>();
     monitor.Interaction = interaction;
 }
예제 #2
0
        public StdInOutHandler(DetachableIO io, Monitor monitor, bool plainOutput = false)
        {
            this.io = io;
            commandHandler = monitor;

            buffer = new StringBuilder();
            CommandInteraction = new StdInOutInteraction(plainOutput);
            monitor.Interaction = CommandInteraction;
        }
예제 #3
0
 public AdvancedLoggerViewer(Monitor monitor)
 {
     this.monitor = monitor;
     command = new AdvancedLoggerViewerCommand(monitor);
     monitor.RegisterCommand(command);
     
     // start lucene backend as soon as possible
     // in order to gather more log entries
     LuceneLoggerBackend.EnsureBackend();
 }
예제 #4
0
        public MonitorPythonEngine(Monitor monitor)
        {
            string emul8Path;
            if(!Misc.TryGetEmul8Directory(out emul8Path) && !Misc.TryGetEmul8Directory(Directory.GetCurrentDirectory(), out emul8Path))
            { 
                throw new RecoverableException("Could not find emul8 root directory.");
            }
            var monitorPath = Path.Combine(emul8Path, MonitorPyPath);
            if(!File.Exists(monitorPath))
            {
                throw new RecoverableException("Could not load scripts from monitor.py library.");
            }

            var imports = Engine.CreateScriptSourceFromString(Aggregate(Imports));
            imports.Execute(Scope);
            var script = Engine.CreateScriptSourceFromFile(monitorPath); // standard lib
            var compiled_script = script.Compile();
            compiled_script.Execute(Scope);

            Scope.SetVariable("self", monitor);
            Scope.SetVariable("monitor", monitor);
        }
예제 #5
0
        public static void Run(Options options, Action <ObjectCreator.Context> beforeRun = null)
        {
            AppDomain.CurrentDomain.UnhandledException += (sender, e) => CrashHandler.HandleCrash((Exception)e.ExceptionObject);
            XwtProvider xwt = null;

            try
            {
                if (!options.DisableXwt)
                {
                    xwt = new XwtProvider(new WindowedUserInterfaceProvider());
                }
                using (var context = ObjectCreator.Instance.OpenContext())
                {
                    var monitor = new Emul8.UserInterface.Monitor();
                    context.RegisterSurrogate(typeof(Emul8.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();
                }
            }
        }
예제 #6
0
        public static void Run(string[] args)
        {
            var options = new Options();
            var optionsParser = new OptionsParser();
            if(!optionsParser.Parse(options, args))
            {
                return;
            }

            Plugins.XwtProviderPlugin.XwtProvider.StartXwtThread();
            using(var context = ObjectCreator.Instance.OpenContext())
            {
                var monitor = new Emul8.UserInterface.Monitor();
                context.RegisterSurrogate(typeof(Emul8.UserInterface.Monitor), monitor);

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

                Logger.AddBackend(ConsoleBackend.Instance, "console");

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

                var crashHandler = new CrashHandler();
                AppDomain.CurrentDomain.UnhandledException += (sender, e) => crashHandler.HandleCrash(e);

                Shell shell = null;
                Type preferredUARTAnalyzer = null;
                if(options.Port > 0)
                {
                    var io = new IOProvider(new SocketIOSource(options.Port));
                    shell = ShellProvider.GenerateShell(io, monitor, true, false);
                }
                else
                {
                    preferredUARTAnalyzer = typeof(UARTWindowBackendAnalyzer);

                    var terminal = new UARTWindowBackendAnalyzer();
                    shell = ShellProvider.GenerateShell(terminal.IO, monitor);
                    monitor.Quitted += shell.Stop;

                    try
                    {
                        terminal.Show();
                    }
                    catch(InvalidOperationException ex)
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.Error.WriteLine(ex.Message);
                        Emulator.Exit();
                    }
                }
                shell.Quitted += Emulator.Exit;

                if(preferredUARTAnalyzer != null)
                {
                    EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                    EmulationManager.Instance.EmulationChanged += () =>
                    {
                        EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                    };
                }
                monitor.Interaction = shell.Writer;
                monitor.MachineChanged += emu => shell.SetPrompt(emu != null ? new Prompt(string.Format("({0}) ", emu), ConsoleColor.DarkYellow) : null);

                if(options.Execute != null)
                {
                    shell.Started += s => s.InjectInput(string.Format("{0}\n", options.Execute));
                }
                else if(!string.IsNullOrEmpty(options.ScriptPath))
                {
                    shell.Started += s => s.InjectInput(string.Format("i {0}{1}\n", Path.IsPathRooted(options.ScriptPath) ? "@" : "$CWD/", options.ScriptPath));
                }

                new Thread(x => shell.Start(true)) 
                { 
                    IsBackground = true, 
                    Name = "Shell thread" 
                }.Start();

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

                Emulator.WaitForExit();
                Plugins.XwtProviderPlugin.XwtProvider.StopXwtThread();
            }
        }
예제 #7
0
 public TraceCommand(Monitor monitor) : base(monitor, "trace", "Hooks up watches for some interesting methods.")
 {
    
     handlers = new Dictionary<string, Type> 
     {
         { "printk", typeof(PrintfHandler) },
         { "printf", typeof(PrintfHandler) }
     };
 }
예제 #8
0
        public static void Run(string[] args)
        {
            var options       = new Options();
            var optionsParser = new OptionsParser();

            if (!optionsParser.Parse(options, args))
            {
                return;
            }

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

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

                Logger.AddBackend(ConsoleBackend.Instance, "console");

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

                var crashHandler = new CrashHandler();
                AppDomain.CurrentDomain.UnhandledException += (sender, e) => crashHandler.HandleCrash(e);

                var resetEvent = new ManualResetEventSlim();
                if (options.StdInOut)
                {
                    Logger.AddBackend(new FileBackend("logger.log"), "file");
                    var world = new StreamIOSource(Console.OpenStandardInput(), Console.OpenStandardOutput());
                    var io    = new DetachableIO(world);
                    monitor.Quitted += resetEvent.Set;
                    var handler = new StdInOutHandler(io, monitor, options.Plain);
                    handler.Start();
                }
                else
                {
                    Shell shell = null;
                    Type  preferredUARTAnalyzer = null;
                    if (options.Port > 0)
                    {
                        var io = new DetachableIO(new SocketIOSource(options.Port));
                        shell          = ShellProvider.GenerateShell(io, monitor, true, false);
                        shell.Quitted += resetEvent.Set;
                    }
                    else if (options.ConsoleMode)
                    {
                        preferredUARTAnalyzer = typeof(UARTMultiplexedBackendAnalyzer);

                        var stream = new PtyUnixStream("/dev/fd/1");
                        var world  = new StreamIOSource(stream, stream.Name);

                        Logger.AddBackend(new FileBackend("logger.log"), "file");
                        var consoleTerm = new ConsoleTerminal(world);
                        UARTMultiplexedBackendAnalyzer.Multiplexer = consoleTerm;

                        monitor.Console = consoleTerm;

                        shell = ShellProvider.GenerateShell(monitor);
                        consoleTerm.AttachTerminal("shell", shell.Terminal);

                        shell.Quitted += resetEvent.Set;
                    }
                    else
                    {
                        preferredUARTAnalyzer = typeof(UARTWindowBackendAnalyzer);

                        var stream   = new PtyUnixStream();
                        var dio      = new DetachableIO(new StreamIOSource(stream, stream.Name));
                        var terminal = new UARTWindowBackendAnalyzer(dio);
                        shell = ShellProvider.GenerateShell(dio, monitor);

                        shell.Quitted   += resetEvent.Set;
                        monitor.Quitted += shell.Stop;

                        try
                        {
                            terminal.Show();
                        }
                        catch (InvalidOperationException ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Error.WriteLine(ex.Message);
                            resetEvent.Set();
                        }
                    }

                    if (preferredUARTAnalyzer != null)
                    {
                        EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        EmulationManager.Instance.EmulationChanged += () =>
                        {
                            EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        };
                    }
                    monitor.Interaction     = shell.Writer;
                    monitor.UseConsole      = options.ConsoleMode;
                    monitor.MachineChanged += emu => shell.SetPrompt(emu != null ? new Prompt(string.Format("({0}) ", emu), ConsoleColor.DarkYellow) : null);

                    if (options.Execute != null)
                    {
                        shell.Started += s => s.InjectInput(string.Format("{0}\n", options.Execute));
                    }
                    else if (!string.IsNullOrEmpty(options.ScriptPath))
                    {
                        shell.Started += s => s.InjectInput(string.Format("i {0}{1}\n", Path.IsPathRooted(options.ScriptPath) ? "@" : "$CWD/", options.ScriptPath));
                    }

                    new Thread(x => shell.Start(true))
                    {
                        IsBackground = true, Name = "Shell thread"
                    }.Start();
                }

                resetEvent.Wait();
                EmulationManager.Instance.Clear();
                TypeManager.Instance.Dispose();
                Logger.Dispose();
            }
        }
예제 #9
0
 public AdvancedLoggerViewerCommand(Monitor monitor) : base(monitor, "showLogger", "Advanced logger viewer")
 {
 }
예제 #10
0
 public TestCommand(Monitor monitor):base(monitor, "featuresTests.TestCommand", "is just a test command.")
 {
 }
예제 #11
0
 public void SetUp()
 {
     monitor = new Monitor();
 }
예제 #12
0
파일: Program.cs 프로젝트: rte-se/emul8
 public static void Main(string[] args)
 {
     var monitor = new Monitor();
     var prop = typeof(Monitor).GetProperty("Commands", BindingFlags.NonPublic | BindingFlags.Instance);
     var commands = (HashSet<Command>)prop.GetValue(monitor, null);
     using(var writer = new StreamWriter(@"doc/source/command_descriptions.rst"))
     {
         writer.WriteLine(".. glossary::");
         writer.WriteLine();
         foreach(var command in commands.OrderBy(x => x.Name))
         {
             writer.WriteLine("   {0}", command.Name);
             writer.WriteLine("      {0}", command.Description);
             if(command.AlternativeNames.Count() > 0)
             {
                 writer.WriteLine();
                 writer.WriteLine("      short: **{0}**", command.AlternativeNames.Aggregate((x,y) => x + ", " + y));
             }
             if(additionalExplanations.ContainsKey(command.Name))
             {
                 writer.WriteLine();
                 var lines = additionalExplanations[command.Name];
                 foreach (var line in lines) {
                     writer.WriteLine("{0}{1}", line.Length > 0 ? "      " : "",  line);
                 }
             }
             writer.WriteLine();
         }
     }
 }
예제 #13
0
 public void SetUp()
 {
     monitor = new Monitor();
     commandEater = new CommandInteractionEater();
     loggerBackend = new DummyLoggerBackend();
     Logger.AddBackend(loggerBackend, "dummy");
 }
예제 #14
0
 public HelloCommand(Monitor monitor) : base(monitor, "hello", "Greets a user.")
 {
 }
예제 #15
0
 public TracePlugin(Monitor monitor)
 {
     this.monitor = monitor;           
     traceCommand = new TraceCommand(monitor);
     monitor.RegisterCommand(traceCommand);
 }
예제 #16
0
 public SampleCommandPlugin(Monitor monitor)
 {
     this.monitor = monitor;            
     helloCommand = new HelloCommand(monitor);
     monitor.RegisterCommand(helloCommand);
 }
예제 #17
0
        public static void Run(string[] args)
        {
            var options = new Options();
            var optionsParser = new OptionsParser();
            if(!optionsParser.Parse(options, args))
            {
                return;
            }

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

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

                Logger.AddBackend(ConsoleBackend.Instance, "console");

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

                var crashHandler = new CrashHandler();
                AppDomain.CurrentDomain.UnhandledException += (sender, e) => crashHandler.HandleCrash(e);

                var resetEvent = new ManualResetEventSlim();
                if(options.StdInOut)
                {
                    Logger.AddBackend(new FileBackend("logger.log"), "file");
                    var world = new StreamIOSource(Console.OpenStandardInput(), Console.OpenStandardOutput());
                    var io = new DetachableIO(world);
                    monitor.Quitted += resetEvent.Set;
                    var handler = new StdInOutHandler(io, monitor, options.Plain);
                    handler.Start();
                }
                else
                {
                    Shell shell = null;
                    Type preferredUARTAnalyzer = null;
                    if(options.Port > 0)
                    {
                        var io = new DetachableIO(new SocketIOSource(options.Port));
                        shell = ShellProvider.GenerateShell(io, monitor, true, false);
                        shell.Quitted += resetEvent.Set;
                    }
                    else if(options.ConsoleMode)
                    {
                        preferredUARTAnalyzer = typeof(UARTMultiplexedBackendAnalyzer);

                        var stream = new PtyUnixStream("/proc/self/fd/1");
                        var world = new StreamIOSource(stream, stream.Name);

                        Logger.AddBackend(new FileBackend("logger.log"), "file");
                        var consoleTerm = new ConsoleTerminal(world);
                        UARTMultiplexedBackendAnalyzer.Multiplexer = consoleTerm;
                   
                        monitor.Console = consoleTerm;

                        shell = ShellProvider.GenerateShell(monitor);
                        consoleTerm.AttachTerminal("shell", shell.Terminal);

                        shell.Quitted += resetEvent.Set;
                    }
                    else
                    {
                        preferredUARTAnalyzer = typeof(UARTWindowBackendAnalyzer);

                        var stream = new PtyUnixStream();
                        var dio = new DetachableIO(new StreamIOSource(stream, stream.Name));
                        var terminal = new UARTWindowBackendAnalyzer(dio);
                        shell = ShellProvider.GenerateShell(dio, monitor);     

                        shell.Quitted += resetEvent.Set;
                        monitor.Quitted += shell.Stop;

                        try
                        {
                            terminal.Show();
                        }
                        catch(InvalidOperationException ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Error.WriteLine(ex.Message);
                            resetEvent.Set();
                        }
                    }

                    if(preferredUARTAnalyzer != null)
                    {
                        EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        EmulationManager.Instance.EmulationChanged += () =>
                        {
                            EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        };
                    }
                    monitor.Interaction = shell.Writer;
                    monitor.UseConsole = options.ConsoleMode;
                    monitor.MachineChanged += emu => shell.SetPrompt(emu != null ? new Prompt(string.Format("({0}) ", emu), ConsoleColor.DarkYellow) : null);

                    if(options.Execute != null)
                    {
                        shell.Started += s => s.InjectInput(string.Format("{0}\n", options.Execute));
                    }
                    else if(!string.IsNullOrEmpty(options.ScriptPath))
                    {
                        shell.Started += s => s.InjectInput(string.Format("i $CWD/{0}\n", options.ScriptPath));
                    }

                    new Thread(x => shell.Start(true)) { IsBackground = true, Name = "Shell thread" }.Start();
                }

                resetEvent.Wait();
                EmulationManager.Instance.Clear();
                TypeManager.Instance.Dispose();
                Logger.Dispose();
            }
        }
예제 #18
0
        public static void Main(string[] args)
        {
            var options       = new Emul8.Robot.Options();
            var optionsParser = new OptionsParser();

            if (!optionsParser.Parse(options, args))
            {
                return;
            }

            var keywordManager = new KeywordManager();

            TypeManager.Instance.AutoLoadedType += keywordManager.Register;

            var processor = new XmlRpcServer(keywordManager);

            server = new HttpServer(processor);

            Task.Run(() =>
            {
                XwtProvider xwt = null;
                try
                {
                    if (!options.DisableX11)
                    {
                        var preferredUARTAnalyzer = typeof(UARTWindowBackendAnalyzer);
                        EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        EmulationManager.Instance.EmulationChanged += () =>
                        {
                            EmulationManager.Instance.CurrentEmulation.BackendManager.SetPreferredAnalyzer(typeof(UARTBackend), preferredUARTAnalyzer);
                        };
                        xwt = new XwtProvider(new WindowedUserInterfaceProvider());
                    }

                    using (var context = ObjectCreator.Instance.OpenContext())
                    {
                        var monitor = new Emul8.UserInterface.Monitor()
                        {
                            Interaction = new CommandInteractionEater()
                        };
                        context.RegisterSurrogate(typeof(Emul8.UserInterface.Monitor), monitor);

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

                        server.Run(options.Port);
                        server.Dispose();
                    }
                }
                finally
                {
                    if (xwt != null)
                    {
                        xwt.Dispose();
                    }
                }
            });

            Emulator.ExecuteAsMainThread();
        }