增加事件驱动和业务回滚处理方式

This commit is contained in:
冯佳
2026-03-04 08:50:04 +08:00
parent cc4c361df6
commit 47a9dff6ef
25 changed files with 2626 additions and 1780 deletions

76
app/transaction.h Normal file
View File

@ -0,0 +1,76 @@
/*
* transaction.h
*
* Created on: 2026-03-04
* Author: RT-Thread
*
* 功能: 事务管理模块头文件
* 依赖: RT-Thread Nano, osal
* 跨平台适配: 基于RT-Thread Nano使用标准API
*/
#ifndef TRANSACTION_H
#define TRANSACTION_H
#include <rtthread.h>
#include "osal.h"
/* 事务状态定义 */
typedef enum {
TRANSACTION_STATUS_IDLE = 0,
TRANSACTION_STATUS_ACTIVE,
TRANSACTION_STATUS_COMMITTED,
TRANSACTION_STATUS_ROLLED_BACK,
TRANSACTION_STATUS_INVALID
} transaction_status_t;
/* 回滚函数类型 */
typedef void (*transaction_rollback_func_t)(void *user_data);
/* 事务结构体 */
typedef struct {
int id; /* 事务ID */
transaction_status_t status; /* 事务状态 */
transaction_rollback_func_t rollback_func; /* 回滚函数 */
void *user_data; /* 用户数据 */
} transaction_t;
/* 最大事务数量 */
#define MAX_TRANSACTIONS 16
/**
* @brief 初始化事务管理
* @return 0 成功非0 失败
*/
int transaction_init(void);
/**
* @brief 开始事务
* @param rollback_func 回滚函数
* @param user_data 用户数据
* @return 事务ID失败返回0
*/
int transaction_begin(transaction_rollback_func_t rollback_func, void *user_data);
/**
* @brief 提交事务
* @param id 事务ID
* @return 0 成功非0 失败
*/
int transaction_commit(int id);
/**
* @brief 回滚事务
* @param id 事务ID
* @return 0 成功非0 失败
*/
int transaction_rollback(int id);
/**
* @brief 获取事务状态
* @param id 事务ID
* @return 事务状态
*/
transaction_status_t transaction_get_status(int id);
#endif /* TRANSACTION_H */