From eb376e51b706463af021de30b2de3233a8f9f923 Mon Sep 17 00:00:00 2001 From: Zedhugh Chen Date: Tue, 24 Mar 2026 02:42:23 +0800 Subject: [PATCH] =?UTF-8?q?core:=20runtime=20=E6=8E=A5=E7=AE=A1=E7=94=A8?= =?UTF-8?q?=E6=88=B7=E9=85=8D=E7=BD=AE=E6=A8=A1=E5=9D=97=E5=8F=A5=E6=9F=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/runtime.c | 28 +++++++++------------------- src/core/runtime.h | 4 ++++ src/core/wm_desc.h | 23 +++++++++++++++++++++++ tests/core/CMakeLists.txt | 4 ++++ tests/core/main.c | 34 +++++++++++++++++++++++++++++++++- 5 files changed, 73 insertions(+), 20 deletions(-) diff --git a/src/core/runtime.c b/src/core/runtime.c index 2815d0f..c77549c 100644 --- a/src/core/runtime.c +++ b/src/core/runtime.c @@ -1,6 +1,6 @@ #include "core/runtime.h" -#include +#include #include "base/memory.h" #include "core/backend.h" @@ -36,35 +36,22 @@ static bool runtime_init_desc_valid(const runtime_init_desc_t *desc) { return true; } -static void runtime_workspace_desc_list_cleanup(workspace_desc_t **list, - size_t *count) { - if (!list || !count) return; - - for (size_t i = 0; i < *count; i++) { - workspace_desc_t *workspace = &(*list)[i]; - p_delete(&workspace->name); - p_delete(&workspace->layout_ids); - } - - p_delete(list); - *count = 0; -} - bool runtime_init(runtime_t *runtime, runtime_init_desc_t *desc) { if (!runtime || !runtime_init_desc_valid(desc)) return false; p_clear(runtime, 1); runtime->backend = desc->backend; runtime->layouts = desc->layouts; + runtime->config_module_handle = desc->config_module_handle; desc->backend = nullptr; p_clear(&desc->layouts, 1); + desc->config_module_handle = nullptr; state_init(&runtime->state, desc->outputs, desc->output_count, desc->workspaces, desc->workspace_count); - runtime_workspace_desc_list_cleanup(&desc->workspaces, - &desc->workspace_count); + workspace_desc_list_cleanup(&desc->workspaces, &desc->workspace_count); desc->outputs = nullptr; desc->output_count = 0; @@ -84,10 +71,11 @@ void runtime_init_desc_cleanup(runtime_init_desc_t *desc) { layout_registry_cleanup(&desc->layouts); } - runtime_workspace_desc_list_cleanup(&desc->workspaces, - &desc->workspace_count); + workspace_desc_list_cleanup(&desc->workspaces, &desc->workspace_count); desc->outputs = nullptr; desc->output_count = 0; + if (desc->config_module_handle) dlclose(desc->config_module_handle); + desc->config_module_handle = nullptr; } void runtime_shutdown(runtime_t *runtime) { @@ -99,4 +87,6 @@ void runtime_shutdown(runtime_t *runtime) { state_cleanup(&runtime->state); backend_destroy(runtime->backend); runtime->backend = nullptr; + if (runtime->config_module_handle) dlclose(runtime->config_module_handle); + runtime->config_module_handle = nullptr; } diff --git a/src/core/runtime.h b/src/core/runtime.h index c53eb97..455f679 100644 --- a/src/core/runtime.h +++ b/src/core/runtime.h @@ -1,5 +1,7 @@ #pragma once +#include + #include "core/backend.h" #include "core/layout.h" #include "core/state.h" @@ -12,6 +14,7 @@ typedef struct runtime_init_desc_t { layout_registry_t layouts; workspace_desc_t *workspaces; size_t workspace_count; + void *config_module_handle; } runtime_init_desc_t; typedef struct runtime_t { @@ -21,6 +24,7 @@ typedef struct runtime_t { state_t state; layout_registry_t layouts; backend_t *backend; + void *config_module_handle; } runtime_t; bool runtime_init(runtime_t *runtime, runtime_init_desc_t *desc); diff --git a/src/core/wm_desc.h b/src/core/wm_desc.h index e9eb2d6..b078e3f 100644 --- a/src/core/wm_desc.h +++ b/src/core/wm_desc.h @@ -2,6 +2,7 @@ #include +#include "base/memory.h" #include "core/types.h" /* @@ -32,6 +33,28 @@ typedef struct workspace_desc_t { layout_id_t initial_layout_id; } workspace_desc_t; +static inline void workspace_desc_cleanup(workspace_desc_t *workspace) { + if (!workspace) return; + + p_delete(&workspace->name); + p_delete(&workspace->layout_ids); + workspace->output_index = 0; + workspace->layout_count = 0; + workspace->initial_layout_id = ZDWM_LAYOUT_ID_INVALID; +} + +static inline void workspace_desc_list_cleanup(workspace_desc_t **list, + size_t *count) { + if (!list || !count) return; + + for (size_t i = 0; i < *count; i++) { + workspace_desc_cleanup(&(*list)[i]); + } + + p_delete(list); + *count = 0; +} + /* * workspace 描述校验接口。 * diff --git a/tests/core/CMakeLists.txt b/tests/core/CMakeLists.txt index d7d176c..0402a2f 100644 --- a/tests/core/CMakeLists.txt +++ b/tests/core/CMakeLists.txt @@ -4,6 +4,9 @@ add_executable(${TEST_APP_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/main.c ${SOURCE_DIR}/base/log.c ${SOURCE_DIR}/backend/output_utils.c + ${SOURCE_DIR}/config/defaults.c + ${SOURCE_DIR}/config/loader.c + ${SOURCE_DIR}/config/runtime_config.c ${SOURCE_DIR}/backend/x11/backend.c ${SOURCE_DIR}/core/layout.c ${SOURCE_DIR}/core/runtime.c @@ -21,6 +24,7 @@ target_include_directories(${TEST_APP_NAME} target_link_libraries(${TEST_APP_NAME} PRIVATE m + PRIVATE ${CMAKE_DL_LIBS} PRIVATE ${deps_LIBRARIES} ) diff --git a/tests/core/main.c b/tests/core/main.c index bc1d790..5dd5f61 100644 --- a/tests/core/main.c +++ b/tests/core/main.c @@ -1,9 +1,41 @@ +#include "base/log.h" +#include "config/runtime_config.h" +#include "core/backend.h" #include "core/runtime.h" +static void bootstrap(runtime_t *runtime) { + backend_t *backend = backend_create(nullptr); + backend_detect_t *detect = backend_detect(backend); + + if (!backend || !detect || detect->output_count == 0) { + fatal("backend detect failed"); + } + + runtime_init_desc_t desc = { + .backend = backend, + .outputs = detect->outputs, + .output_count = detect->output_count, + }; + if (!runtime_config_load(nullptr, &desc)) { + fatal("failed to build runtime inputs"); + } + + backend = nullptr; + + bool inited = runtime_init(runtime, &desc); + + runtime_init_desc_cleanup(&desc); + backend_detect_destroy(detect); + + if (!inited) { + fatal("zdwm runtime init failed"); + } +}; + int main(void) { runtime_t runtime = {0}; - runtime_init(&runtime, nullptr); + bootstrap(&runtime); runtime_shutdown(&runtime); return 0;