From c3097faac1a3e434880ebe1ac213d0a13143df7b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=A4=A9=E6=B5=A9?=
Date: Tue, 21 Apr 2026 02:45:16 +0800
Subject: [PATCH 1/7] =?UTF-8?q?feat:=20=E6=96=B0=E5=BB=BACMakeLists.txt?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
CMakeLists.txt | 16 ++++++++++++++++
fsm.c | 4 ++++
fsm.h | 7 +++++++
3 files changed, 27 insertions(+)
create mode 100644 CMakeLists.txt
create mode 100644 fsm.c
create mode 100644 fsm.h
diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 0000000..bcd6159
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,16 @@
+cmake_minimum_required(VERSION 3.28)
+
+project(qffsm C)
+
+add_library(${PROJECT_NAME})
+
+target_sources(${PROJECT_NAME} PRIVATE fsm.c)
+
+target_include_directories(${PROJECT_NAME} PUBLIC .)
+target_compile_options(${PROJECT_NAME} PRIVATE
+ -ffunction-sections -fdata-sections
+ -Wall -Wextra
+)
+target_link_options(${PROJECT_NAME} PRIVATE
+ -Wl,--gc-sections
+)
\ No newline at end of file
diff --git a/fsm.c b/fsm.c
new file mode 100644
index 0000000..2c76aec
--- /dev/null
+++ b/fsm.c
@@ -0,0 +1,4 @@
+//
+// Created by Hydro on 2026/4/21.
+//
+#include "fsm.h"
\ No newline at end of file
diff --git a/fsm.h b/fsm.h
new file mode 100644
index 0000000..58e52a6
--- /dev/null
+++ b/fsm.h
@@ -0,0 +1,7 @@
+//
+// Created by Hydro on 2026/4/21.
+
+#ifndef QF_FSM_FSM_H
+#define QF_FSM_FSM_H
+
+#endif //QF_FSM_FSM_H
From b191f5b9255eea6fb83e7e560b027fb5a1bb6f55 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=A4=A9=E6=B5=A9?=
Date: Tue, 21 Apr 2026 02:50:05 +0800
Subject: [PATCH 2/7] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9Eformat?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
clang-format | 137 +++++++++++++++++++++++++++++++++++++++++++++++++++
fsm.h | 2 +-
2 files changed, 138 insertions(+), 1 deletion(-)
create mode 100644 clang-format
diff --git a/clang-format b/clang-format
new file mode 100644
index 0000000..777ad36
--- /dev/null
+++ b/clang-format
@@ -0,0 +1,137 @@
+Language: Cpp
+AccessModifierOffset: -4
+AlignAfterOpenBracket: Align
+AlignConsecutiveMacros: true
+AlignConsecutiveAssignments: true
+AlignConsecutiveDeclarations: true
+AlignEscapedNewlines: Left
+AlignOperands: true
+AlignTrailingComments: true
+AllowAllArgumentsOnNextLine: true
+AllowAllConstructorInitializersOnNextLine: true
+AllowAllParametersOfDeclarationOnNextLine: true
+AllowShortBlocksOnASingleLine: Never
+AllowShortCaseLabelsOnASingleLine: false
+AllowShortFunctionsOnASingleLine: None
+AllowShortLambdasOnASingleLine: All
+AllowShortIfStatementsOnASingleLine: Never
+AllowShortLoopsOnASingleLine: false
+AlwaysBreakAfterDefinitionReturnType: TopLevel
+AlwaysBreakAfterReturnType: TopLevelDefinitions
+AlwaysBreakBeforeMultilineStrings: true
+AlwaysBreakTemplateDeclarations: Yes
+BinPackArguments: false
+BinPackParameters: false
+BraceWrapping:
+ AfterCaseLabel: false
+ AfterClass: true
+ AfterControlStatement: true
+ AfterEnum: true
+ AfterFunction: true
+ AfterNamespace: false
+ AfterObjCDeclaration: true
+ AfterStruct: true
+ AfterUnion: true
+ AfterExternBlock: true
+ BeforeCatch: true
+ BeforeElse: true
+ IndentBraces: false
+ SplitEmptyFunction: true
+ SplitEmptyRecord: true
+ SplitEmptyNamespace: true
+BreakBeforeBinaryOperators: All
+BreakBeforeBraces: Custom
+BreakBeforeInheritanceComma: false
+BreakInheritanceList: BeforeComma
+BreakBeforeTernaryOperators: true
+BreakConstructorInitializersBeforeComma: false
+BreakConstructorInitializers: BeforeComma
+BreakAfterJavaFieldAnnotations: true
+BreakStringLiterals: true
+ColumnLimit: 80
+CommentPragmas: '^ IWYU pragma:'
+CompactNamespaces: false
+ConstructorInitializerAllOnOneLineOrOnePerLine: false
+ConstructorInitializerIndentWidth: 4
+ContinuationIndentWidth: 4
+Cpp11BracedListStyle: false
+DeriveLineEnding: true
+DerivePointerAlignment: false
+DisableFormat: false
+ExperimentalAutoDetectBinPacking: false
+FixNamespaceComments: false
+ForEachMacros:
+ - foreach
+ - Q_FOREACH
+ - BOOST_FOREACH
+IncludeBlocks: Preserve
+IncludeCategories:
+ - Regex: '^"(llvm|llvm-c|clang|clang-c)/'
+ Priority: 2
+ SortPriority: 0
+ - Regex: '^(<|"(gtest|gmock|isl|json)/)'
+ Priority: 3
+ SortPriority: 0
+ - Regex: '.*'
+ Priority: 1
+ SortPriority: 0
+IncludeIsMainRegex: '(Test)?$'
+IncludeIsMainSourceRegex: ''
+IndentCaseLabels: true
+IndentGotoLabels: true
+IndentPPDirectives: None
+IndentWidth: 4
+IndentWrappedFunctionNames: false
+InsertBraces: true
+JavaScriptQuotes: Leave
+JavaScriptWrapImports: true
+KeepEmptyLinesAtTheStartOfBlocks: true
+MacroBlockBegin: ''
+MacroBlockEnd: ''
+MaxEmptyLinesToKeep: 1
+NamespaceIndentation: None
+ObjCBinPackProtocolList: Auto
+ObjCBlockIndentWidth: 4
+ObjCSpaceAfterProperty: true
+ObjCSpaceBeforeProtocolList: false
+PenaltyBreakAssignment: 2
+PenaltyBreakBeforeFirstCallParameter: 19
+PenaltyBreakComment: 300
+PenaltyBreakFirstLessLess: 120
+PenaltyBreakString: 1000
+PenaltyBreakTemplateDeclaration: 10
+PenaltyExcessCharacter: 1000000
+PenaltyReturnTypeOnItsOwnLine: 200
+PointerAlignment: Right
+ReflowComments: true
+SortIncludes: false
+SortUsingDeclarations: false
+SpaceAfterCStyleCast: false
+SpaceAfterLogicalNot: false
+SpaceAfterTemplateKeyword: false
+SpaceBeforeAssignmentOperators: true
+SpaceBeforeCpp11BracedList: true
+SpaceBeforeCtorInitializerColon: true
+SpaceBeforeInheritanceColon: true
+SpaceBeforeParens: Custom
+SpaceBeforeParensOptions:
+ AfterControlStatements: true
+ AfterFunctionDefinitionName: true
+SpaceBeforeRangeBasedForLoopColon: true
+SpaceInEmptyBlock: false
+SpaceInEmptyParentheses: false
+SpacesBeforeTrailingComments: 1
+SpacesInAngles: false
+SpacesInConditionalStatement: false
+SpacesInContainerLiterals: false
+SpacesInCStyleCastParentheses: false
+SpacesInParentheses: false
+SpacesInSquareBrackets: false
+SpaceBeforeSquareBrackets: false
+Standard: Latest
+StatementMacros:
+ - Q_UNUSED
+ - QT_REQUIRE_VERSION
+TabWidth: 8
+UseCRLF: false
+UseTab: Never
\ No newline at end of file
diff --git a/fsm.h b/fsm.h
index 58e52a6..e3bcd48 100644
--- a/fsm.h
+++ b/fsm.h
@@ -1,6 +1,6 @@
//
// Created by Hydro on 2026/4/21.
-
+//
#ifndef QF_FSM_FSM_H
#define QF_FSM_FSM_H
From 2cb289f19916fe909137f426721e7e077230189e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=A4=A9=E6=B5=A9?=
Date: Tue, 21 Apr 2026 02:52:18 +0800
Subject: [PATCH 3/7] =?UTF-8?q?fix:=20=E4=BF=AE=E6=94=B9clang-format?=
=?UTF-8?q?=E7=9A=84=E6=96=87=E4=BB=B6=E5=90=8D?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
clang-format => .clang-format | 0
fsm.h | 5 ++++-
2 files changed, 4 insertions(+), 1 deletion(-)
rename clang-format => .clang-format (100%)
diff --git a/clang-format b/.clang-format
similarity index 100%
rename from clang-format
rename to .clang-format
diff --git a/fsm.h b/fsm.h
index e3bcd48..4e6941e 100644
--- a/fsm.h
+++ b/fsm.h
@@ -4,4 +4,7 @@
#ifndef QF_FSM_FSM_H
#define QF_FSM_FSM_H
-#endif //QF_FSM_FSM_H
+struct qf_fsm
+{
+};
+#endif // QF_FSM_FSM_H
From cb77f5164e810635816c7a783aed1adafbdd7835 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=A4=A9=E6=B5=A9?=
Date: Tue, 21 Apr 2026 03:05:57 +0800
Subject: [PATCH 4/7] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E5=BF=85?=
=?UTF-8?q?=E8=A6=81=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
fsm.h | 32 ++++++++++++++++++++++++++++++--
1 file changed, 30 insertions(+), 2 deletions(-)
diff --git a/fsm.h b/fsm.h
index 4e6941e..3851344 100644
--- a/fsm.h
+++ b/fsm.h
@@ -3,8 +3,36 @@
//
#ifndef QF_FSM_FSM_H
#define QF_FSM_FSM_H
-
-struct qf_fsm
+#include
+typedef enum
{
+ FSM_OK,
+ FSM_FAIL
+} fsm_result_e;
+
+typedef fsm_result_e (*fsm_cb)(void *userdata);
+typedef struct qf_fsm_state
+{
+ uint16_t state;
+ fsm_cb on_exit;
+ fsm_cb on_entry;
+ void *user_data;
+} fsm_state_t;
+typedef struct qf_fsm_transition
+{
+ uint16_t state;
+ uint16_t event;
+ fsm_cb on_action;
+} fsm_transition_t;
+struct qf_fsm_event
+{
+ uint16_t event;
+ void *user_data;
};
+typedef struct qf_fsm
+{
+ uint16_t current_state;
+ fsm_state_t *p_state_list;
+
+} fsm_handle_t;
#endif // QF_FSM_FSM_H
From e0ca05678ad1546722f9a2a6b5d09af552f7b7c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=A4=A9=E6=B5=A9?=
Date: Tue, 21 Apr 2026 03:30:12 +0800
Subject: [PATCH 5/7] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=95=B0=E6=8D=AE?=
=?UTF-8?q?=E7=BB=93=E6=9E=84?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
fsm.h | 39 +++++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 8 deletions(-)
diff --git a/fsm.h b/fsm.h
index 3851344..587d73a 100644
--- a/fsm.h
+++ b/fsm.h
@@ -3,36 +3,59 @@
//
#ifndef QF_FSM_FSM_H
#define QF_FSM_FSM_H
+#include
#include
+#define EVENT_QUEUE_LEN 16
+#define EVENT_QUEUE_HANDLE_MAX_SIZE 32
typedef enum
{
FSM_OK,
FSM_FAIL
} fsm_result_e;
-
+typedef struct qf_fsm_event fsm_event_t;
+typedef struct qf_fsm fsm_handle_t;
+typedef struct qf_fsm_transition fsm_transition_t;
typedef fsm_result_e (*fsm_cb)(void *userdata);
+typedef fsm_result_e (*fsm_event_queue_init)(void *handle_ptr,
+ void *data_ptr,
+ size_t size);
+typedef fsm_result_e (*fsm_event_queue_get)(void *handle_ptr,
+ fsm_event_t *event);
+typedef fsm_result_e (*fsm_event_queue_put)(void *handle_ptr,
+ fsm_event_t *event);
typedef struct qf_fsm_state
{
uint16_t state;
fsm_cb on_exit;
+ fsm_cb on_event;
fsm_cb on_entry;
void *user_data;
} fsm_state_t;
-typedef struct qf_fsm_transition
+struct qf_fsm_transition
{
uint16_t state;
uint16_t event;
+ uint16_t next_state;
fsm_cb on_action;
-} fsm_transition_t;
+};
struct qf_fsm_event
{
uint16_t event;
void *user_data;
};
-typedef struct qf_fsm
+struct qf_fsm
{
- uint16_t current_state;
- fsm_state_t *p_state_list;
-
-} fsm_handle_t;
+ uint16_t current_state;
+ uint16_t num_states;
+ fsm_state_t *p_state_list;
+ uint32_t num_trans;
+ fsm_transition_t *p_trans_list;
+ uint8_t event_queue_handle[EVENT_QUEUE_HANDLE_MAX_SIZE];
+ fsm_event_t event_queue[EVENT_QUEUE_LEN];
+ bool custom_queue;
+ fsm_event_queue_init event_queue_init;
+ fsm_event_queue_put event_queue_put;
+ fsm_event_queue_get event_queue_get;
+};
+
#endif // QF_FSM_FSM_H
From 80e4dd2fc5aebcdf49a82c16f206da671b8fae8a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=A4=A9=E6=B5=A9?=
Date: Tue, 21 Apr 2026 03:57:54 +0800
Subject: [PATCH 6/7] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E8=87=AA?=
=?UTF-8?q?=E5=AE=9A=E4=B9=89=E4=BA=8B=E4=BB=B6=E9=98=9F=E5=88=97=E7=9A=84?=
=?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E6=96=B9=E5=BC=8F?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
fsm.c | 28 +++++++++++++++++++++++++++-
fsm.h | 14 ++++++++++++--
2 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/fsm.c b/fsm.c
index 2c76aec..134d954 100644
--- a/fsm.c
+++ b/fsm.c
@@ -1,4 +1,30 @@
//
// Created by Hydro on 2026/4/21.
//
-#include "fsm.h"
\ No newline at end of file
+#include "fsm.h"
+fsm_result_e
+fsm_init_with_queue (fsm_handle_t *handle_ptr,
+ const fsm_event_queue_init event_queue_init,
+ const fsm_event_queue_put event_queue_put,
+ const fsm_event_queue_get event_queue_get)
+{
+ fsm_result_e result = FSM_OK;
+ do
+ {
+ if (!(handle_ptr && event_queue_init && event_queue_put
+ && event_queue_get))
+ {
+ result = FSM_FAIL;
+ break;
+ }
+ handle_ptr->event_queue_get = event_queue_get;
+ handle_ptr->event_queue_put = event_queue_put;
+ handle_ptr->event_queue_init = event_queue_init;
+
+ result = handle_ptr->event_queue_init(handle_ptr->event_queue_handle,
+ handle_ptr->event_queue,
+ EVENT_QUEUE_LEN
+ * sizeof(fsm_event_t));
+ } while (0);
+ return result;
+}
\ No newline at end of file
diff --git a/fsm.h b/fsm.h
index 587d73a..ae90945 100644
--- a/fsm.h
+++ b/fsm.h
@@ -7,6 +7,7 @@
#include
#define EVENT_QUEUE_LEN 16
#define EVENT_QUEUE_HANDLE_MAX_SIZE 32
+
typedef enum
{
FSM_OK,
@@ -16,7 +17,7 @@ typedef struct qf_fsm_event fsm_event_t;
typedef struct qf_fsm fsm_handle_t;
typedef struct qf_fsm_transition fsm_transition_t;
typedef fsm_result_e (*fsm_cb)(void *userdata);
-typedef fsm_result_e (*fsm_event_queue_init)(void *handle_ptr,
+typedef fsm_result_e (*fsm_event_queue_init)(void *queue_handle,
void *data_ptr,
size_t size);
typedef fsm_result_e (*fsm_event_queue_get)(void *handle_ptr,
@@ -47,6 +48,7 @@ struct qf_fsm
{
uint16_t current_state;
uint16_t num_states;
+ char *name;
fsm_state_t *p_state_list;
uint32_t num_trans;
fsm_transition_t *p_trans_list;
@@ -57,5 +59,13 @@ struct qf_fsm
fsm_event_queue_put event_queue_put;
fsm_event_queue_get event_queue_get;
};
-
+fsm_result_e fsm_init(fsm_handle_t *handle_ptr);
+fsm_result_e fsm_init_with_queue(fsm_handle_t *handle_ptr,
+ fsm_event_queue_init event_queue_init,
+ fsm_event_queue_put event_queue_put,
+ fsm_event_queue_get event_queue_get);
+fsm_result_e fsm_event_put(fsm_handle_t *handle_ptr, fsm_event_t *event);
+fsm_result_e fsm_process_queue(fsm_handle_t *handle_ptr);
+fsm_result_e fsm_dispatch(fsm_handle_t *handle_ptr, fsm_event_t *event);
+uint16_t fsm_get_state(fsm_handle_t *h);
#endif // QF_FSM_FSM_H
From 1a2aeca518f0d32a09b9637335e8c2d453441732 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E8=B5=B5=E5=A4=A9=E6=B5=A9?=
Date: Tue, 21 Apr 2026 07:00:49 +0800
Subject: [PATCH 7/7] =?UTF-8?q?feat:=20=E6=96=B0=E5=A2=9E=E6=8E=A5?=
=?UTF-8?q?=E5=8F=A3=E5=AE=9E=E7=8E=B0=EF=BC=8C=E5=9F=BA=E7=A1=80=E5=8A=9F?=
=?UTF-8?q?=E8=83=BD=E5=AE=8C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
fsm.c | 147 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
fsm.h | 11 +++--
2 files changed, 152 insertions(+), 6 deletions(-)
diff --git a/fsm.c b/fsm.c
index 134d954..e85a711 100644
--- a/fsm.c
+++ b/fsm.c
@@ -2,8 +2,33 @@
// Created by Hydro on 2026/4/21.
//
#include "fsm.h"
+
+fsm_transition_t *
+fsm_transition (fsm_handle_t *handle_ptr, const fsm_event_t *event)
+{
+ fsm_transition_t *trans = NULL;
+ do
+ {
+ if (!(handle_ptr && event))
+ {
+ break;
+ }
+ const fsm_state_t *current_state = fsm_get_state(handle_ptr);
+ for (size_t i = 0; i < handle_ptr->num_trans; i++)
+ {
+ if (handle_ptr->p_trans_list[i].state == current_state->state
+ && handle_ptr->p_trans_list[i].event == event->event)
+ {
+ trans = &handle_ptr->p_trans_list[i];
+ break;
+ }
+ }
+ } while (0);
+ return trans;
+}
fsm_result_e
fsm_init_with_queue (fsm_handle_t *handle_ptr,
+ uint16_t init_state,
const fsm_event_queue_init event_queue_init,
const fsm_event_queue_put event_queue_put,
const fsm_event_queue_get event_queue_get)
@@ -17,14 +42,134 @@ fsm_init_with_queue (fsm_handle_t *handle_ptr,
result = FSM_FAIL;
break;
}
+ for (size_t i = 0; i < handle_ptr->num_states; i++)
+ {
+ if (handle_ptr->p_state_list[i].state == init_state)
+ {
+ handle_ptr->current_state = &handle_ptr->p_state_list[i];
+ }
+ }
handle_ptr->event_queue_get = event_queue_get;
handle_ptr->event_queue_put = event_queue_put;
handle_ptr->event_queue_init = event_queue_init;
-
+ handle_ptr->custom_queue = true;
result = handle_ptr->event_queue_init(handle_ptr->event_queue_handle,
handle_ptr->event_queue,
EVENT_QUEUE_LEN
* sizeof(fsm_event_t));
} while (0);
return result;
+}
+fsm_result_e
+fsm_event_put (fsm_handle_t *handle_ptr, fsm_event_t *event)
+{
+ fsm_result_e result = FSM_OK;
+ do
+ {
+ if (!(handle_ptr && event))
+ {
+ result = FSM_FAIL;
+ break;
+ }
+ if (handle_ptr->custom_queue)
+ {
+ result = handle_ptr->event_queue_put(handle_ptr->event_queue_handle,
+ event);
+ }
+ else
+ {
+ // TODO:补充默认队列的环形缓冲区填充逻辑
+ result = FSM_FAIL;
+ }
+ } while (0);
+ return result;
+}
+fsm_result_e
+fsm_process_queue (fsm_handle_t *handle_ptr)
+{
+ fsm_result_e result = FSM_OK;
+ do
+ {
+ if (!handle_ptr)
+ {
+ result = FSM_FAIL;
+ break;
+ }
+ fsm_event_t event = { 0 };
+ if (handle_ptr->custom_queue)
+ {
+ result = handle_ptr->event_queue_get(handle_ptr->event_queue_handle,
+ &event);
+ }
+ if (result != FSM_OK)
+ {
+ result = FSM_FAIL;
+ break;
+ }
+ fsm_dispatch(handle_ptr, &event);
+ } while (0);
+ return result;
+}
+fsm_result_e
+fsm_dispatch (fsm_handle_t *handle_ptr, const fsm_event_t *event)
+{
+ fsm_result_e result = FSM_OK;
+ do
+ {
+ if (!(handle_ptr && event))
+ {
+ result = FSM_FAIL;
+ break;
+ }
+ const fsm_transition_t *trans = fsm_transition(handle_ptr, event);
+ fsm_state_t *current_state = fsm_get_state(handle_ptr);
+ if (trans)
+ {
+ // 发生状态切换
+ if (trans->next_state != current_state->state)
+ {
+ if (current_state->on_exit)
+ {
+ current_state->on_exit(current_state->user_data);
+ }
+ // 执行事件动作
+ if (trans->on_action)
+ {
+ trans->on_action(event->user_data);
+ }
+ for (size_t i = 0; i < handle_ptr->num_states; i++)
+ {
+ if (handle_ptr->p_state_list[i].state == trans->next_state)
+ {
+ current_state = &handle_ptr->p_state_list[i];
+ if (current_state->on_entry)
+ {
+ current_state->on_entry(current_state->user_data);
+ }
+ break;
+ }
+ }
+ handle_ptr->current_state = current_state;
+ }
+ else
+ {
+ // 执行事件动作
+ if (trans->on_action)
+ {
+ trans->on_action(event->user_data);
+ }
+ }
+ }
+ else
+ {
+ result = FSM_FAIL;
+ break;
+ }
+ } while (0);
+ return result;
+}
+fsm_state_t *
+fsm_get_state (const fsm_handle_t *h)
+{
+ return h->current_state;
}
\ No newline at end of file
diff --git a/fsm.h b/fsm.h
index ae90945..2b1b8f2 100644
--- a/fsm.h
+++ b/fsm.h
@@ -46,9 +46,9 @@ struct qf_fsm_event
};
struct qf_fsm
{
- uint16_t current_state;
- uint16_t num_states;
+ fsm_state_t *current_state;
char *name;
+ uint16_t num_states;
fsm_state_t *p_state_list;
uint32_t num_trans;
fsm_transition_t *p_trans_list;
@@ -59,13 +59,14 @@ struct qf_fsm
fsm_event_queue_put event_queue_put;
fsm_event_queue_get event_queue_get;
};
-fsm_result_e fsm_init(fsm_handle_t *handle_ptr);
+fsm_result_e fsm_init(fsm_handle_t *handle_ptr, uint16_t init_state);
fsm_result_e fsm_init_with_queue(fsm_handle_t *handle_ptr,
+ uint16_t init_state,
fsm_event_queue_init event_queue_init,
fsm_event_queue_put event_queue_put,
fsm_event_queue_get event_queue_get);
fsm_result_e fsm_event_put(fsm_handle_t *handle_ptr, fsm_event_t *event);
fsm_result_e fsm_process_queue(fsm_handle_t *handle_ptr);
-fsm_result_e fsm_dispatch(fsm_handle_t *handle_ptr, fsm_event_t *event);
-uint16_t fsm_get_state(fsm_handle_t *h);
+fsm_result_e fsm_dispatch(fsm_handle_t *handle_ptr, const fsm_event_t *event);
+fsm_state_t *fsm_get_state(const fsm_handle_t *h);
#endif // QF_FSM_FSM_H