1 // 2 // Copyright (c) 2010-2023 Antmicro 3 // 4 // This file is licensed under the MIT License. 5 // Full license text is available in 'licenses/MIT.txt'. 6 // 7 using System.Collections.Generic; 8 9 namespace Antmicro.Renode.RobotFramework 10 { 11 public class Recorder 12 { Recorder()13 static Recorder() 14 { 15 Instance = new Recorder(); 16 } 17 18 public static Recorder Instance { get; private set; } 19 RecordEvent(string name, object[] args, Replay replayMode = Replay.InReexecutionMode)20 public void RecordEvent(string name, object[] args, Replay replayMode = Replay.InReexecutionMode) 21 { 22 events.Add(new Event { Name = name, Arguments = args, ReplayMode = replayMode}); 23 } 24 SaveCurrentState(string name)25 public void SaveCurrentState(string name) 26 { 27 // this is to allow overwriting when running tests with -n argument 28 savedStates[name] = new List<Event>(events); 29 } 30 TryGetState(string name, out List<Event> events)31 public bool TryGetState(string name, out List<Event> events) 32 { 33 return savedStates.TryGetValue(name, out events); 34 } 35 ClearEvents()36 public void ClearEvents() 37 { 38 events.Clear(); 39 } 40 Recorder()41 private Recorder() 42 { 43 events = new List<Event>(); 44 savedStates = new Dictionary<string, List<Event>>(); 45 } 46 47 private readonly List<Event> events; 48 private readonly Dictionary<string, List<Event>> savedStates; 49 50 public struct Event 51 { 52 public string Name { get; set; } 53 public object[] Arguments { get; set; } 54 public Replay ReplayMode { get; set; } 55 } 56 } 57 } 58