Added addFSMTransition proc etc.

This commit is contained in:
Raycho Mukelov 2023-11-05 06:42:19 +02:00
parent ddb58f7063
commit 30ba492caf
2 changed files with 12 additions and 7 deletions

View File

@ -59,19 +59,22 @@ type
proc new*[RaftNodeState, EventType, NodeType, RaftNodeStates](
T: type ConsensusFSM[RaftNodeState, EventType, NodeType, RaftMessageBase], startSymbol: RaftNodeState): T =
result = new(ConsensusFSM[NodeType, EventType, RaftNodeStates])
result = (ConsensusFSM[NodeType, EventType, RaftNodeStates])
result = ConsensusFSM[NodeType, EventType, RaftNodeStates].new
initRLock(result.mtx)
result.state = startSymbol
debug "new: ", fsm=repr(result)
proc addNewFsmTransition*[RaftNodeState, EventType, NodeType, RaftMessageBase](
proc addFSMTransition*[RaftNodeState, EventType, NodeType, RaftMessageBase](
fsm: ConsensusFSM[RaftNodeState, EventType, NodeType, RaftMessageBase],
fromState: RaftNodeState,
toState: RaftNodeState) =
termSymb: TerminalSymbol[EventType, NodeType, RaftMessageBase],
toState: RaftNodeState,
action: Option[ConsensusFSMTransActionType]) =
fsm.stateTransitionsLUT[fromState.state] = (toState, none)
fsm.stateTransitionsLUT[(fromState.state, termSymb)] = (toState, action)
proc computeFSMLogicFunctionsPermutationValue[RaftNodeState, NodeType, EventType, RaftMessageBase](
proc computeFSMLogicFunctionsPermutationValu*[RaftNodeState, NodeType, EventType, RaftMessageBase](
fsm: ConsensusFSM[RaftNodeState, EventType, NodeType, RaftMessageBase],
nts: RaftNodeState,
termSymb: TerminalSymbol,
@ -96,7 +99,7 @@ proc computeFSMLogicFunctionsPermutationValue[RaftNodeState, NodeType, EventType
termSymb[1] = logicFunctionsConds
result = termSymb
proc consensusFSMAdvance[RaftNodeState, EventType, NodeType, RaftMessageBase](
proc consensusFSMAdvance*[RaftNodeState, EventType, NodeType, RaftMessageBase](
fsm: ConsensusFSM[RaftNodeState, EventType, NodeType, RaftMessageBase],
node: NodeType,
event: EventType,

View File

@ -12,4 +12,6 @@ import ../raft/consensus_state_machine
suite "Create and test Consensus State Machine":
test
test "Create Consensus State Machine":
let csm = ConsensusStateMachine.new()
check csm != nil