![]() |
|
|||
0001 /** 0002 * @brief State machine definition 0003 * 0004 * @file exsm.h 0005 */ 0006 /* ----------------------------------------------------------------------------- 0007 * Enduro/X Middleware Platform for Distributed Transaction Processing 0008 * Copyright (C) 2009-2016, ATR Baltic, Ltd. All Rights Reserved. 0009 * Copyright (C) 2017-2023, Mavimax, Ltd. All Rights Reserved. 0010 * This software is released under one of the following licenses: 0011 * AGPL (with Java and Go exceptions) or Mavimax's license for commercial use. 0012 * See LICENSE file for full text. 0013 * ----------------------------------------------------------------------------- 0014 * AGPL license: 0015 * 0016 * This program is free software; you can redistribute it and/or modify it under 0017 * the terms of the GNU Affero General Public License, version 3 as published 0018 * by the Free Software Foundation; 0019 * 0020 * This program is distributed in the hope that it will be useful, but WITHOUT ANY 0021 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 0022 * PARTICULAR PURPOSE. See the GNU Affero General Public License, version 3 0023 * for more details. 0024 * 0025 * You should have received a copy of the GNU Affero General Public License along 0026 * with this program; if not, write to the Free Software Foundation, Inc., 0027 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 0028 * 0029 * ----------------------------------------------------------------------------- 0030 * A commercial use license is available from Mavimax, Ltd 0031 * contact@mavimax.com 0032 * ----------------------------------------------------------------------------- 0033 */ 0034 #ifndef EXSM_H__ 0035 #define EXSM_H__ 0036 0037 #if defined(__cplusplus) 0038 extern "C" { 0039 #endif 0040 0041 /*---------------------------Includes-----------------------------------*/ 0042 #include <ndrx_config.h> 0043 #include <ndrstandard.h> 0044 /*---------------------------Externs------------------------------------*/ 0045 /*---------------------------Macros-------------------------------------*/ 0046 0047 /** Return from state machine (special for exit). 0048 * This returns last event code as machine exit code 0049 */ 0050 #define NDRX_SM_ST_RETURN -1 0051 0052 /** Return from state machine (special for exit). 0053 * This returns 0 as machine exit code 0054 */ 0055 #define NDRX_SM_ST_RETURN0 -2 0056 0057 #define NDRX_SM_EV_EOF EXFAIL /**< Event list end marker */ 0058 0059 #define NDRX_SM_TRAN(EVENT, NEXT_STATE) {EVENT, #EVENT, NEXT_STATE} /**< Transition macro */ 0060 #define NDRX_SM_TRAN_END {EXFAIL, "", 0} /**< Transition end macro */ 0061 0062 #define NDRX_SM_FLAGS_SCAN 0x0001 /*< Use scanning approach to match events */ 0063 #define NDRX_SM_FLAGS_INDEX 0x0002 /*< Use index approach to match events */ 0064 /** 0065 * State machine state definition 0066 */ 0067 #define NDRX_SM_STATE(STATE, FUNC, ...) \ 0068 { \ 0069 STATE, #STATE, FUNC, 0, {__VA_ARGS__} \ 0070 } \ 0071 /*---------------------------Enums--------------------------------------*/ 0072 /*---------------------------Typedefs-----------------------------------*/ 0073 0074 /** 0075 * State machine transition 0076 */ 0077 typedef struct 0078 { 0079 int event; /**< event id */ 0080 char event_name[32]; /**< */ 0081 int next_state; /**< next state */ 0082 } ndrx_sm_tran_t; 0083 0084 /** 0085 * State machine type, with custom number of transitions 0086 * @param NAME state machine name 0087 * @param NR_TRAN number of transitions 0088 */ 0089 #define NDRX_SM_T(NAME, NR_TRAN) \ 0090 typedef struct \ 0091 { \ 0092 int state; /**< state number */ \ 0093 char state_name[32]; /**< state name */ \ 0094 int (*func)(void *data); /**< state function (callback) */ \ 0095 int flags; /**< internal flags of the state */ \ 0096 ndrx_sm_tran_t transitions[NR_TRAN]; /**< transitions */ \ 0097 } NAME 0098 /*---------------------------Globals------------------------------------*/ 0099 /*---------------------------Statics------------------------------------*/ 0100 /*---------------------------Prototypes---------------------------------*/ 0101 0102 extern NDRX_API int ndrx_sm_run(void *sm, int nr_tran, int entry_state, void *data, int log_topic); 0103 extern NDRX_API int ndrx_sm_comp(void *sm, int nr_state, int nr_tran, int last_state); 0104 0105 #if defined(__cplusplus) 0106 } 0107 #endif 0108 0109 #endif 0110 /* vim: set ts=4 sw=4 et smartindent: */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |