refactor(runtime): 将 runtime 模块从 core 目录迁移至独立的 runtime 目录并封装内部细节
This commit is contained in:
42
src/main.c
42
src/main.c
@@ -3,52 +3,16 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "base/log.h"
|
||||
#include "config/runtime_config.h"
|
||||
#include "core/backend.h"
|
||||
#include "core/runtime.h"
|
||||
|
||||
static void bootstrap(runtime_t *runtime) {
|
||||
auto backend = backend_create(nullptr);
|
||||
auto 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("runtime init failed");
|
||||
}
|
||||
}
|
||||
#include "runtime/runtime.h"
|
||||
|
||||
char **cmd_argv = nullptr;
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
cmd_argv = argv;
|
||||
|
||||
runtime_t runtime = {0};
|
||||
auto restart = runtime_run(nullptr, nullptr);
|
||||
|
||||
bootstrap(&runtime);
|
||||
runtime_setup(&runtime);
|
||||
runtime_scan(&runtime);
|
||||
runtime_run(&runtime);
|
||||
runtime_shutdown(&runtime);
|
||||
|
||||
if (runtime.will_restart) {
|
||||
if (restart) {
|
||||
execvp(cmd_argv[0], cmd_argv);
|
||||
fatal("execvp() failed: %s", strerror(errno));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user