public void Dispose() { FileFetcher.CancelDownload(); lock (machLock) { PauseAll(); Array.ForEach(machs.Rights, x => x.Dispose()); machs.Clear(); MasterTimeSource.Dispose(); ExternalsManager.Clear(); HostMachine.Dispose(); CurrentLogger.Dispose(); BackendManager.Dispose(); } }
public bool TryGetEmulationElementByName(string name, object context, out IEmulationElement element) { if (name == null) { element = null; return(false); } var machineContext = context as Machine; if (machineContext != null) { IPeripheral outputPeripheral; if ((machineContext.TryGetByName(name, out outputPeripheral) || machineContext.TryGetByName(string.Format("sysbus.{0}", name), out outputPeripheral))) { element = outputPeripheral; return(true); } } Machine machine; if (TryGetMachineByName(name, out machine)) { element = machine; return(true); } IExternal external; if (ExternalsManager.TryGetByName(name, out external)) { element = external; return(true); } IHostMachineElement hostMachineElement; if (name.StartsWith(string.Format("{0}.", HostMachine.HostMachineName)) && HostMachine.TryGetByName(name.Substring(HostMachine.HostMachineName.Length + 1), out hostMachineElement)) { element = hostMachineElement; return(true); } element = null; return(false); }
public void Dispose() { FileFetcher.CancelDownload(); lock (machLock) { var toDispose = machs.Rights.ToArray(); //Although a single machine does not have to be paused before its disposal, //disposing multiple entities has to ensure that all are stopped. ExternalsManager.Pause(); Array.ForEach(toDispose, x => x.Pause()); Array.ForEach(toDispose, x => x.Dispose()); machs.Clear(); ExternalsManager.Clear(); HostMachine.Dispose(); CurrentLogger.Dispose(); BackendManager.Dispose(); } }
public Emulation() { MasterTimeSource = new MasterTimeSource(); HostMachine = new HostMachine(); MACRepository = new MACRepository(); ExternalsManager = new ExternalsManager(); ExternalsManager.AddExternal(HostMachine, HostMachine.HostMachineName); Connector = new Connector(); FileFetcher = new CachingFileFetcher(); CurrentLogger = Logger.GetLogger(); randomGenerator = new Lazy <PseudorandomNumberGenerator>(() => new PseudorandomNumberGenerator()); nameCache = new LRUCache <object, Tuple <string, string> >(NameCacheSize); peripheralToMachineCache = new LRUCache <IPeripheral, Machine>(PeripheralToMachineCacheSize); machs = new FastReadConcurrentTwoWayDictionary <string, Machine>(); machs.ItemAdded += (name, machine) => { machine.StateChanged += OnMachineStateChanged; machine.PeripheralsChanged += (m, e) => { if (e.Operation != PeripheralsChangedEventArgs.PeripheralChangeType.Addition) { nameCache.Invalidate(); peripheralToMachineCache.Invalidate(); } }; OnMachineAdded(machine); }; machs.ItemRemoved += (name, machine) => { machine.StateChanged -= OnMachineStateChanged; nameCache.Invalidate(); peripheralToMachineCache.Invalidate(); OnMachineRemoved(machine); }; BackendManager = new BackendManager(); BlobManager = new BlobManager(); theBag = new Dictionary <string, object>(); }
public bool TryGetEmulationElementName(object obj, out string name, out string containerName) { if (obj == null) { name = null; containerName = null; return(false); } Tuple <string, string> result; if (nameCache.TryGetValue(obj, out result)) { name = result.Item1; containerName = result.Item2; return(true); } containerName = null; var objAsIPeripheral = obj as IPeripheral; if (objAsIPeripheral != null) { Machine machine; string machName; if (TryGetMachineForPeripheral(objAsIPeripheral, out machine) && TryGetMachineName(machine, out machName)) { containerName = machName; if (Misc.IsPythonObject(obj)) { name = Misc.GetPythonName(obj); } else { if (!machine.TryGetAnyName(objAsIPeripheral, out name)) { name = Machine.UnnamedPeripheral; } } nameCache.Add(obj, Tuple.Create(name, containerName)); return(true); } } var objAsMachine = obj as Machine; if (objAsMachine != null) { if (EmulationManager.Instance.CurrentEmulation.TryGetMachineName(objAsMachine, out name)) { nameCache.Add(obj, Tuple.Create(name, containerName)); return(true); } } var objAsIExternal = obj as IExternal; if (objAsIExternal != null) { if (ExternalsManager.TryGetName(objAsIExternal, out name)) { nameCache.Add(obj, Tuple.Create(name, containerName)); return(true); } } var objAsIHostMachineElement = obj as IHostMachineElement; if (objAsIHostMachineElement != null) { if (HostMachine.TryGetName(objAsIHostMachineElement, out name)) { containerName = HostMachine.HostMachineName; nameCache.Add(obj, Tuple.Create(name, containerName)); return(true); } } name = null; return(false); }