#add: 完成基础的项目结构搭建
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
idf_component_register(SRCS
|
||||
"application.cc"
|
||||
"context.cc"
|
||||
"loader.cc"
|
||||
INCLUDE_DIRS ".")
|
||||
@@ -0,0 +1,45 @@
|
||||
#include "application.hh"
|
||||
|
||||
#include <new> // For std::nothrow
|
||||
#include <stop_token> // For std::stop_source, std::stop_token, std::nostopstate
|
||||
#include <thread> // For std::jthread
|
||||
|
||||
#include "context.hh" // For context
|
||||
#include "loader.hh" // For loader::ui, loader::service
|
||||
|
||||
class impl {
|
||||
public:
|
||||
impl()
|
||||
: ui_thread_(&impl::ui_thread_function, this),
|
||||
service_thread_(&impl::service_thread_function, this),
|
||||
context_() {};
|
||||
~impl() noexcept = default;
|
||||
|
||||
void run() {
|
||||
context_.run();
|
||||
}
|
||||
|
||||
private:
|
||||
void ui_thread_function(std::stop_token token) {
|
||||
// Implementation of the UI thread function
|
||||
loader::ui ui_instance;
|
||||
ui_instance.set_context(&context_);
|
||||
}
|
||||
|
||||
void service_thread_function(std::stop_token token) {
|
||||
// Implementation of the service thread function
|
||||
loader::service service_instance;
|
||||
service_instance.set_context(&context_);
|
||||
}
|
||||
|
||||
private:
|
||||
std::jthread ui_thread_;
|
||||
std::jthread service_thread_;
|
||||
context context_;
|
||||
};
|
||||
|
||||
application::application() : pimpl_(new(std::nothrow) impl()) {}
|
||||
|
||||
application::~application() noexcept { delete pimpl_; }
|
||||
|
||||
void application::run() { pimpl_->run(); }
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef APPLICATION_HH
|
||||
#define APPLICATION_HH
|
||||
#pragma once
|
||||
|
||||
class impl;
|
||||
|
||||
class application {
|
||||
public:
|
||||
application();
|
||||
~application() noexcept;
|
||||
|
||||
void run();
|
||||
|
||||
private:
|
||||
impl *pimpl_;
|
||||
};
|
||||
|
||||
#endif // APPLICATION_HH
|
||||
@@ -0,0 +1,12 @@
|
||||
#ifndef CONTEXT_HH
|
||||
#define CONTEXT_HH
|
||||
#pragma once
|
||||
// 事件循环上下文
|
||||
class context {
|
||||
public:
|
||||
context() = default;
|
||||
~context() noexcept = default;
|
||||
|
||||
void run() noexcept;
|
||||
};
|
||||
#endif // CONTEXT_HH
|
||||
@@ -0,0 +1,25 @@
|
||||
#ifndef LOADER_HH
|
||||
#define LOADER_HH
|
||||
#pragma once
|
||||
|
||||
class context;
|
||||
|
||||
namespace loader {
|
||||
class ui {
|
||||
public:
|
||||
ui() = default;
|
||||
~ui() noexcept = default;
|
||||
|
||||
void set_context(context *ctx);
|
||||
};
|
||||
|
||||
class service {
|
||||
public:
|
||||
service() = default;
|
||||
~service() noexcept = default;
|
||||
|
||||
void set_context(context *ctx);
|
||||
};
|
||||
} // namespace loader
|
||||
|
||||
#endif // LOADER_HH
|
||||
Reference in New Issue
Block a user