Skip to content

Commit

Permalink
udpate
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroAir committed Feb 5, 2024
1 parent 5518db4 commit 096c1f9
Show file tree
Hide file tree
Showing 118 changed files with 3,333 additions and 3,961 deletions.
21 changes: 11 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ set(lithium_src_dir ${Lithium_PROJECT_ROOT_DIR}/src)
set(lithium_module_dir ${lithium_src_dir}/atom)
set(lithium_client_dir ${lithium_src_dir}/client)
set(lithium_component_dir ${lithium_src_dir}/addon)
set(lithium_task_dir ${lithium_src_dir}/task)

add_custom_target(CmakeAdditionalFiles
SOURCES
Expand Down Expand Up @@ -160,10 +161,14 @@ set(script_module
)

set(task_module
#${lithium_src_dir}/task/task_manager.cpp
#${lithium_src_dir}/task/task_stack.cpp
#${lithium_src_dir}/task/task_generator.cpp
#${lithium_src_dir}/task/task_container.cpp
${lithium_task_dir}/manager.cpp
${lithium_task_dir}/generator.cpp
${lithium_task_dir}/container.cpp
${lithium_task_dir}/tick.cpp
${lithium_task_dir}/loader.cpp
${lithium_task_dir}/list.cpp
${lithium_task_dir}/pool.cpp
# ${lithium_task_dir}/chekcer.cpp
)

set(Lithium_module
Expand Down Expand Up @@ -214,12 +219,6 @@ include_directories(${CMAKE_SOURCE_DIR}/libs/oatpp)
include_directories(${CMAKE_SOURCE_DIR}/libs/oatpp-swagger)
include_directories(${CMAKE_SOURCE_DIR}/libs/oatpp-websocket)

# TODO : 更好的构建系统,不需要这样引用
include_directories(${lithium_src_dir}/)
include_directories(${lithium_src_dir}/core)
include_directories(${lithium_src_dir}/core/base)
include_directories(${lithium_src_dir}/core/property)

# Build all dependencies
# 构建所有需要的依赖库
add_subdirectory(libs/)
Expand All @@ -236,6 +235,8 @@ add_subdirectory(${lithium_module_dir})
include_directories(modules)
add_subdirectory(modules)

add_subdirectory(${lithium_client_dir})


add_executable(lithium_server ${component_module} ${config_module} ${module_module} ${device_module} ${task_module} ${server_module} ${script_module} ${Lithium_module})

Expand Down
4 changes: 2 additions & 2 deletions locale/lithium.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: [email protected]\n"
"POT-Creation-Date: 2024-01-26 20:43+0800\n"
"POT-Creation-Date: 2024-02-06 04:56+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
Expand All @@ -17,7 +17,7 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: E:/msys64/home/Lithium/src/LithiumApp.cpp:589
#: E:/msys64/home/Lithium/src/LithiumApp.cpp:549
#, c++-format
msgid "Dispatched command {} with result: {}"
msgstr ""
2 changes: 1 addition & 1 deletion locale/po/en_US.UTF-8/lithium.po
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#: E:/msys64/home/Lithium/src/LithiumApp.cpp:589
#: E:/msys64/home/Lithium/src/LithiumApp.cpp:549
#, c++-format
msgid "Dispatched command {} with result: {}"
msgstr ""
64 changes: 12 additions & 52 deletions src/LithiumApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Description: Lithium App Enter
#include "config.h"

#include "atom/server/global_ptr.hpp"
#include "atom/driver/iproperty.hpp"

#include "atom/log/loguru.hpp"
#include "atom/type/json.hpp"
Expand Down Expand Up @@ -82,16 +81,9 @@ namespace Lithium
// Specialized Managers and Threads
m_ConfigManager = GetPtr<ConfigManager>("lithium.config");
m_DeviceManager = GetPtr<DeviceManager>("lithium.device");
m_ThreadManager = GetPtr<Atom::Async::ThreadManager>("lithium.async.thread");
m_ProcessManager = GetPtr<Atom::System::ProcessManager>("lithium.system.process");
m_MessageBus = GetPtr<Atom::Server::MessageBus>("lithium.bus");

// Specialized Message Processing Threads for Device and Device Manager
m_MessageBus->StartProcessingThread<IStringProperty>();
m_MessageBus->StartProcessingThread<IBoolProperty>();
m_MessageBus->StartProcessingThread<INumberProperty>();
m_MessageBus->StartProcessingThread<INumberVector>();

// Common Message Processing Threads
// Max : Maybe we only need one thread for Message, and dynamically cast message
// to the right type to process.
Expand Down Expand Up @@ -124,18 +116,28 @@ namespace Lithium
void InitLithiumApp()
{
LOG_F(INFO, "Init Lithium App");
// Config
AddPtr("lithium.config", ConfigManager::createShared());
// Message Bus
AddPtr("lithium.bus", Atom::Server::MessageBus::createShared());
// AddPtr("ModuleLoader", ModuleLoader::createShared());
AddPtr("lithium.async.thread", Atom::Async::ThreadManager::createShared(GetIntConfig("config/server/maxthread")));
// AddPtr("lithium.async.thread", Atom::Async::ThreadManager::createShared(GetIntConfig("config/server/maxthread")));
AddPtr("lithium.system.process", Atom::System::ProcessManager::createShared(GetIntConfig("config/server/maxprocess")));
// AddPtr("PluginManager", PluginManager::createShared(GetPtr<Process::ProcessManager>("ProcessManager")));
// AddPtr("TaskManager", std::make_shared<Task::TaskManager>("tasks.json"));
// AddPtr("TaskGenerator", std::make_shared<Task::TaskGenerator>(GetPtr<DeviceManager>("DeviceManager")));
// AddPtr("TaskStack", std::make_shared<Task::TaskStack>());
// AddPtr("ScriptManager", ScriptManager::createShared(GetPtr<MessageBus>("MessageBus")));
AddPtr("lithium.device", DeviceManager::createShared(GetPtr<Atom::Server::MessageBus>("lithium.bus"), GetPtr<ConfigManager>("ConfigManager")));
AddPtr("lithium.device", DeviceManager::createShared(GetPtr<Atom::Server::MessageBus>("lithium.bus"), GetPtr<ConfigManager>("lithium.config")));
AddPtr("lithium.error.stack", std::make_shared<Atom::Error::ErrorStack>());

AddPtr("lithium.task.container", TaskContainer::createShared());
AddPtr("lithiun.task.generator", TaskGenerator::createShared());
AddPtr("lithium.task.loader", TaskLoader::createShared());
AddPtr("lithium.task.pool", TaskPool::createShared(std::thread::hardware_concurrency()));
AddPtr("lithium.task.tick", TickScheduler::createShared(std::thread::hardware_concurrency()));
AddPtr("lithium.task.manager", TaskManager::createShared());

}

json createSuccessResponse(const std::string &command, const json &value)
Expand Down Expand Up @@ -530,48 +532,6 @@ namespace Lithium
return createSuccessResponse(__func__, output);
}

// -----------------------------------------------------------------
// Thread
// -----------------------------------------------------------------

json LithiumApp::joinAllThreads(const json &params)
{
INIT_FUNC();
if (!m_ThreadManager->joinAllThreads())
{
return createErrorResponse(__func__, json(), "Failed to join all threads");
}
return createSuccessResponse(__func__, json());
}

json LithiumApp::joinThreadByName(const json &params)
{
INIT_FUNC();
CHECK_PARAM("name");
std::string name = params["name"].get<std::string>();
if (!m_ThreadManager->isThreadRunning(name))
{
return createErrorResponse(__func__, json(), std::format("Thread {} does not exist", name));
}
if (!m_ThreadManager->joinThreadByName(name))
{
return createErrorResponse(__func__, json(), std::format("Failed to join thread {}", name));
}
return createSuccessResponse(__func__, json());
}

json LithiumApp::isThreadRunning(const json &params)
{
INIT_FUNC();
CHECK_PARAM("name");
std::string name = params["name"].get<std::string>();
if (!m_ThreadManager->isThreadRunning(name))
{
return createErrorResponse(__func__, json(), std::format("Thread {} does not exist", name));
}
return createSuccessResponse(__func__, json());
}

json LithiumApp::DispatchCommand(const std::string &name, const json &params)
{
if (name.empty())
Expand Down
8 changes: 3 additions & 5 deletions src/LithiumApp.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ Description: Lithium App Enter

#include <memory>

#include "atom/async/thread.hpp"
#include "config/configor.hpp"
#include "device/manager.hpp"
#include "atom/system/process.hpp"
Expand All @@ -28,6 +27,7 @@ Description: Lithium App Enter
#include "atom/server/commander.hpp"
#include "addon/manager.hpp"
#include "script/python.hpp"
#include "task/manager.hpp"

// -------------------------------------------------------------------
// About the LithiumApp
Expand Down Expand Up @@ -131,9 +131,6 @@ namespace Lithium
ReturnMessage returnMessage(const std::string &message);

public:
json joinThreadByName(const json &params);
json joinAllThreads(const json &params);
json isThreadRunning(const json &params);

// -------------------------------------------------------------------
// Lithium Command methods (the main entry point)
Expand Down Expand Up @@ -176,13 +173,14 @@ namespace Lithium
std::unique_ptr<CommandDispatcher<json, json>> m_CommandDispatcher;

private:
std::shared_ptr<Atom::Async::ThreadManager> m_ThreadManager;
std::shared_ptr<TaskPool> m_TaskPool;
std::shared_ptr<ConfigManager> m_ConfigManager;
std::shared_ptr<DeviceManager> m_DeviceManager;
std::shared_ptr<Atom::System::ProcessManager> m_ProcessManager;
std::shared_ptr<Atom::Server::MessageBus> m_MessageBus;
std::shared_ptr<Atom::Error::ErrorStack> m_ErrorStack;
std::shared_ptr<ComponentManager> m_ComponentManager;
std::shared_ptr<TaskManager> m_TaskManager;

std::shared_ptr<PyScriptManager> m_PyScriptManager;
};
Expand Down
10 changes: 5 additions & 5 deletions src/addon/loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Description: C++ and Modules Loader
#include <typeinfo>
#include <cxxabi.h>
#include <regex>
#include <mutex>

#include "atom/io/io.hpp"

Expand All @@ -45,9 +46,8 @@ namespace fs = std::filesystem;

namespace Lithium
{
ModuleLoader::ModuleLoader(const std::string &dir_name = "modules", std::shared_ptr<Atom::Async::ThreadManager> threadManager = Atom::Async::ThreadManager::createShared())
ModuleLoader::ModuleLoader(const std::string &dir_name = "modules")
{
m_ThreadManager = threadManager;
DLOG_F(INFO, "C++ module manager loaded successfully.");
}

Expand All @@ -65,12 +65,12 @@ namespace Lithium

std::shared_ptr<ModuleLoader> ModuleLoader::createShared()
{
return std::make_shared<ModuleLoader>("modules", Atom::Async::ThreadManager::createShared());
return std::make_shared<ModuleLoader>("modules");
}

std::shared_ptr<ModuleLoader> ModuleLoader::createShared(const std::string &dir_name = "modules", std::shared_ptr<Atom::Async::ThreadManager> threadManager = Atom::Async::ThreadManager::createShared())
std::shared_ptr<ModuleLoader> ModuleLoader::createShared(const std::string &dir_name = "modules")
{
return std::make_shared<ModuleLoader>(dir_name, threadManager);
return std::make_shared<ModuleLoader>(dir_name);
}

bool ModuleLoader::LoadModule(const std::string &path, const std::string &name)
Expand Down
8 changes: 2 additions & 6 deletions src/addon/loader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@ Description: C++ and Modules Loader
#include "atom/log/loguru.hpp"
#include "error/error_code.hpp"

#include "atom/async/thread.hpp"

using json = nlohmann::json;

namespace Lithium
Expand All @@ -77,7 +75,7 @@ namespace Lithium
* @param dir_name 模块所在的目录名称。
* @param threadManager 线程管理器的共享指针。
*/
ModuleLoader(const std::string &dir_name, std::shared_ptr<Atom::Async::ThreadManager> threadManager);
ModuleLoader(const std::string &dir_name);

/**
* @brief 析构函数,释放 ModuleLoader 对象。
Expand All @@ -101,7 +99,7 @@ namespace Lithium
* @param threadManager 线程管理器的共享指针。
* @return 新创建的共享 ModuleLoader 指针对象。
*/
static std::shared_ptr<ModuleLoader> createShared(const std::string &dir_name, std::shared_ptr<Atom::Async::ThreadManager> threadManager);
static std::shared_ptr<ModuleLoader> createShared(const std::string &dir_name);

// -------------------------------------------------------------------
// Module methods
Expand Down Expand Up @@ -336,8 +334,6 @@ namespace Lithium
#else
std::unordered_map<std::string, std::shared_ptr<ModuleInfo>> modules_; // 模块哈希表
#endif
// Injected Thread Manager
std::shared_ptr<Atom::Async::ThreadManager> m_ThreadManager;

mutable std::shared_mutex m_SharedMutex;
};
Expand Down
29 changes: 20 additions & 9 deletions src/atom/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
# CMakeLists.txt for Atom
# This project is licensed under the terms of the GPL3 license.
#
# Project Name: Atom
# Description: Atom Library for all of the Element Astro Project
# Author: Max Qian
# License: GPL3

cmake_minimum_required(VERSION 3.20)
project(atom C CXX)

CHECK_INCLUDE_FILE(format HAS_STD_FORMAT)

add_subdirectory(async)
add_subdirectory(components)
add_subdirectory(connection)
add_subdirectory(driver)
add_subdirectory(extra)
add_subdirectory(io)
add_subdirectory(log)
add_subdirectory(type)
add_subdirectory(web)
add_subdirectory(components)
add_subdirectory(server)
add_subdirectory(task)
add_subdirectory(driver)
add_subdirectory(type)
add_subdirectory(utils)
add_subdirectory(web)

if(NOT HAS_STD_FORMAT)
find_package(fmt REQUIRED)
Expand Down Expand Up @@ -99,12 +110,12 @@ list(APPEND ${PROJECT_NAME}_LIBS
loguru
cpp_httplib
libzippp
atom-asyncstatic
atom-utilsstatic
atom-driverstatic
atom-async
atom-task
atom-driver
atom-component
atom-utilsstatic
atom-webstatic
atom-utils
atom-web
)

# Build Object Library
Expand Down
Loading

0 comments on commit 096c1f9

Please sign in to comment.