Exemple #1
0
        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());
        }
Exemple #2
0
 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();
 }
Exemple #3
0
        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);
        }
Exemple #4
0
 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();
     }
 }
Exemple #5
0
        public Emulation()
        {
            syncDomains      = new List <ISynchronizationDomain>();
            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);

            machs            = new FastReadConcurrentTwoWayDictionary <string, Machine>();
            machs.ItemAdded += (name, machine) =>
            {
                machine.StateChanged       += OnMachineStateChanged;
                machine.PeripheralsChanged += (m, e) =>
                {
                    if (e.Operation != PeripheralsChangedEventArgs.PeripheralChangeType.Addition)
                    {
                        nameCache.Invalidate();
                    }
                };

                OnMachineAdded(machine);
            };

            machs.ItemRemoved += (name, machine) =>
            {
                machine.StateChanged -= OnMachineStateChanged;
                nameCache.Invalidate();

                OnMachineRemoved(machine);
            };
            BackendManager = new BackendManager();
            BlobManager    = new BlobManager();
            theBag         = new Dictionary <string, object>();
        }
Exemple #6
0
        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);
        }