Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroAir committed Jan 1, 2024
1 parent 8a64f63 commit 20d927f
Show file tree
Hide file tree
Showing 24 changed files with 350 additions and 204 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ 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
)

set(Lithium_module
Expand Down Expand Up @@ -228,7 +229,7 @@ target_link_libraries(lithium_server loguru)
target_link_libraries(lithium_server libzippp)
target_link_libraries(lithium_server atomstatic)

target_link_libraries(lithium_server lithiumcorestatic)
target_link_libraries(lithium_server atom.propertystatic)
target_link_libraries(lithium_server lithiumpluginstatic)
if(NOT WIN32)
target_link_libraries(lithium_server hydrogenclientstatic)
Expand Down
27 changes: 27 additions & 0 deletions client/lib/api/subsystem_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,31 @@ class SubsystemApi {
static removeByIds(data) {
return HttpUtil.post('/subsystem/removeByIds', data: data);
}

static loadById(String lib_path, String lib_name, int lib_type) {
return HttpUtil.post('/api/module/load', data: {
{'lib_path': lib_path},
{"lib_name", lib_name},
{"lib_type", lib_type}
});
}

static unloadById(String lib_path, String lib_name, int lib_type) {
return HttpUtil.post('/api/module/unload', data: {
{"lib_name", lib_name}
});
}

static enableById(String lib_path, String lib_name, int lib_type) {
return HttpUtil.post('/api/module/enable', data: {
{'lib_path': lib_path},
{"lib_name", lib_name}
});
}

static disableById(String lib_path, String lib_name, int lib_type) {
return HttpUtil.post('/api/module/disable', data: {
{"lib_name", lib_name}
});
}
}
4 changes: 2 additions & 2 deletions client/lib/common/routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ class Routes {
'/message': MessageMain(),
'/subsystemList': SubsystemMain(),
'/settingBase': SettingBase(),
'/secondLevel': OnlyText('二级菜单页面'),
'/threeLevel': OnlyText('三级菜单页面'),
//'/secondLevel': OnlyText('二级菜单页面'),
//'/threeLevel': OnlyText('三级菜单页面'),
};
static List<String> whiteRoutes = ['/register'];

Expand Down
2 changes: 1 addition & 1 deletion 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: 2023-12-30 21:14+0800\n"
"POT-Creation-Date: 2024-01-01 12:32+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 Down
1 change: 1 addition & 0 deletions src/atom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ add_subdirectory(type)
add_subdirectory(web)
add_subdirectory(connection)
add_subdirectory(components)
add_subdirectory(property)

if(NOT HAS_STD_FORMAT)
find_package(fmt REQUIRED)
Expand Down
70 changes: 70 additions & 0 deletions src/atom/property/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
cmake_minimum_required(VERSION 3.20)
project(atom.property C CXX)

# Sources
list(APPEND ${PROJECT_NAME}_SOURCES
task/daemon_task.cpp
task/device_task.cpp
task/loop_task.cpp
task/plugin_task.cpp
task/conditional_task.cpp
task/task.cpp

base64.cpp
iphoto.cpp
iproperty.cpp
uuid.cpp
)

# Headers
list(APPEND ${PROJECT_NAME}_HEADERS
task/daemon_task.hpp
task/device_task.hpp
task/loop_task.hpp
task/plugin_task.hpp
task/conditional_task.hpp
task/task.hpp

base64.hpp
iphoto.hpp
iproperty.hpp
uuid.hpp
sha256.hpp
)

# Private Headers
list(APPEND ${PROJECT_NAME}_PRIVATE_HEADERS

)

# Build Object Library
add_library(${PROJECT_NAME}_OBJECT OBJECT)
set_property(TARGET ${PROJECT_NAME}_OBJECT PROPERTY POSITION_INDEPENDENT_CODE 1)

target_link_libraries(${PROJECT_NAME}_OBJECT loguru)

target_sources(${PROJECT_NAME}_OBJECT
PUBLIC
${${PROJECT_NAME}_HEADERS}
PRIVATE
${${PROJECT_NAME}_SOURCES}
${${PROJECT_NAME}_PRIVATE_HEADERS}
)

target_link_libraries(${PROJECT_NAME}_OBJECT ${${PROJECT_NAME}_LIBS})

add_library(${PROJECT_NAME}static STATIC)

target_link_libraries(${PROJECT_NAME}static ${PROJECT_NAME}_OBJECT ${${PROJECT_NAME}_LIBS})
target_link_libraries(${PROJECT_NAME}static ${CMAKE_THREAD_LIBS_INIT})
target_include_directories(${PROJECT_NAME}static PUBLIC .)

set_target_properties(${PROJECT_NAME}static PROPERTIES
VERSION ${CMAKE_HYDROGEN_VERSION_STRING}
SOVERSION ${HYDROGEN_SOVERSION}
OUTPUT_NAME ${PROJECT_NAME} # this same name like shared library - backwards compatibility
)

install(TARGETS ${PROJECT_NAME}static
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
45 changes: 21 additions & 24 deletions src/atom/property/task/conditional_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,28 @@ Description: Conditional Task Definition

#include "conditional_task.hpp"

namespace Lithium
ConditionalTask::ConditionalTask(const std::function<bool(const json &)> &condition_fn,
const json &params,
const std::function<void(const json &)> &task_fn,
std::function<json(const json &)> &stop_fn)
: BasicTask(stop_fn, stop_fn != nullptr), condition_fn_(condition_fn), params_(params), task_fn_(task_fn) {}

// Executes the task
const json ConditionalTask::execute()
{
ConditionalTask::ConditionalTask(const std::function<bool(const json &)> &condition_fn,
const json &params,
const std::function<void(const json &)> &task_fn,
std::function<json(const json &)> &stop_fn)
: BasicTask(stop_fn, stop_fn != nullptr), condition_fn_(condition_fn), params_(params), task_fn_(task_fn) {}

// Executes the task
const json ConditionalTask::execute()
if (condition_fn_(params_))
{
if (condition_fn_(params_))
{
task_fn_(params_);
}
done_ = true;
return {{"status", "done"}};
task_fn_(params_);
}
done_ = true;
return {{"status", "done"}};
}

// Serializes the task to a JSON object
const json ConditionalTask::toJson() const
{
auto json = BasicTask::toJson();
json["type"] = "conditional";
json["params"] = params_;
return json;
}
} // namespace Lithium
// Serializes the task to a JSON object
const json ConditionalTask::toJson() const
{
auto json = BasicTask::toJson();
json["type"] = "conditional";
json["params"] = params_;
return json;
}
65 changes: 31 additions & 34 deletions src/atom/property/task/conditional_task.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,40 @@ Description: Conditional Task Definition

#include "task.hpp"

namespace Lithium
class ConditionalTask : public Atom::Task::BasicTask
{
class ConditionalTask : public BasicTask
{
public:
/**
* @brief ConditionalTask类构造函数
* @param condition_fn 条件函数,用于判断是否执行任务
* @param params 任务参数
* @param task_fn 任务函数,用于执行任务逻辑
* @param stop_fn 一个可选的停止函数,默认为nullptr
*/
ConditionalTask(const std::function<bool(const json &)> &condition_fn,
const json &params,
const std::function<void(const json &)> &task_fn,
std::function<json(const json &)> &stop_fn);
public:
/**
* @brief ConditionalTask类构造函数
* @param condition_fn 条件函数,用于判断是否执行任务
* @param params 任务参数
* @param task_fn 任务函数,用于执行任务逻辑
* @param stop_fn 一个可选的停止函数,默认为nullptr
*/
ConditionalTask(const std::function<bool(const json &)> &condition_fn,
const json &params,
const std::function<void(const json &)> &task_fn,
std::function<json(const json &)> &stop_fn);

/**
* @brief 执行任务的虚函数,由子类实现具体逻辑
* @return 以json格式返回任务执行结果
*/
virtual const json execute() override;
/**
* @brief 执行任务的虚函数,由子类实现具体逻辑
* @return 以json格式返回任务执行结果
*/
virtual const json execute() override;

/**
* @brief 将任务序列化为JSON对象
* @return 表示任务的JSON对象
*/
virtual const json toJson() const override;
/**
* @brief 将任务序列化为JSON对象
* @return 表示任务的JSON对象
*/
virtual const json toJson() const override;

private:
// 条件函数,用于判断是否执行任务
std::function<bool(const json &)> condition_fn_;
private:
// 条件函数,用于判断是否执行任务
std::function<bool(const json &)> condition_fn_;

// 任务参数
json params_;
// 任务参数
json params_;

// 任务函数,用于执行任务逻辑
std::function<void(const json &)> task_fn_;
};
}
// 任务函数,用于执行任务逻辑
std::function<void(const json &)> task_fn_;
};
56 changes: 26 additions & 30 deletions src/atom/property/task/daemon_task.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,21 @@ Description: Daemon Task Definition

