public void UnregisterAsAChildOf(IPeripheral peripheralParent, IRegistrationPoint registrationPoint) { lock (collectionSync) { CollectGarbageStamp(); try { var parentNode = registeredPeripherals.GetNode(peripheralParent); IPeripheral removedPeripheral = null; parentNode.RemoveChild(registrationPoint, p => { IPeripheralsGroup group; if (PeripheralsGroups.TryGetActiveGroupContaining(p, out group)) { throw new RegistrationException(string.Format("Given peripheral is a member of '{0}' peripherals group and cannot be directly removed.", group.Name)); } removedPeripheral = p; return(true); }); CollectGarbage(); if (removedPeripheral != null && registeredPeripherals.TryGetNode(removedPeripheral) == null) { EmulationManager.Instance.CurrentEmulation.BackendManager.HideAnalyzersFor(removedPeripheral); } } catch (RegistrationException) { CollectGarbage(); throw; } } }
public PeripheralTreeEntry(IPeripheral peripheral, IPeripheral parent, Type type, IRegistrationPoint registrationPoint, string name, int level) { this.type = type; Name = name; RegistrationPoint = registrationPoint; Peripheral = peripheral; Parent = parent; Level = level; }
public PeripheralTreeEntry(IPeripheral peripheral, IPeripheral parent, Type type, IRegistrationPoint registrationPoint, string name, int level) { this.type = type; Name = name; RegistrationPoint = registrationPoint; Peripheral = peripheral; Parent = parent; Level = level; }
private void Register(IPeripheral peripheral, IRegistrationPoint registrationPoint, IPeripheral parent) { using (ObtainPausedState()) { Action executeAfterLock = null; lock (collectionSync) { var parentNode = registeredPeripherals.GetNode(parent); parentNode.AddChild(peripheral, registrationPoint); var ownLife = peripheral as IHasOwnLife; if (ownLife != null) { ownLifes.Add(ownLife); if (state == State.Paused) { executeAfterLock = delegate { ownLife.Start(); ownLife.Pause(); }; } } } if (executeAfterLock != null) { executeAfterLock(); } if (peripheral is ITimeSink timeSink) { LocalTimeSource.RegisterSink(timeSink); } } OnMachinePeripheralsChanged(peripheral, PeripheralsChangedEventArgs.PeripheralChangeType.Addition); EmulationManager.Instance.CurrentEmulation.BackendManager.TryCreateBackend(peripheral); }
private void RegisterInParents(DeviceInfo device, IDictionary <string, IPeripheral> parents) { foreach (var parentName in device.Connections.Keys) { //TODO: nongeneric version var parent = parents.Single(x => x.Key == parentName).Value; var connections = device.Connections[parentName]; var ifaces = parent.GetType().GetInterfaces().Where(x => IsSpecializationOfRawGeneric(typeof(IPeripheralRegister <,>), x)).ToList(); var ifaceCandidates = ifaces.Where(x => x.GetGenericArguments()[0].IsAssignableFrom(device.Peripheral.GetType())).ToList(); foreach (var connection in connections) { IRegistrationPoint regPoint = null; Type formalType = null; if (connection.ContainsKey(TYPE_NODE)) { var name = (string)connection[TYPE_NODE]; formalType = GetDeviceTypeFromName(name); } Type foundIface = null; foreach (var iface in ifaceCandidates) { var iRegPoint = iface.GetGenericArguments()[1]; Type objType; if (formalType != null && iRegPoint.IsAssignableFrom(formalType)) { objType = formalType; } else { objType = iRegPoint; } object regPointObject; if (!TryInitializeCtor(objType, connection, out regPointObject)) { if (connection.Keys.Any() || !TryHandleSingleton(objType, out regPointObject)) { continue; } } regPoint = (IRegistrationPoint)regPointObject; foundIface = iface; break; //is a construable type } if (foundIface == null) { // let's try attachment through the AttachTo mechanism FailDevice(device.Name, "connection to " + parentName); } else { Dynamic.InvokeMemberAction(parent, "Register", new object[] { device.Peripheral, regPoint } ); } } } }
public void RegisterAsAChildOf(IPeripheral peripheralParent, IPeripheral peripheralChild, IRegistrationPoint registrationPoint) { Register(peripheralChild, registrationPoint, peripheralParent); }