/// <summary> /// Gets the target machine for an event; if not found, logs a halted-machine entry. /// </summary> /// <param name="targetMachineId">The id of target machine.</param> /// <param name="e">The event that will be sent.</param> /// <param name="sender">The machine that is sending the event.</param> /// <param name="operationGroupId">The operation group id.</param> /// <param name="targetMachine">Receives the target machine, if found.</param> protected bool GetTargetMachine(MachineId targetMachineId, Event e, BaseMachine sender, Guid operationGroupId, out Machine targetMachine) { if (!this.MachineMap.TryGetValue(targetMachineId, out targetMachine)) { var senderState = (sender as Machine)?.CurrentStateName ?? string.Empty; this.Logger.OnSend(targetMachineId, sender?.Id, senderState, e.GetType().FullName, operationGroupId, isTargetHalted: true); return(false); } return(true); }
/// <summary> /// Sets the operation group id for the specified machine. /// </summary> /// <param name="created">Machine created</param> /// <param name="sender">Sender machine</param> /// <param name="operationGroupId">Operation group id</param> internal void SetOperationGroupIdForMachine(Machine created, BaseMachine sender, Guid?operationGroupId) { if (operationGroupId.HasValue) { created.Info.OperationGroupId = operationGroupId.Value; } else if (sender != null) { created.Info.OperationGroupId = sender.Info.OperationGroupId; } else { created.Info.OperationGroupId = Guid.Empty; } }
/// <summary> /// Gets the new operation group id to propagate. /// </summary> /// <param name="sender">Sender machine</param> /// <param name="operationGroupId">Operation group id</param> /// <returns>Operation group Id</returns> internal Guid GetNewOperationGroupId(BaseMachine sender, Guid?operationGroupId) { if (operationGroupId.HasValue) { return(operationGroupId.Value); } else if (sender != null) { return(sender.Info.OperationGroupId); } else { return(Guid.Empty); } }
/// <summary> /// Returns a nondeterministic integer choice, that can be /// controlled during analysis or testing. /// </summary> /// <param name="machine">Machine</param> /// <param name="maxValue">The max value.</param> /// <returns>Integer</returns> internal abstract int GetNondeterministicIntegerChoice(BaseMachine machine, int maxValue);
/// <summary> /// Returns a fair nondeterministic boolean choice, that can be /// controlled during analysis or testing. /// </summary> /// <param name="machine">Machine</param> /// <param name="uniqueId">Unique id</param> /// <returns>Boolean</returns> internal abstract bool GetFairNondeterministicBooleanChoice(BaseMachine machine, string uniqueId);
/// <summary> /// Returns a nondeterministic boolean choice, that can be /// controlled during analysis or testing. /// </summary> /// <param name="machine">Machine</param> /// <param name="maxValue">The max value.</param> /// <returns>Boolean</returns> internal abstract bool GetNondeterministicBooleanChoice(BaseMachine machine, int maxValue);
/// <summary> /// Invokes the specified <see cref="PSharp.Monitor"/> with the specified <see cref="Event"/>. /// </summary> /// <param name="sender">Sender machine</param> /// <param name="type">Type of the monitor</param> /// <param name="e">Event</param> internal abstract void Monitor(Type type, BaseMachine sender, Event e);
/// <summary> /// Sends an asynchronous <see cref="Event"/> to a remote machine. /// </summary> /// <param name="mid">MachineId</param> /// <param name="e">Event</param> /// <param name="sender">Sender machine</param> /// <param name="options">Optional parameters of a send operation.</param> internal abstract void SendEventRemotely(MachineId mid, Event e, BaseMachine sender, SendOptions options);
/// <summary> /// Sends an asynchronous <see cref="Event"/> to a machine. Returns immediately /// if the target machine was already running. Otherwise blocks until the machine handles /// the event and reaches quiescense again. /// </summary> /// <param name="mid">MachineId</param> /// <param name="e">Event</param> /// <param name="sender">Sender machine</param> /// <param name="options">Optional parameters of a send operation.</param> /// <returns>True if event was handled, false if the event was only enqueued</returns> internal abstract Task <bool> SendEventAndExecute(MachineId mid, Event e, BaseMachine sender, SendOptions options);