core: runtime 接管用户配置模块句柄
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
#include "core/runtime.h"
|
#include "core/runtime.h"
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <dlfcn.h>
|
||||||
|
|
||||||
#include "base/memory.h"
|
#include "base/memory.h"
|
||||||
#include "core/backend.h"
|
#include "core/backend.h"
|
||||||
@@ -36,35 +36,22 @@ static bool runtime_init_desc_valid(const runtime_init_desc_t *desc) {
|
|||||||
return true;
|
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) {
|
bool runtime_init(runtime_t *runtime, runtime_init_desc_t *desc) {
|
||||||
if (!runtime || !runtime_init_desc_valid(desc)) return false;
|
if (!runtime || !runtime_init_desc_valid(desc)) return false;
|
||||||
|
|
||||||
p_clear(runtime, 1);
|
p_clear(runtime, 1);
|
||||||
runtime->backend = desc->backend;
|
runtime->backend = desc->backend;
|
||||||
runtime->layouts = desc->layouts;
|
runtime->layouts = desc->layouts;
|
||||||
|
runtime->config_module_handle = desc->config_module_handle;
|
||||||
|
|
||||||
desc->backend = nullptr;
|
desc->backend = nullptr;
|
||||||
p_clear(&desc->layouts, 1);
|
p_clear(&desc->layouts, 1);
|
||||||
|
desc->config_module_handle = nullptr;
|
||||||
|
|
||||||
state_init(&runtime->state, desc->outputs, desc->output_count,
|
state_init(&runtime->state, desc->outputs, desc->output_count,
|
||||||
desc->workspaces, desc->workspace_count);
|
desc->workspaces, desc->workspace_count);
|
||||||
|
|
||||||
runtime_workspace_desc_list_cleanup(&desc->workspaces,
|
workspace_desc_list_cleanup(&desc->workspaces, &desc->workspace_count);
|
||||||
&desc->workspace_count);
|
|
||||||
desc->outputs = nullptr;
|
desc->outputs = nullptr;
|
||||||
desc->output_count = 0;
|
desc->output_count = 0;
|
||||||
|
|
||||||
@@ -84,10 +71,11 @@ void runtime_init_desc_cleanup(runtime_init_desc_t *desc) {
|
|||||||
layout_registry_cleanup(&desc->layouts);
|
layout_registry_cleanup(&desc->layouts);
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime_workspace_desc_list_cleanup(&desc->workspaces,
|
workspace_desc_list_cleanup(&desc->workspaces, &desc->workspace_count);
|
||||||
&desc->workspace_count);
|
|
||||||
desc->outputs = nullptr;
|
desc->outputs = nullptr;
|
||||||
desc->output_count = 0;
|
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) {
|
void runtime_shutdown(runtime_t *runtime) {
|
||||||
@@ -99,4 +87,6 @@ void runtime_shutdown(runtime_t *runtime) {
|
|||||||
state_cleanup(&runtime->state);
|
state_cleanup(&runtime->state);
|
||||||
backend_destroy(runtime->backend);
|
backend_destroy(runtime->backend);
|
||||||
runtime->backend = nullptr;
|
runtime->backend = nullptr;
|
||||||
|
if (runtime->config_module_handle) dlclose(runtime->config_module_handle);
|
||||||
|
runtime->config_module_handle = nullptr;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "core/backend.h"
|
#include "core/backend.h"
|
||||||
#include "core/layout.h"
|
#include "core/layout.h"
|
||||||
#include "core/state.h"
|
#include "core/state.h"
|
||||||
@@ -12,6 +14,7 @@ typedef struct runtime_init_desc_t {
|
|||||||
layout_registry_t layouts;
|
layout_registry_t layouts;
|
||||||
workspace_desc_t *workspaces;
|
workspace_desc_t *workspaces;
|
||||||
size_t workspace_count;
|
size_t workspace_count;
|
||||||
|
void *config_module_handle;
|
||||||
} runtime_init_desc_t;
|
} runtime_init_desc_t;
|
||||||
|
|
||||||
typedef struct runtime_t {
|
typedef struct runtime_t {
|
||||||
@@ -21,6 +24,7 @@ typedef struct runtime_t {
|
|||||||
state_t state;
|
state_t state;
|
||||||
layout_registry_t layouts;
|
layout_registry_t layouts;
|
||||||
backend_t *backend;
|
backend_t *backend;
|
||||||
|
void *config_module_handle;
|
||||||
} runtime_t;
|
} runtime_t;
|
||||||
|
|
||||||
bool runtime_init(runtime_t *runtime, runtime_init_desc_t *desc);
|
bool runtime_init(runtime_t *runtime, runtime_init_desc_t *desc);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
#include "base/memory.h"
|
||||||
#include "core/types.h"
|
#include "core/types.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -32,6 +33,28 @@ typedef struct workspace_desc_t {
|
|||||||
layout_id_t initial_layout_id;
|
layout_id_t initial_layout_id;
|
||||||
} workspace_desc_t;
|
} 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 描述校验接口。
|
* workspace 描述校验接口。
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -4,6 +4,9 @@ add_executable(${TEST_APP_NAME}
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/main.c
|
${CMAKE_CURRENT_SOURCE_DIR}/main.c
|
||||||
${SOURCE_DIR}/base/log.c
|
${SOURCE_DIR}/base/log.c
|
||||||
${SOURCE_DIR}/backend/output_utils.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}/backend/x11/backend.c
|
||||||
${SOURCE_DIR}/core/layout.c
|
${SOURCE_DIR}/core/layout.c
|
||||||
${SOURCE_DIR}/core/runtime.c
|
${SOURCE_DIR}/core/runtime.c
|
||||||
@@ -21,6 +24,7 @@ target_include_directories(${TEST_APP_NAME}
|
|||||||
|
|
||||||
target_link_libraries(${TEST_APP_NAME}
|
target_link_libraries(${TEST_APP_NAME}
|
||||||
PRIVATE m
|
PRIVATE m
|
||||||
|
PRIVATE ${CMAKE_DL_LIBS}
|
||||||
PRIVATE ${deps_LIBRARIES}
|
PRIVATE ${deps_LIBRARIES}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,41 @@
|
|||||||
|
#include "base/log.h"
|
||||||
|
#include "config/runtime_config.h"
|
||||||
|
#include "core/backend.h"
|
||||||
#include "core/runtime.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) {
|
int main(void) {
|
||||||
runtime_t runtime = {0};
|
runtime_t runtime = {0};
|
||||||
runtime_init(&runtime, nullptr);
|
|
||||||
|
|
||||||
|
bootstrap(&runtime);
|
||||||
runtime_shutdown(&runtime);
|
runtime_shutdown(&runtime);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user