#include "daemon_task.hpp"

namespace Lithium
DaemonTask::DaemonTask(const std::function<void()> &task_fn,
std::function<json(const json &)> &stop_fn)
: BasicTask(stop_fn, true), task_fn_(task_fn)
{
DaemonTask::DaemonTask(const std::function<void()> &task_fn,
std::function<json(const json &)> &stop_fn)
: BasicTask(stop_fn, true), task_fn_(task_fn)
{
}
}

const json DaemonTask::execute()
{
// 执行任务的具体逻辑实现
const json DaemonTask::execute()
{
// 执行任务的具体逻辑实现
#if __cplusplus >= 202002L
std::jthread task_thread([this](std::stop_token stoken)
{
std::jthread task_thread([this](std::stop_token stoken)
{
#else
std::jthread task_thread([this](std::stop_token stoken)
{
std::jthread task_thread([this](std::stop_token stoken)
{
#endif
while (!stoken.stop_requested())
{
Expand All @@ -57,24 +55,22 @@ namespace Lithium
}
}
done_ = true; });
task_thread.detach(); // 分离任务线程
return {{"status", "running"}};
}
task_thread.detach(); // 分离任务线程
return {{"status", "running"}};
}

const json DaemonTask::toJson() const
{
auto json = BasicTask::toJson();
json["type"] = "daemon";
return json;
}
const json DaemonTask::toJson() const
{
auto json = BasicTask::toJson();
json["type"] = "daemon";
return json;
}

void DaemonTask::runTask()
void DaemonTask::runTask()
{
while (!stop_flag_)
{
while (!stop_flag_)
{
task_fn_();
}
done_ = true;
task_fn_();
}

}
done_ = true;
}
Loading

0 comments on commit 20d927f

Please sign in to comment.