public DispatcherItem(Guid guid, IProcessor processor, bool running, TimeSpan runDelay, SimulationStepSize stepSize) { this.Guid = guid; this.Processor = processor; this.Running = running; this.RunDelay = runDelay; this.StepSize = stepSize; }
/// <summary>Notifies, simulation step finished.</summary> /// <param name="item">Processor which was simulated</param> /// <param name="stepSize">Simulated step size.</param> /// <param name="ramChanges">Changes done to the ram during the simulation step.</param> /// <param name="registerChanges">Changes done to the registers during the simulation step.</param> private void NotifyFinishedStep(IDispatcherItem item, SimulationStepSize stepSize, IReadOnlyDictionary<byte, byte> ramChanges, IReadOnlyDictionary<Registers, IRegister> registerChanges) { Action<IDispatcherItem, SimulationStepSize, IReadOnlyDictionary<byte, byte>, IReadOnlyDictionary<Registers, IRegister>> handler; lock (eventLock) { handler = finishedStep; } if (handler != null) { //Call handler outside of the lock, so called handle methods will not caue a deadlock. //This is safe because delegates are immutable. handler(item, stepSize, ramChanges, registerChanges); } }
/// <summary>Called, when a simulation step was processed.</summary> /// <param name="item">Processor which was simulated</param> /// <param name="stepSize">Simulated step size.</param> /// <param name="ramChanges">Changes done to the ram during the simulation step.</param> /// <param name="registerChanges">Changes done to the registers during the simulation step.</param> private void FinishedStep(IDispatcherItem item, SimulationStepSize stepSize, IReadOnlyDictionary<byte, byte> ramChanges, IReadOnlyDictionary<Registers, IRegister> registerChanges) { var guid = item.Guid.ToString(); Clients.Group(guid).UpdateProcessor(stepSize, ramChanges, registerChanges); }
public void Step(string clientId, SimulationStepSize stepSize) { IDispatcherItem item; if (processors.TryGetValue(clientId, out item)) { Dispatcher.Step(item.Guid, stepSize); } }
public void ChangeSetpSize(string clientId, SimulationStepSize stepSize) => Update(clientId, item => item.SetStepSize(stepSize));
public void Run(string clientId, SimulationStepSize stepSize) => Update(clientId, item => item.SetStepSize(stepSize).SetRunning(true));
public IDispatcherItem SetStepSize(SimulationStepSize stepSize) { if (this.StepSize == stepSize) { return this; } return new DispatcherItem(Guid, Processor, Running, RunDelay, stepSize); }
public void Step(SimulationStepSize stepSize) => DoWithCheckedStepSize(stepSize, s => Manager.Step(Context.ConnectionId, s));
public void ChangeStepSize(SimulationStepSize stepSize) => DoWithCheckedStepSize(stepSize, s => Manager.ChangeSetpSize(Context.ConnectionId, s));
/// <summary> /// Executes given delegate only, if a valid step size is passed. /// </summary> /// <param name="stepSize">Step size to check and pass.</param> /// <param name="action">Action which is called with valid step size.</param> private void DoWithCheckedStepSize(SimulationStepSize stepSize, Action<SimulationStepSize> action) { if (Enum.IsDefined(typeof(SimulationStepSize), stepSize)) { action(stepSize); } }
public void Step(Guid id, SimulationStepSize stepSize) => stepRequests.AddOrUpdate(id, ImmutableQueue.Create(stepSize), (key, list) => list.Enqueue(stepSize));
public IDispatcherItem CreateProcessor(bool running, TimeSpan runDelay, SimulationStepSize stepSize) { IDispatcherItem item; do { item = itemFactory(Guid.NewGuid(), container.Resolve<IProcessor>(), running, runDelay, stepSize); } while (!processors.TryAdd(item.Guid, item)); return item; }