Files
smart-home-control-system/include/shs/app.h
T
sambu 3e10ee8488 test(S6): 补齐 app 层与 HTTP 第二组集成测试,行覆盖率 72.2%→80.3%(NFR-05 达标)
新增
- tests/integration/test_menu.c:菜单 14 项全分派、命令全集正/负例、参数解析、脚本化 stdin 主循环
- tests/integration/test_http_api.c:其余 11 个接口 + 错误路径(400/404/协议层 400)
- src/app/app_options.c:app_parse_args/app_print_usage 从 main.c 迁入静态库(app.h 声明此前无实现)
- app_clear_stop():复用主循环时清除退出标志
- tools/coverage.sh:A10 覆盖率门限自动判定;acceptance 扩到 A1~A10 共 25 项

修复(本轮集成测试暴露)
- menu_render 漏渲染首项「设备列表」(行号 0 既当标题又当表项 0)
- http_server_stop 只置标志不关套接字,导致同进程无法二次启动(聚合运行 70 项失败)
- POST /api/config 未匹配到字段时假成功(现返回 400)
- CRC/I2C 字节序、采样路数、离线设备负例等此前已在集成阶段修复

实测:CTest 19/19;聚合运行 19 套件 2450 断言 0 失败;ASan 19/19;覆盖率 80.3%
2026-09-14 22:23:17 +08:00

44 lines
1.9 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* @file app.h
* @brief 应用入口层:CLI 交互、网页服务、脚本回放
*
* 教材对应:项目十「项目集成与部署」·项目一(程序结构)。
*/
#ifndef SHS_APP_H
#define SHS_APP_H
#include "shs/common.h"
#include "shs/errors.h"
#include "shs/system.h"
/** 解析命令行参数(--cli / --web / --replay FILE / --port N / --data DIR) */
typedef struct {
shs_run_mode_t mode; /**< 运行模式 */
uint16_t port; /**< 网页端口(0 表示用配置值) */
const char *replay; /**< 回放脚本路径 */
const char *data_dir; /**< 数据目录覆盖 */
bool help; /**< 是否请求帮助 */
char bind_addr[SHS_NAME_MAX]; /**< --bind 指定的监听地址,空串表示用配置值 */
bool selftest; /**< --selftest:仅运行系统自检后退出 */
} AppOptions;
/** 参数解析:成功返回 SHS_OK;非法参数返回负错误码 */
shs_err_t app_parse_args(int argc, char **argv, AppOptions *opts);
/** 打印使用说明 */
void app_print_usage(const char *program);
/** 运行 CLI 交互模式(菜单主循环) */
shs_err_t app_run_cli(SmartHomeSystem *sys);
/** 运行网页模式(启动 HTTP 服务并阻塞,直到 app_request_stop) */
shs_err_t app_run_web(SmartHomeSystem *sys, uint16_t port);
/** 脚本回放:从文件逐行读取命令并执行(无人值守演示) */
shs_err_t app_replay_script(SmartHomeSystem *sys, const char *script_path);
/** 执行一条文本命令(CLI 与回放共用),结果写入 out */
shs_err_t app_execute_command(SmartHomeSystem *sys, const char *line, char *out, size_t out_size);
/** 清除退出请求(测试或嵌入场景里复用主循环时使用;与 app_request_stop 配对) */
void app_clear_stop(void);
/** 请求主循环退出(信号处理或测试调用) */
void app_request_stop(void);
bool app_stop_requested(void);
#endif /* SHS_APP_H */