public string[,] GetElementsInSyncDomain(int num)
        {
            var table = new Table();

            table.AddRow("SyncDomain {0}".FormatWith(num));

            foreach (var machine in Machines)
            {
                if (machine.SyncDomain == SyncDomains[num])
                {
                    table.AddRow(this[machine]);
                }
            }

            foreach (var synchronizedExternal in ExternalsManager.Externals.Select(x => x as ISynchronized).Where(x => x != null))
            {
                string name;
                if (synchronizedExternal.SyncDomain == SyncDomains[num] && ExternalsManager.TryGetName((IExternal)synchronizedExternal, out name))
                {
                    table.AddRow(name);
                }
            }

            return(table.ToArray());
        }
 public void PauseAll()
 {
     lock (machLock)
     {
         Array.ForEach(machs.Rights, x => x.Pause());
         ExternalsManager.Pause();
         MasterTimeSource.Stop();
         IsStarted = false;
     }
 }
 public void PauseAll()
 {
     //ToList cast is a precaution for a situation where the list of machines changes
     //during pausing. It might happen on rare occasions. E.g. when a script loads them, and user
     //hits the pause button.
     //Otherwise it would crash.
     foreach (var machine in Machines.ToList())
     {
         machine.Pause();
     }
     ExternalsManager.Pause();
 }
Esempio n. 4
0
 private void InnerStartAll()
 {
     //ToList cast is a precaution for a situation where the list of machines changes
     //during start up procedure. It might happen on rare occasions. E.g. when a script loads them, and user
     //hits the pause button.
     //Otherwise it would crash.
     ExternalsManager.Start();
     foreach (var machine in Machines.ToList())
     {
         machine.Start();
     }
 }
 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();
     }
 }
Esempio n. 8
0
        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);
        }