示例#1
0
 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;
 }
示例#2
0
文件: Dispatcher.cs 项目: TheJP/stebs
 /// <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);
     }
 }
示例#3
0
 /// <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);
 }
示例#4
0
 public void Step(string clientId, SimulationStepSize stepSize)
 {
     IDispatcherItem item;
     if (processors.TryGetValue(clientId, out item))
     {
         Dispatcher.Step(item.Guid, stepSize);
     }
 }
示例#5
0
 public void ChangeSetpSize(string clientId, SimulationStepSize stepSize) => Update(clientId, item => item.SetStepSize(stepSize));
示例#6
0
 public void Run(string clientId, SimulationStepSize stepSize) => Update(clientId, item => item.SetStepSize(stepSize).SetRunning(true));
示例#7
0
 public IDispatcherItem SetStepSize(SimulationStepSize stepSize)
 {
     if (this.StepSize == stepSize) { return this; }
     return new DispatcherItem(Guid, Processor, Running, RunDelay, stepSize);
 }
示例#8
0
文件: StebsHub.cs 项目: TheJP/stebs
 public void Step(SimulationStepSize stepSize) => DoWithCheckedStepSize(stepSize, s => Manager.Step(Context.ConnectionId, s));
示例#9
0
文件: StebsHub.cs 项目: TheJP/stebs
 public void ChangeStepSize(SimulationStepSize stepSize) => DoWithCheckedStepSize(stepSize, s => Manager.ChangeSetpSize(Context.ConnectionId, s));
示例#10
0
文件: StebsHub.cs 项目: TheJP/stebs
 /// <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); }
 }
示例#11
0
文件: Dispatcher.cs 项目: TheJP/stebs
 public void Step(Guid id, SimulationStepSize stepSize) =>
     stepRequests.AddOrUpdate(id, ImmutableQueue.Create(stepSize), (key, list) => list.Enqueue(stepSize));
示例#12
0
文件: Dispatcher.cs 项目: TheJP/stebs
 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;
 }