wlmaker
Loading...
Searching...
No Matches
Functions | Variables
fsm.c File Reference
#include "fsm.h"
#include <libbase/libbase.h>
Include dependency graph for fsm.c:

Functions

void wlmtk_fsm_init (wlmtk_fsm_t *fsm_ptr, const wlmtk_fsm_transition_t *transitions, int initial_state)
 
bool wlmtk_fsm_event (wlmtk_fsm_t *fsm_ptr, int event, void *ud_ptr)
 
static void test_event (bs_test_t *test_ptr)
 
static bool test_fsm_handler (wlmtk_fsm_t *fsm_ptr, void *ud_ptr)
 

Variables

const bs_test_case_t wlmtk_fsm_test_cases []
 
static const wlmtk_fsm_transition_t test_transitions []
 

Detailed Description

Event-driven finite state machine.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Function Documentation

◆ test_event()

void test_event ( bs_test_t *  test_ptr)
static

Tests FSM.

◆ test_fsm_handler()

static bool test_fsm_handler ( wlmtk_fsm_t fsm_ptr,
void *  ud_ptr 
)
static

Test handler for the FSM unit test: Sets the bool to true.

◆ wlmtk_fsm_event()

bool wlmtk_fsm_event ( wlmtk_fsm_t fsm_ptr,
int  event,
void *  ud_ptr 
)

Handles an event for the finite-state machine.

Will search for the transition matching (current state, event) and call the associate handler.

Parameters
fsm_ptr
event
ud_ptr
Returns
If a matching transition was found: The return value of the associated handler (or true, if no handler was given). Otherwise, returns false.

◆ wlmtk_fsm_init()

void wlmtk_fsm_init ( wlmtk_fsm_t fsm_ptr,
const wlmtk_fsm_transition_t transitions,
int  initial_state 
)

Initializes the finite-state machine.

Parameters
fsm_ptr
transitions
initial_state

Variable Documentation

◆ test_transitions

const wlmtk_fsm_transition_t test_transitions[]
static
Initial value:
= {
{ 1, 100, 2, test_fsm_handler },
{ 2, 101, 3, NULL },
}
static bool test_fsm_handler(wlmtk_fsm_t *fsm_ptr, void *ud_ptr)
Definition fsm.c:70
#define WLMTK_FSM_TRANSITION_SENTINEL
Definition fsm.h:58

Test transition table for the FSM unit test.

◆ wlmtk_fsm_test_cases

const bs_test_case_t wlmtk_fsm_test_cases[]
Initial value:
= {
{ 1, "event", test_event },
{ 0, NULL, NULL }
}
static void test_event(bs_test_t *test_ptr)
Definition fsm.c:83

Unit tests for the finite-state machine.