public void Announce(PrtEventValue ev, PrtValue payload, PrtMachine parent) { if (ev.Equals(PrtValue.@null)) { throw new PrtIllegalEnqueueException("Enqueued event must not be null"); } PrtType prtType = ev.evt.payloadType; //assertion to check if argument passed inhabits the payload type. if (prtType is PrtNullType) { if (!payload.Equals(PrtValue.@null)) { throw new PrtIllegalEnqueueException("Did not expect a payload value"); } } else if (!PrtValue.PrtInhabitsType(payload, prtType)) { throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", payload.ToString(), prtType.ToString(), ev.evt.name)); } var allSpecMachines = GetSpecMachines(parent.renamedName); foreach (var mon in allSpecMachines) { if (mon.observes.Contains(ev)) { TraceLine("<AnnounceLog> Enqueued Event <{0}, {1}> to Spec Machine {2}", ev, payload, mon.Name); mon.PrtEnqueueEvent(ev, payload, parent); } } }
public override void PrtEnqueueEvent(PrtValue e, PrtValue arg, PrtMachine source) { if (e is PrtNullValue) { throw new PrtIllegalEnqueueException("Enqueued event must be non-null"); } PrtType prtType; PrtEventValue ev = e as PrtEventValue; //assertion to check if argument passed inhabits the payload type. prtType = ev.evt.payloadType; if (!(prtType is PrtNullType) && !PrtValue.PrtInhabitsType(arg, prtType)) { throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", arg.GetString(), prtType.GetString(), ev.evt.name)); } else if (prtType is PrtNullType && !(arg is PrtNullValue)) { throw new PrtIllegalEnqueueException("Did not expect a payload value"); } if (currentStatus == PrtMachineStatus.Halted) { stateImpl.Trace( @"<EnqueueLog> {0}-{1} Machine has been halted and Event {2} is dropped", this.Name, this.instanceNumber, ev.evt.name); } else { stateImpl.Trace( @"<EnqueueLog> Enqueued Event <{0}, {1}> in {2}-{3} by {4}-{5}", ev.evt.name, arg.GetString(), this.Name, this.instanceNumber, source.Name, source.instanceNumber); this.eventQueue.EnqueueEvent(e, arg); if (this.maxBufferSize != -1 && this.eventQueue.Size() > this.maxBufferSize) { if (this.doAssume) { throw new PrtAssumeFailureException(); } else { throw new PrtMaxBufferSizeExceededException( String.Format(@"<EXCEPTION> Event Buffer Size Exceeded {0} in Machine {1}-{2}", this.maxBufferSize, this.Name, this.instanceNumber)); } } if (currentStatus == PrtMachineStatus.Blocked && this.eventQueue.IsEnabled(this)) { currentStatus = PrtMachineStatus.Enabled; } } //Announce it to all the monitors stateImpl.Announce(e, arg, source); }
public override void PrtEnqueueEvent(PrtValue e, PrtValue arg, PrtMachine source, PrtMachineValue target = null) { PrtEventValue ev = e as PrtEventValue; if (ev.evt.name == "null") { throw new PrtIllegalEnqueueException("Enqueued event must not be null"); } //check if the sent event is in source send set if (!source.sends.Contains(e as PrtEventValue)) { throw new PrtIllegalEnqueueException(String.Format("Machine <0> cannot send event {1}", source.Name, e.ToString())); } //check if the sent event is in target permissions if (target is PrtInterfaceValue) { if (!(target as PrtInterfaceValue).permissions.Contains(e as PrtEventValue)) { throw new PrtIllegalEnqueueException(String.Format("Event {1} is not in the permission set of the target", e.ToString())); } } PrtType prtType = ev.evt.payloadType; //assertion to check if argument passed inhabits the payload type. if (prtType is PrtNullType) { if (!arg.Equals(PrtValue.@null)) { throw new PrtIllegalEnqueueException("Did not expect a payload value"); } } else if (!PrtValue.PrtInhabitsType(arg, prtType)) { throw new PrtInhabitsTypeException(String.Format("Payload <{0}> does not match the expected type <{1}> with event <{2}>", arg.ToString(), prtType.ToString(), ev.evt.name)); } //check if the event sent is in the permissions if (currentStatus == PrtMachineStatus.Halted) { stateImpl.Trace( @"<EnqueueLog> {0}-{1} Machine has been halted and Event {2} is dropped", this.Name, this.instanceNumber, ev.evt.name); } else { stateImpl.Trace( @"<EnqueueLog> Enqueued Event <{0}, {1}> in {2}-{3} by {4}-{5}", ev.evt.name, arg.ToString(), this.Name, this.instanceNumber, source.Name, source.instanceNumber); this.eventQueue.EnqueueEvent(e, arg); if (this.maxBufferSize != DefaultMaxBufferSize && this.eventQueue.Size() > this.maxBufferSize) { if (this.doAssume) { throw new PrtAssumeFailureException(); } else { throw new PrtMaxBufferSizeExceededException( String.Format(@"<EXCEPTION> Event Buffer Size Exceeded {0} in Machine {1}-{2}", this.maxBufferSize, this.Name, this.instanceNumber)); } } if (currentStatus == PrtMachineStatus.Blocked && this.eventQueue.IsEnabled(this)) { currentStatus = PrtMachineStatus.Enabled; } } //Announce it to all the spec machines stateImpl.Announce(e as PrtEventValue, arg, source); }