Inhalte

Dependency Injection: Stopper

Table of Contents

Introduction

The Stopper class executes the individual states. The Stopper class is therefore quite stupid because it knows nothing about the states.

Stopper Class

Class SimpleStopperUnit
FUNCTION_BLOCK SimpleStopperUnit IMPLEMENTS IRunable, IResetable
VAR
	receivingWorkflow :IStateMachine;
	sendingWorkflow :IStateMachine;
	initalReceivingState :IStateMachine;
	initialSendingState :IStateMachine;
END_VAR
METHOD FB_init :BOOL
VAR_INPUT
	// if TRUE, the retain variables are initialized (warm start / cold start)
	bInitRetains :BOOL := FALSE;
	// if TRUE, the instance afterwards gets moved into the copy code (online change)
	bInCopyCode :BOOL := TRUE;
	
	firstStateReceivingWorkflow :IWorkfowState;
	lastStateReceivingWorkflow :IWorkfowState;
	firstStateSendingWorkflow :IWorkfowState;
	lastStateSendingWorkflow :IWorkfowState;
END_VAR
THIS^.initalReceivingState :=
THIS^.receivingWorkflow :=
firstStateReceivingWorkflow;
lastStateReceivingWorkflow.setNextState(firstStateReceivingWorkflow);

THIS^.initialSendingState :=
THIS^.sendingWorkflow :=
firstStateSendingWorkflow;
lastStateSendingWorkflow.setNextState(firstStateSendingWorkflow);
METHOD reset
THIS^.receivingWorkflow := THIS^.initalReceivingState;
THIS^.sendingWorkflow := THIS^.initialSendingState;
METHOD run
VAR CONSTANT
	INTERFACE_IS_NOT_REFERENCED :__UXINT :=0;
END_VAR
IF (THIS^.receivingWorkflow <> INTERFACE_IS_NOT_REFERENCED) THEN
	THIS^.receivingWorkflow := THIS^.receivingWorkflow.executeState();
END_IF

IF (THIS^.sendingWorkflow <> INTERFACE_IS_NOT_REFERENCED) THEN
	THIS^.sendingWorkflow := THIS^.sendingWorkflow.executeState();
END_IF