1 // 2 // Copyright (c) 2010-2018 Antmicro 3 // Copyright (c) 2011-2015 Realtime Embedded 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 using System; 9 using Antmicro.Renode.Core.Structure; 10 using Antmicro.Renode.Utilities; 11 using Antmicro.Migrant; 12 using Antmicro.Migrant.Hooks; 13 using Antmicro.Renode.Peripherals; 14 15 namespace Antmicro.Renode.Core 16 { 17 public sealed class PeripheralTreeEntry 18 { PeripheralTreeEntry(IPeripheral peripheral, IPeripheral parent, Type type, IRegistrationPoint registrationPoint, string name, int level)19 public PeripheralTreeEntry(IPeripheral peripheral, IPeripheral parent, Type type, IRegistrationPoint registrationPoint, string name, int level) 20 { 21 this.type = type; 22 Name = name; 23 RegistrationPoint = registrationPoint; 24 Peripheral = peripheral; 25 Parent = parent; 26 Level = level; 27 } 28 29 public Type Type 30 { 31 get 32 { 33 return type; 34 } 35 } 36 ToString()37 public override string ToString() 38 { 39 return string.Format("[PeripheralTreeEntry: Type={0}, Peripheral={1}, Parent={2}, Name={3}, Level={4}, RegistrationPoint={5}]", 40 Type, Peripheral.GetType(), Parent == null ? "(none)" : Parent.GetType().ToString(), Name, Level, RegistrationPoint); 41 } 42 Reparent(PeripheralTreeEntry entry)43 public void Reparent(PeripheralTreeEntry entry) 44 { 45 Parent = entry.Parent; 46 Level = entry.Level + 1; 47 } 48 49 public IPeripheral Peripheral { get; private set; } 50 public IPeripheral Parent { get; private set; } 51 public string Name { get; private set; } 52 public int Level { get; private set; } 53 public IRegistrationPoint RegistrationPoint { get; private set; } 54 55 [PreSerialization] SaveType()56 private void SaveType() 57 { 58 typeName = type.FullName; 59 } 60 61 [PostDeserialization] RecoverType()62 private void RecoverType() 63 { 64 type = TypeManager.Instance.GetTypeByName(typeName); 65 typeName = null; 66 } 67 68 [Transient] 69 private Type type; 70 private string typeName; 71 } 72 } 73 74