Skip to main content

apply

Short summary

A method to apply the concrete action on the given object (THIS^.object)

Return: CNM_ReturnTypes.SingleExecutionState

Parameters

NameTypeCommentKind
executeBOOLcontrol bit to start or abort the application, should to be active until the CNM_ReturnTypes.SingleExecutionState is SUCCESSinput

Code

Declaration

METHOD FINAL apply :CNM_ReturnTypes.SingleExecutionState
VAR_INPUT
(*control bit to start or abort the application, should to be active until the CNM_ReturnTypes.SingleExecutionState is SUCCESS*)
execute :BOOL;
END_VAR
VAR_INST
iterator :ForwardArrayListIterator(0);
lastExecute :BOOL;
step :USINT;
returnState :CNM_ReturnTypes.SingleExecutionState;
currentApplier :CNM_CollectionInterfaces.IApplier;
cycleManager :CNM_CycleManager.SimpleCycleManager;
END_VAR
VAR
listToAttach :POINTER TO ArrayList;
listReference :REFERENCE TO ArrayList;
END_VAR
VAR CONSTANT
INIT :DINT := CNM_ReturnTypes.DefaultSteps.STEP.INIT;
RUN :DINT := INIT + 1;
GET_APPLIER :DINT := RUN + 1;
SUCCESS :DINT := CNM_ReturnTypes.DefaultSteps.STEP.SUCCESS;
ERROR :DINT := CNM_ReturnTypes.DefaultSteps.STEP.ERROR;

STEP_IDLE :USINT := 0;
STEP_INIT :USINT := 1;
STEP_RUN :USINT := 2;
STEP_DONE :USINT := 3;
STEP_ERROR :USINT := 4;
END_VAR

Implementation

cycleManager(execute := execute);

CASE cycleManager.step.current OF
INIT:
cycleManager.configuration.sequence.requireSuccessStep := FALSE;
__QUERYPOINTER(THIS^.myactions.list, listToAttach);
listReference REF= listToAttach^;
iterator.attachArrayList(listReference);
iterator.reset();
IF(iterator.moveNext() AND_THEN __QUERYINTERFACE(iterator.current, currentApplier))THEN
currentApplier.accept(THIS^.object);
currentApplier.apply(FALSE);
currentApplier.apply(TRUE);
cycleManager.proceed();
ELSE
cycleManager.proceedWith(SUCCESS);
END_IF

RUN:
CASE currentApplier.apply(TRUE) OF
CNM_ReturnTypes.SingleExecutionState.SUCCESS:
cycleManager.proceed();
CNM_ReturnTypes.SingleExecutionState.ABORTED,
CNM_ReturnTypes.SingleExecutionState.ERROR:
cycleManager.proceedWith(ERROR);
ELSE
;// do nothing, stay in RUN
END_CASE

GET_APPLIER:
IF(iterator.moveNext() AND_THEN __QUERYINTERFACE(iterator.current, currentApplier))THEN
currentApplier.accept(THIS^.object);
currentApplier.apply(FALSE);
currentApplier.apply(TRUE);
cycleManager.proceedWith(RUN);
ELSE
cycleManager.proceedWith(SUCCESS);
END_IF

END_CASE

apply := cycleManager.state;