API State - Krystian-L-Lis/Stage GitHub Wiki

#API #State

GetState

Type: Function
Description:
Searches an I_Entity for an I_State component matching the provided ID pattern.
Results:

  • Ok – Returns I_State.
  • Err.NotFound – Returns null.
  • Err.InvRef – Returns null.
  • Err.Itf0 – Returns null, incorrect interface.

Signature:

FUNCTION GetState : Result  
VAR_INPUT
    iEntity: I_Entity;
    sTagId: Str;
    iOut: REFERENCE TO I_State;
END_VAR

GetStateManager

Type: Function
Description:
Searches an I_Entity for an I_StateManager component.
Results:

  • Ok – Returns I_StateManager.
  • Err.NotFound – Returns null.
  • Err.InvRef – Returns null.
  • Err.Itf0 – Returns null, incorrect interface.

Signature:

FUNCTION GetStateManager : Result  
VAR_INPUT
    iEntity: I_Entity;
    iOut: REFERENCE TO I_StateManager;
END_VAR

ICompToIStateMgr

Type: Function
Description:
Casts I_Component to I_StateManager.
Results:

  • Ok – Successful cast.
  • Err.Itf0 – Incorrect interface.
  • Err.NoMatch – No matching interface found.

Signature:

FUNCTION ICompToIStateMgr : Result  
VAR_INPUT
    iIn: I_Component;
    iOut: REFERENCE TO I_StateManager;
END_VAR

ICompToIState

Type: Function
Description:
Casts I_Component to I_State.
Results:

  • Ok – Successful cast.
  • Err.Itf0 – Incorrect interface.
  • Err.NoMatch – No matching interface found.

Signature:

FUNCTION ICompToIState : Result  
VAR_INPUT
    iIn  : I_Component;
    iOut : REFERENCE TO I_State;
END_VAR

I_StateManager

Type: Interface
Extends: I_RawComponent
Description:
Manages the lifecycle and transitions of states within an entity. Supports queuing state change requests, triggering state transitions, and broadcasting state change events.

Members

Current

Type: Property
Accessors: Get
Description: Retrieves the currently active state.
Signature: PROPERTY Current : I_State


Owner

Type: Property
Accessors: Get
Description: Returns the owning entity.
Signature: PROPERTY Owner : I_Entity


Proxy

Type: Property
Accessors: Get, Set
Description: Allows external assignment of a reference to this instance.
Signature: PROPERTY Proxy : REFERENCE TO I_StateManager Example:

iSmgr: I_StateManager;
smgr: StateManager := (Proxy := iSmgr);
// Result: iSmgr <> 0

Pretender

Type: Property
Accessors: Get
Description: Retrieves the state queued to become active.
Signature: PROPERTY Pretender : I_State


Previous

Type: Property
Accessors: Get
Description: Retrieves the last active state.
Signature: PROPERTY Previous : I_State


Request

Type: Method
Description: Queues a request to transition to a given state.
Results:

  • Ok – Request successfully queued.
  • Err.Itf0 – Invalid state interface.
  • Err.NoMatch – State does not belong to same entity.
  • Err.IncArg – State is already queued.

Signature:

METHOD Request : Result  
VAR_INPUT  
    iState : I_State;  
END_VAR

StateManager

Type: Function Block
Implements: I_StateManager
Description:
Implements state management including lifecycle, queuing, and transition handling.

Members

Current

Type: Property
Accessors: Get
From: I_StateManager
Description: Retrieves the currently active state.
Signature: PROPERTY Current : I_State


Owner

Type: Property
Accessors: Get
From: I_StateManager
Description: Returns the owning entity.
Signature: PROPERTY Owner : I_Entity


Pretender

Type: Property
Accessors: Get
From: I_StateManager
Description: Retrieves the next state queued for transition.
Signature: PROPERTY Pretender : I_State


Previous

Type: Property
Accessors: Get
From: I_StateManager
Description: Returns the previously active state.
Signature: PROPERTY Previous : I_State


Request

Type: Method
Accessors: Get
From: I_StateManager
Description: Queues a request to transition to a given state.
Results:

  • Ok – Request successfully queued.
  • Err.Itf0 – Invalid state interface.
  • Err.NoMatch – State does not belong to same entity.
  • Err.IncArg – State is already queued.

Signature:

METHOD Request : Result  
VAR_INPUT  
    iState : I_State;  
END_VAR

I_State

Type: Interface
Extends: I_RawComponent
Description:
Abstracts a state object and allows casting to I_Component.

Members

Owner

Type: Property
Accessors: Get
Description: Returns the entity that owns this state.
Signature: PROPERTY Owner : I_Entity


Tag

Type: Property
Accessors: Get
Description:
Returns the tag associated with this signal.
Signature: PROPERTY Tag : I_Tag


State

Type: Function Block
Implements: I_State
Description:
Provides base behaviour for representing and managing a system state.

Members

Owner

Type: Property
Accessors: Get
From: I_State
Description: Returns the entity that owns this state.
Signature: PROPERTY Owner : I_Entity


Tag

Type: Property
Accessors: Get
From: I_State
Description: Accesses the I_Tag associated with this state.
Signature: PROPERTY Tag : I_Tag


Proxy

Type: Property
Accessors: Get, Set
Description: Allows external assignment of a reference to this instance.
Signature: PROPERTY Proxy : REFERENCE TO I_State Example:

iState: I_State;
state: SomeState := (Proxy := iState);
// Result: iState <> 0

CanActivate

Type: Method
Access: Protected
Description: Determines whether the state can be activated. Default is TRUE.
Signature: METHOD PROTECTED CanActivate : BOOL


CanDeactivate

Type: Method
Access: Protected
Description: Determines whether the state can be deactivated. Default is TRUE.
Signature: METHOD PROTECTED CanDeactivate : BOOL


OnEntry

Type: Method
Access: Protected
Description: Executed when the state is entered.
Signature: METHOD PROTECTED OnEntry


OnExecute

Type: Method
Access: Protected
Description: Logic executed during state operation.
Signature: METHOD PROTECTED OnExecute


OnExit

Type: Method
Access: Protected
Description: Executed when the state is exited.
Signature: METHOD PROTECTED OnExit


⚠️ **GitHub.com Fallback** ⚠️