refactor(module_lifecycle): 重构模块生命周期管理实现

移除了LC_SUSPENDED状态并简化了生命周期状态转换逻辑,
将状态名称查询功能统一到module_lifecycle_name函数中,
删除了不再需要的状态检查和路径验证函数,
同时更新了相关的配置文件和模块调用以适配新的API。
This commit is contained in:
2026-04-21 14:34:08 +08:00
parent e0817a7b44
commit 0a1357c62d
5 changed files with 64 additions and 162 deletions

View File

@@ -74,24 +74,6 @@ static struct protocol_module_ctx ctx = {
#define session_state ctx.session_state
static const char *lifecycle_name(enum module_lifecycle state)
{
switch (state) {
case LC_UNINIT:
return "UNINIT";
case LC_RUNNING:
return "RUNNING";
case LC_STOPPED:
return "STOPPED";
case LC_SUSPENDED:
return "SUSPENDED";
case LC_ERROR:
return "ERROR";
default:
return "?";
}
}
static const char *proto_session_name(enum proto_session_state state)
{
switch (state) {
@@ -275,7 +257,7 @@ int protocol_module_process_message(enum proto_transport transport,
if (!module_lifecycle_is_running(&ctx.lc)) {
LOG_WRN("Reject proto msg transport:%s len:%u lc:%s",
proto_transport_name(transport), (uint32_t)req_payload_len,
lifecycle_name(ctx.lc.state));
module_lifecycle_name(ctx.lc.state));
return -EAGAIN;
}
@@ -290,7 +272,7 @@ int protocol_module_process_message(enum proto_transport transport,
LOG_WRN("Reject HelloReq transport:%s session:%s lc:%s",
proto_transport_name(transport),
proto_session_name(session_state[transport]),
lifecycle_name(ctx.lc.state));
module_lifecycle_name(ctx.lc.state));
return -EAGAIN;
}
@@ -407,7 +389,7 @@ static bool handle_proto_rx_event(const struct proto_rx_event *event)
LOG_WRN("Protocol processing failed (%d) transport:%s session:%s lc:%s len:%u",
err, proto_transport_name(event->transport),
proto_session_name(session_state[event->transport]),
lifecycle_name(ctx.lc.state),
module_lifecycle_name(ctx.lc.state),
(uint32_t)event->dyndata.size);
}