diff --git a/libs/cpp_httplib/httplib.h b/libs/cpp_httplib/httplib.h index abf91f52..ca6cca25 100644 --- a/libs/cpp_httplib/httplib.h +++ b/libs/cpp_httplib/httplib.h @@ -8,6 +8,8 @@ #ifndef CPPHTTPLIB_HTTPLIB_H #define CPPHTTPLIB_HTTPLIB_H +#define CPPHTTPLIB_OPENSSL_SUPPORT + #define CPPHTTPLIB_VERSION "0.14.1" /* diff --git a/locale/lithium.pot b/locale/lithium.pot index 532ca55a..6f7a3ab0 100644 --- a/locale/lithium.pot +++ b/locale/lithium.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: Lithium \n" "Report-Msgid-Bugs-To: astro_air@126.com\n" -"POT-Creation-Date: 2023-10-08 14:31+0800\n" +"POT-Creation-Date: 2023-10-19 02:44+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,275 +17,275 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:163 +#: /workspaces/Lithium/src/modules/device/device_manager.cpp:163 msgid "A device with name {} already exists, please choose a different name" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:190 +#: /workspaces/Lithium/src/modules/device/device_manager.cpp:190 msgid "Trying to add a new camera instance : {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:192 +#: /workspaces/Lithium/src/modules/device/device_manager.cpp:192 msgid "Added new camera {} instance successfully" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:197 +#: /workspaces/Lithium/src/modules/device/device_manager.cpp:197 msgid "Trying to add a new telescope instance : {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:199 +#: /workspaces/Lithium/src/modules/device/device_manager.cpp:199 msgid "Added new telescope instance successfully" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:204 +#: /workspaces/Lithium/src/modules/device/device_manager.cpp:204 msgid "Trying to add a new Focuser instance : {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/device_manager.cpp:206 +#: /workspaces/Lithium/src/modules/device/device_manager.cpp:206 msgid "Added new focuser instance successfully" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/device/indidevice_manager.cpp:266 +#: /workspaces/Lithium/src/modules/device/indidevice_manager.cpp:266 msgid "Failed to run command: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:63 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:63 msgid "Failed to destroy ThreadManager: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:82 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:82 msgid "Thread manager has stopped, cannot add new thread" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:100 -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:122 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:100 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:122 msgid "Unhandled exception in thread: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:128 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:128 msgid "Added thread: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:133 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:133 msgid "Failed to add thread {}: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:149 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:149 msgid "All threads joined" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:153 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:153 msgid "Failed to join all threads: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:163 -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:180 -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:194 -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:205 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:163 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:180 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:194 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:205 msgid "Thread {} not found" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:172 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:172 msgid "Thread {} joined" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:184 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:184 msgid "Failed to join thread {}: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/thread/thread.cpp:210 +#: /workspaces/Lithium/src/modules/thread/thread.cpp:210 msgid "Failed to check if thread {} is running: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:75 +#: /workspaces/Lithium/src/modules/system/process.cpp:75 msgid "Failed to create PowerShell process" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:85 +#: /workspaces/Lithium/src/modules/system/process.cpp:85 msgid "Running command: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:98 -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:122 -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:143 +#: /workspaces/Lithium/src/modules/system/process.cpp:98 +#: /workspaces/Lithium/src/modules/system/process.cpp:122 +#: /workspaces/Lithium/src/modules/system/process.cpp:143 msgid "Failed to create process" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:108 -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:153 +#: /workspaces/Lithium/src/modules/system/process.cpp:108 +#: /workspaces/Lithium/src/modules/system/process.cpp:153 msgid "Process created: {} (PID: {})" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:132 +#: /workspaces/Lithium/src/modules/system/process.cpp:132 msgid "Running script: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:170 -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:182 +#: /workspaces/Lithium/src/modules/system/process.cpp:170 +#: /workspaces/Lithium/src/modules/system/process.cpp:182 msgid "Process terminated: {} (PID: {})" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:174 +#: /workspaces/Lithium/src/modules/system/process.cpp:174 msgid "Failed to terminate process" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:190 -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:246 +#: /workspaces/Lithium/src/modules/system/process.cpp:190 +#: /workspaces/Lithium/src/modules/system/process.cpp:246 msgid "Process not found" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:205 +#: /workspaces/Lithium/src/modules/system/process.cpp:205 msgid "Process not found by name: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:212 +#: /workspaces/Lithium/src/modules/system/process.cpp:212 msgid "Currently running processes:" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:216 +#: /workspaces/Lithium/src/modules/system/process.cpp:216 msgid "{} (PID: {})" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:261 +#: /workspaces/Lithium/src/modules/system/process.cpp:261 msgid "Process completed: {} (PID: {})" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:265 +#: /workspaces/Lithium/src/modules/system/process.cpp:265 msgid "Failed to wait for process completion" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:271 +#: /workspaces/Lithium/src/modules/system/process.cpp:271 #, c-format msgid "Process completed: %s (PID: %d)" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:276 +#: /workspaces/Lithium/src/modules/system/process.cpp:276 msgid "All processes completed." msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:287 +#: /workspaces/Lithium/src/modules/system/process.cpp:287 msgid "Failed to create process snapshot" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:328 +#: /workspaces/Lithium/src/modules/system/process.cpp:328 msgid "Failed to open /proc directory" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:357 +#: /workspaces/Lithium/src/modules/system/process.cpp:357 msgid "Failed to get process path" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:378 +#: /workspaces/Lithium/src/modules/system/process.cpp:378 msgid "Failed to get process info length" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:385 +#: /workspaces/Lithium/src/modules/system/process.cpp:385 msgid "Failed to allocate memory" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/process.cpp:391 +#: /workspaces/Lithium/src/modules/system/process.cpp:391 msgid "Failed to get process info" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:94 +#: /workspaces/Lithium/src/modules/system/pid.cpp:94 msgid "CreateToolhelp32Snapshot failed." msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:113 +#: /workspaces/Lithium/src/modules/system/pid.cpp:113 msgid "Watching process with PID: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:124 +#: /workspaces/Lithium/src/modules/system/pid.cpp:124 msgid "Process exited with code: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:133 +#: /workspaces/Lithium/src/modules/system/pid.cpp:133 msgid "GetExitCodeProcess failed." msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:143 +#: /workspaces/Lithium/src/modules/system/pid.cpp:143 msgid "OpenProcess failed." msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:170 +#: /workspaces/Lithium/src/modules/system/pid.cpp:170 msgid "Process exited with status: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/modules/system/pid.cpp:179 +#: /workspaces/Lithium/src/modules/system/pid.cpp:179 msgid "Process terminated by signal: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:223 +#: /workspaces/Lithium/src/App.cpp:223 msgid "port the server running on" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:224 +#: /workspaces/Lithium/src/App.cpp:224 msgid "host the server running on" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:225 +#: /workspaces/Lithium/src/App.cpp:225 msgid "path to the config file" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:226 +#: /workspaces/Lithium/src/App.cpp:226 msgid "path to the modules directory" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:227 +#: /workspaces/Lithium/src/App.cpp:227 msgid "web panel" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:228 +#: /workspaces/Lithium/src/App.cpp:228 msgid "path to log file" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:230 +#: /workspaces/Lithium/src/App.cpp:230 msgid "Lithium Command Line Interface:" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:231 +#: /workspaces/Lithium/src/App.cpp:231 msgid "End." msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:239 +#: /workspaces/Lithium/src/App.cpp:239 #, c-format msgid "Failed to parser command line : %s" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:260 +#: /workspaces/Lithium/src/App.cpp:260 #, c-format msgid "Command line server port : %d" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/App.cpp:266 +#: /workspaces/Lithium/src/App.cpp:266 #, c-format msgid "Set server port to %d" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:67 +#: /workspaces/Lithium/src/LithiumApp.cpp:67 msgid "Failed to load Lithium App , error : {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:79 +#: /workspaces/Lithium/src/LithiumApp.cpp:79 msgid "Get config value: {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:85 +#: /workspaces/Lithium/src/LithiumApp.cpp:85 msgid "Set {} to {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:272 +#: /workspaces/Lithium/src/LithiumApp.cpp:272 msgid "Failed to run chai command : {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:290 +#: /workspaces/Lithium/src/LithiumApp.cpp:290 msgid "Failed to run chai multi command {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:303 +#: /workspaces/Lithium/src/LithiumApp.cpp:303 msgid "Failed to load chaiscript file {}" msgstr "" -#: E:/msys64/home/Qrm/OpenAPT/src/LithiumApp.cpp:316 +#: /workspaces/Lithium/src/LithiumApp.cpp:316 msgid "Failed to run chai script {}" msgstr "" diff --git a/src/App.cpp b/src/App.cpp index 8b691210..c61b67a6 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -35,7 +35,7 @@ Description: Main #include "controller/AsyncStaticController.hpp" #include "controller/AsyncSystemController.hpp" #include "controller/AsyncWebSocketController.hpp" -#include "controller/IOController.hpp" +#include "controller/AsyncIOController.hpp" #include "controller/AsyncProcessController.hpp" #include "controller/AsyncPHD2Controller.hpp" #include "controller/AsyncTaskController.hpp" diff --git a/src/AppComponent.hpp b/src/AppComponent.hpp index 370b50bb..5db696e8 100644 --- a/src/AppComponent.hpp +++ b/src/AppComponent.hpp @@ -1,5 +1,5 @@ /* - * AppComponent.cpp + * AppComponent.hpp * * Copyright (C) 2023 Max Qian * diff --git a/src/ErrorHandler.cpp b/src/ErrorHandler.cpp index 0ee2ce31..4d2577c6 100644 --- a/src/ErrorHandler.cpp +++ b/src/ErrorHandler.cpp @@ -1,3 +1,34 @@ +/* + * ErrorHandle.cpp + * + * Copyright (C) 2023 Max Qian + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/************************************************* + +Copyright: 2023 Max Qian. All rights reserved + +Author: Max Qian + +E-mail: astro_air@126.com + +Date: 2023-7-13 + +Description: Error Handle (404 or 500) + +**************************************************/ + #include "ErrorHandler.hpp" ErrorHandler::ErrorHandler(const std::shared_ptr &objectMapper) diff --git a/src/ErrorHandler.hpp b/src/ErrorHandler.hpp index 84e3da5c..aae39351 100644 --- a/src/ErrorHandler.hpp +++ b/src/ErrorHandler.hpp @@ -1,3 +1,34 @@ +/* + * ErrorHandle.hpp + * + * Copyright (C) 2023 Max Qian + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/************************************************* + +Copyright: 2023 Max Qian. All rights reserved + +Author: Max Qian + +E-mail: astro_air@126.com + +Date: 2023-7-13 + +Description: Error Handle (404 or 500) + +**************************************************/ + #ifndef Lithium_ERRORHANDLER_HPP #define Lithium_ERRORHANDLER_HPP diff --git a/src/LithiumApp.cpp b/src/LithiumApp.cpp index d393c0f5..395da9e3 100644 --- a/src/LithiumApp.cpp +++ b/src/LithiumApp.cpp @@ -74,13 +74,13 @@ namespace Lithium m_MessageBus->StopAllProcessingThreads(); } - nlohmann::json LithiumApp::GetConfig(const std::string &key_path) const + json LithiumApp::GetConfig(const std::string &key_path) const { DLOG_F(INFO, _("Get config value: {}"), key_path); return m_ConfigManager->getValue(key_path); } - void LithiumApp::SetConfig(const std::string &key_path, const nlohmann::json &value) + void LithiumApp::SetConfig(const std::string &key_path, const json &value) { DLOG_F(INFO, _("Set {} to {}"), key_path, value.dump()); m_ConfigManager->setValue(key_path, value); @@ -136,7 +136,7 @@ namespace Lithium return m_DeviceManager->findDeviceByName(name); } - std::shared_ptr LithiumApp::getTask(DeviceType type, const std::string &device_name, const std::string &task_name, const nlohmann::json ¶ms) + std::shared_ptr LithiumApp::getTask(DeviceType type, const std::string &device_name, const std::string &task_name, const json ¶ms) { return m_DeviceManager->getTask(type, device_name, task_name, params); } diff --git a/src/LithiumApp.hpp b/src/LithiumApp.hpp index 39d27a21..5f75e956 100644 --- a/src/LithiumApp.hpp +++ b/src/LithiumApp.hpp @@ -49,6 +49,7 @@ Description: Lithium App Enter namespace Lithium { + class LithiumApp { public: diff --git a/src/client/astap.cpp b/src/client/astap.cpp index a64e300e..ab9dd2b2 100644 --- a/src/client/astap.cpp +++ b/src/client/astap.cpp @@ -48,7 +48,7 @@ Description: Astap Solver Interface #include #endif -#include +#include "loguru/loguru.hpp" #include using namespace std; diff --git a/src/client/astrometry.cpp b/src/client/astrometry.cpp index dcff890d..7f25acc8 100644 --- a/src/client/astrometry.cpp +++ b/src/client/astrometry.cpp @@ -35,7 +35,11 @@ Description: Astrometry Command Line #include #include #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include #include #include diff --git a/src/client/phd2client.cpp b/src/client/phd2client.cpp index ad15d4b4..0962beef 100644 --- a/src/client/phd2client.cpp +++ b/src/client/phd2client.cpp @@ -3,7 +3,7 @@ #include #include #include -#include +#include "loguru/loguru.hpp" #define CONNECT_CHECK(func) \ if (!phd2_client->IsConnected()) \ diff --git a/src/client/phd2client.hpp b/src/client/phd2client.hpp index f9220ffd..3a4b3093 100644 --- a/src/client/phd2client.hpp +++ b/src/client/phd2client.hpp @@ -10,7 +10,7 @@ #include -#include +#include "nlohmann/json.hpp" #ifdef _WIN32 #include diff --git a/src/core/camera.cpp b/src/core/camera.cpp index d927af0f..3fa4de56 100644 --- a/src/core/camera.cpp +++ b/src/core/camera.cpp @@ -61,7 +61,7 @@ bool Camera::reconnect(const IParams ¶ms) return true; } -bool Camera::isConnected(const IParams ¶ms) +bool Camera::isConnected() { return true; } diff --git a/src/core/camera.hpp b/src/core/camera.hpp index f5656bba..6467e0bd 100644 --- a/src/core/camera.hpp +++ b/src/core/camera.hpp @@ -37,7 +37,7 @@ Description: Camera Simulator and Basic Definition #include "shared_memory.hpp" #endif -class Camera : virtual public Device +class Camera : public Device { public: /** @@ -55,7 +55,7 @@ class Camera : virtual public Device virtual bool reconnect(const IParams ¶ms) override; - virtual bool isConnected(const IParams ¶ms) override; + virtual bool isConnected() override; public: /** diff --git a/src/core/device.hpp b/src/core/device.hpp index e6b63e16..6687fa52 100644 --- a/src/core/device.hpp +++ b/src/core/device.hpp @@ -37,7 +37,7 @@ Description: Basic Device Defination #include #include -#include +#include "nlohmann/json.hpp" #include "emhash/hash_table8.hpp" #include "property/iproperty.hpp" diff --git a/src/core/deviceio.cpp b/src/core/deviceio.cpp index 4619be75..3e69e0a3 100644 --- a/src/core/deviceio.cpp +++ b/src/core/deviceio.cpp @@ -32,7 +32,7 @@ Description: Device IO Module #include "deviceio.hpp" #include "event/eventloop.hpp" -#include +#include "loguru/loguru.hpp" #include #include diff --git a/src/core/event/eventloop.hpp b/src/core/event/eventloop.hpp index f6da8727..270a022f 100644 --- a/src/core/event/eventloop.hpp +++ b/src/core/event/eventloop.hpp @@ -33,7 +33,11 @@ Description: EventLoop #include #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include #include #include diff --git a/src/core/network/fifoclient.cpp b/src/core/network/fifoclient.cpp index 2a70fe14..01cec5f3 100644 --- a/src/core/network/fifoclient.cpp +++ b/src/core/network/fifoclient.cpp @@ -31,7 +31,7 @@ Description: FIFO CLient #include "fifoclient.hpp" #include -#include +#include "loguru/loguru.hpp" #ifdef _WIN32 FifoClient::FifoClient(const std::string &fifoPath) : fifoPath(fifoPath), pipeHandle(INVALID_HANDLE_VALUE) diff --git a/src/core/network/fifoserver.cpp b/src/core/network/fifoserver.cpp index c14bb830..7238f780 100644 --- a/src/core/network/fifoserver.cpp +++ b/src/core/network/fifoserver.cpp @@ -31,7 +31,7 @@ Description: FIFO Server #include "fifoserver.hpp" #include -#include +#include "loguru/loguru.hpp" #ifdef _WIN32 FifoServer::FifoServer(const std::string &fifoPath) : fifoPath(fifoPath), pipeHandle(INVALID_HANDLE_VALUE) diff --git a/src/core/shared_memory.hpp b/src/core/shared_memory.hpp index 0619f49b..69610253 100644 --- a/src/core/shared_memory.hpp +++ b/src/core/shared_memory.hpp @@ -1,7 +1,7 @@ #include #include -#include +#include "loguru/loguru.hpp" #if defined(_WIN32) || defined(_WIN64) // Windows #include diff --git a/src/debug/launcher.hpp b/src/debug/launcher.hpp index f281fedd..5fdaa6d1 100644 --- a/src/debug/launcher.hpp +++ b/src/debug/launcher.hpp @@ -43,7 +43,7 @@ Description: Lithium Server Launcher #include #include #include -#include +#include "nlohmann/json.hpp" using json = nlohmann::json; namespace fs = std::filesystem; diff --git a/src/modules/config/configor.cpp b/src/modules/config/configor.cpp index 0cba01b3..5093bf89 100644 --- a/src/modules/config/configor.cpp +++ b/src/modules/config/configor.cpp @@ -31,7 +31,11 @@ Description: Configor #include #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include #include diff --git a/src/modules/device/device_manager.cpp b/src/modules/device/device_manager.cpp index 9994668d..1f025a77 100644 --- a/src/modules/device/device_manager.cpp +++ b/src/modules/device/device_manager.cpp @@ -989,7 +989,7 @@ namespace Lithium or "name" : "gain" */ - CHECK_MAIN_CAMERA_J; + CHECK_DEVICE_J(m_main_camera, "no main camera specific"); json res; if (m_params.is_array()) { diff --git a/src/modules/device/indi_device.cpp b/src/modules/device/indi_device.cpp index 65650efb..ca19b1e5 100644 --- a/src/modules/device/indi_device.cpp +++ b/src/modules/device/indi_device.cpp @@ -40,7 +40,7 @@ Description: INDI Web Driver #include #define LOGURU_USE_FMTLIB 1 -#include +#include "loguru/loguru.hpp" #ifdef _WIN32 #include diff --git a/src/modules/device/indi_device.hpp b/src/modules/device/indi_device.hpp index 7bd0c9d7..6c768997 100644 --- a/src/modules/device/indi_device.hpp +++ b/src/modules/device/indi_device.hpp @@ -36,7 +36,7 @@ Description: INDI Web Driver #include #include -#include +#include "nlohmann/json.hpp" using json = nlohmann::json; diff --git a/src/modules/device/indidevice_manager.cpp b/src/modules/device/indidevice_manager.cpp index dab22d8d..7b81a1eb 100644 --- a/src/modules/device/indidevice_manager.cpp +++ b/src/modules/device/indidevice_manager.cpp @@ -88,13 +88,13 @@ void INDIManager::start_server() } // Clear old fifo pipe and create new one DLOG_F(INFO, "Deleting fifo pipe at: {}", fifo_path); - system(("rm -f " + fifo_path).c_str()); - system(("mkfifo " + fifo_path).c_str()); + int res = system(("rm -f " + fifo_path).c_str()); + res = system(("mkfifo " + fifo_path).c_str()); // Just start the server without driver std::string cmd = "indiserver -p " + std::to_string(port) + " -m 100 -v -f " + fifo_path + " > /tmp/indiserver.log 2>&1 &"; DLOG_F(INFO, "Started INDI server on port ", port); - system(cmd.c_str()); + res = system(cmd.c_str()); } #endif @@ -192,7 +192,7 @@ void INDIManager::start_driver(std::shared_ptr driver) DLOG_F(ERROR, "Failed to start driver: {}", driver->name); } #else - system(full_cmd.c_str()); + int res = system(full_cmd.c_str()); DLOG_F(INFO, "Started driver : {}", driver->name); #endif @@ -226,7 +226,7 @@ void INDIManager::stop_driver(std::shared_ptr driver) DLOG_F(ERROR, "Failed to stop driver: {}", driver->label); } #else - system(full_cmd.c_str()); + int res = system(full_cmd.c_str()); DLOG_F(INFO, "Stop running driver: {}", driver->label); running_drivers.erase(driver->label); #endif diff --git a/src/modules/deviceloader/hydrogen_server.cpp b/src/modules/deviceloader/hydrogen_server.cpp index 8ac91899..3065ac04 100644 --- a/src/modules/deviceloader/hydrogen_server.cpp +++ b/src/modules/deviceloader/hydrogen_server.cpp @@ -3,7 +3,11 @@ #include #include #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include #include #include diff --git a/src/modules/deviceloader/hydrogen_server.hpp b/src/modules/deviceloader/hydrogen_server.hpp index b4312488..406ee199 100644 --- a/src/modules/deviceloader/hydrogen_server.hpp +++ b/src/modules/deviceloader/hydrogen_server.hpp @@ -1,8 +1,12 @@ #pragma once #ifndef MAIN_FUNC +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include #endif +#endif #include "fifo_server.hpp" #include "driver_info.hpp" diff --git a/src/modules/deviceloader/serialize.cpp b/src/modules/deviceloader/serialize.cpp index b45eebe9..b5d1c3f6 100644 --- a/src/modules/deviceloader/serialize.cpp +++ b/src/modules/deviceloader/serialize.cpp @@ -1,7 +1,11 @@ #include "serialize.hpp" #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include diff --git a/src/modules/deviceloader/xml_util.hpp b/src/modules/deviceloader/xml_util.hpp index a59cf26e..30e5705b 100644 --- a/src/modules/deviceloader/xml_util.hpp +++ b/src/modules/deviceloader/xml_util.hpp @@ -1,7 +1,11 @@ #pragma once #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include "lilxml.hpp" diff --git a/src/modules/error/error_stack.cpp b/src/modules/error/error_stack.cpp index fd3fb898..fa1992d5 100644 --- a/src/modules/error/error_stack.cpp +++ b/src/modules/error/error_stack.cpp @@ -32,7 +32,7 @@ Description: Error Stack #include "error_stack.hpp" #include -#include +#include "loguru/loguru.hpp" std::ostream &operator<<(std::ostream &os, const ErrorInfo &error) { diff --git a/src/modules/io/compress.cpp b/src/modules/io/compress.cpp index f1370f62..0d73c057 100644 --- a/src/modules/io/compress.cpp +++ b/src/modules/io/compress.cpp @@ -85,7 +85,7 @@ namespace Lithium::File std::filesystem::path input_path(file_name); if (!std::filesystem::exists(input_path)) { - DLOG_F(ERROR, "Input file %s does not exist.", file_name.c_str()); + DLOG_F(ERROR, "Input file {} does not exist.", file_name); return false; } @@ -93,14 +93,14 @@ namespace Lithium::File gzFile out = gzopen(output_path.string().c_str(), "wb"); if (!out) { - DLOG_F(ERROR, "Failed to create compressed file %s", output_path.string().c_str()); + DLOG_F(ERROR, "Failed to create compressed file {}", output_path.string()); return false; } std::ifstream in(file_name, std::ios::binary); if (!in) { - DLOG_F(ERROR, "Failed to open input file %s", file_name.c_str()); + DLOG_F(ERROR, "Failed to open input file {}", file_name); gzclose(out); return false; } @@ -113,7 +113,7 @@ namespace Lithium::File if (gzwrite(out, buf, bytesRead) != bytesRead) { - DLOG_F(ERROR, "Failed to compress file %s", file_name.c_str()); + DLOG_F(ERROR, "Failed to compress file {}", file_name); in.close(); gzclose(out); return false; @@ -122,7 +122,7 @@ namespace Lithium::File in.close(); gzclose(out); - DLOG_F(INFO, "Compressed file %s -> %s", file_name.c_str(), output_path.string().c_str()); + DLOG_F(INFO, "Compressed file {} -> {}", file_name, output_path.string()); return true; } @@ -131,7 +131,7 @@ namespace Lithium::File std::filesystem::path input_path(file_name); if (!std::filesystem::exists(input_path)) { - DLOG_F(ERROR, "Input file %s does not exist.", file_name.c_str()); + DLOG_F(ERROR, "Input file {} does not exist.", file_name); return false; } @@ -139,14 +139,14 @@ namespace Lithium::File FILE *out = fopen(output_path.string().c_str(), "wb"); if (!out) { - DLOG_F(ERROR, "Failed to create decompressed file %s", output_path.string().c_str()); + DLOG_F(ERROR, "Failed to create decompressed file {}", output_path.string()); return false; } gzFile in = gzopen(file_name.c_str(), "rb"); if (!in) { - DLOG_F(ERROR, "Failed to open compressed file %s", file_name.c_str()); + DLOG_F(ERROR, "Failed to open compressed file {}", file_name); fclose(out); return false; } @@ -157,7 +157,7 @@ namespace Lithium::File { if (fwrite(buf, 1, bytesRead, out) != static_cast(bytesRead)) { - DLOG_F(ERROR, "Failed to decompress file %s", file_name.c_str()); + DLOG_F(ERROR, "Failed to decompress file {}", file_name); fclose(out); gzclose(in); return false; @@ -166,7 +166,7 @@ namespace Lithium::File fclose(out); gzclose(in); - DLOG_F(INFO, "Decompressed file %s -> %s", file_name.c_str(), output_path.string().c_str()); + DLOG_F(INFO, "Decompressed file {} -> {}", file_name, output_path.string()); return true; } @@ -174,11 +174,11 @@ namespace Lithium::File { // Size of the read/write buffer char outfile_name[256]; - sprintf(outfile_name, "%s.gz", folder_name); + sprintf(outfile_name, "{}.gz", folder_name); gzFile out = gzopen(outfile_name, "wb"); if (!out) { - DLOG_F(ERROR, "Failed to create compressed file %s", outfile_name); + DLOG_F(ERROR, "Failed to create compressed file {}", outfile_name); return false; } #ifdef _WIN32 @@ -186,11 +186,11 @@ namespace Lithium::File // File handle WIN32_FIND_DATAA findData; char searchPath[256]; - sprintf(searchPath, "%s\\*", folder_name); + sprintf(searchPath, "{}\\*", folder_name); hFind = FindFirstFileA(searchPath, &findData); if (hFind == INVALID_HANDLE_VALUE) { - DLOG_F(ERROR, "Failed to open folder %s", folder_name); + DLOG_F(ERROR, "Failed to open folder {}", folder_name); gzclose(out); return false; } @@ -201,7 +201,7 @@ namespace Lithium::File continue; // Construct the file path char file_name[256]; - sprintf(file_name, "%s%c%s", folder_name, PATH_SEPARATOR, findData.cFileName); + sprintf(file_name, "{}%c{}", folder_name, PATH_SEPARATOR, findData.cFileName); // If it's a directory, recursively call this function if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { @@ -223,7 +223,7 @@ namespace Lithium::File FILE *in = fopen(file_name, "rb"); if (!in) { - DLOG_F(WARNING, "Failed to open file %s", file_name); + DLOG_F(WARNING, "Failed to open file {}", file_name); continue; } char buf[CHUNK]; @@ -247,7 +247,7 @@ namespace Lithium::File dir = opendir(folder_name); if (!dir) { - DLOG_F(ERROR, "Failed to open folder %s", folder_name); + DLOG_F(ERROR, "Failed to open folder {}", folder_name); gzclose(out); return false; } @@ -256,10 +256,10 @@ namespace Lithium::File if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) continue; char file_name[512]; - int ret = snprintf(file_name, sizeof(file_name), "%s/%s", folder_name, entry->d_name); + int ret = snprintf(file_name, sizeof(file_name), "{}/{}", folder_name, entry->d_name); if (ret < 0 || ret >= sizeof(file_name)) { - DLOG_F(ERROR, "Failed to compress file %s because the output was truncated or an error occurred in snprintf()", entry->d_name); + DLOG_F(ERROR, "Failed to compress file {} because the output was truncated or an error occurred in snprintf()", entry->d_name); closedir(dir); gzclose(out); return false; @@ -285,7 +285,7 @@ namespace Lithium::File FILE *in = fopen(file_name, "rb"); if (!in) { - DLOG_F(WARNING, "Failed to open file %s", file_name); + DLOG_F(WARNING, "Failed to open file {}", file_name); continue; } char buf[CHUNK]; @@ -296,7 +296,7 @@ namespace Lithium::File { fclose(in); gzclose(out); - DLOG_F(ERROR, "Failed to compress file %s", file_name); + DLOG_F(ERROR, "Failed to compress file {}", file_name); return false; } } @@ -305,7 +305,7 @@ namespace Lithium::File closedir(dir); #endif gzclose(out); - DLOG_F(INFO, "Compressed folder %s -> %s", folder_name, outfile_name); + DLOG_F(INFO, "Compressed folder {} -> {}", folder_name, outfile_name); return true; } @@ -314,7 +314,7 @@ namespace Lithium::File std::ifstream file(zip_file, std::ios::binary); if (!file) { - DLOG_F(ERROR, "Failed to open ZIP file: %s", zip_file.c_str()); + DLOG_F(ERROR, "Failed to open ZIP file: {}", zip_file); return false; } file.close(); @@ -324,7 +324,7 @@ namespace Lithium::File const std::string &strerror, int zip_error_code, int system_error_code) - { DLOG_F(ERROR, "Exract zip file failed : %s %s", message.c_str(), strerror.c_str()); }); + { DLOG_F(ERROR, "Exract zip file failed : {} {}", message, strerror); }); zip.open(ZipArchive::ReadOnly); ProgressListener pl; zip.addProgressListener(&pl); @@ -337,7 +337,7 @@ namespace Lithium::File { std::string name = entry.getName(); int size = entry.getSize(); - DLOG_F(ERROR, "Extracting file: %s, size: %d", name.c_str(), size); + DLOG_F(ERROR, "Extracting file: {}, size: %d", name, size); std::string textData = entry.readAsText(); std::filesystem::path file_path = std::filesystem::path(destination_folder) / name; std::ofstream file(file_path); @@ -345,11 +345,11 @@ namespace Lithium::File { file << textData; file.close(); - DLOG_F(INFO, "File extracted: %s", file_path.c_str()); + DLOG_F(INFO, "File extracted: {}", file_path); } else { - DLOG_F(ERROR, "Failed to create file: %s", file_path.c_str()); + DLOG_F(ERROR, "Failed to create file: {}", file_path); } } zip.close(); @@ -358,7 +358,7 @@ namespace Lithium::File } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to extract ZIP file: %s", e.what()); + DLOG_F(ERROR, "Failed to extract ZIP file: {}", e.what()); return false; } } @@ -372,7 +372,7 @@ namespace Lithium::File const std::string &strerror, int zip_error_code, int system_error_code) - { DLOG_F(ERROR, "Create zip file failed : %s %s", message.c_str(), strerror.c_str()); }); + { DLOG_F(ERROR, "Create zip file failed : {} {}", message, strerror); }); zip.open(ZipArchive::Write); ProgressListener pl; @@ -398,7 +398,7 @@ namespace Lithium::File } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to create ZIP file: %s", e.what()); + DLOG_F(ERROR, "Failed to create ZIP file: {}", e.what()); return false; } } diff --git a/src/modules/io/file.cpp b/src/modules/io/file.cpp index 331cc5e3..773e232f 100644 --- a/src/modules/io/file.cpp +++ b/src/modules/io/file.cpp @@ -57,18 +57,18 @@ namespace Lithium::File { if (fileExists(filename)) { - DLOG_F(ERROR, "File \"%s\" already exists!", filename.c_str()); + DLOG_F(ERROR, "File \"{}\" already exists!", filename); return false; } std::ofstream outfile(filename); if (!outfile) { - DLOG_F(ERROR, "Error creating file \"%s\"!", filename.c_str()); + DLOG_F(ERROR, "Error creating file \"{}\"!", filename); return false; } outfile.close(); std::fclose(std::fopen(filename.c_str(), "a")); // create a link to the file - DLOG_F(INFO, "Created file \"%s\"", filename.c_str()); + DLOG_F(INFO, "Created file \"{}\"", filename); return true; } @@ -76,17 +76,17 @@ namespace Lithium::File { if (!fileExists(filename)) { - DLOG_F(ERROR, "File \"%s\" does not exist!", filename.c_str()); + DLOG_F(ERROR, "File \"{}\" does not exist!", filename); return false; } m_filename = filename; m_file.open(filename, std::ios::in | std::ios::out); if (!m_file) { - DLOG_F(ERROR, "Could not open file \"%s\"!", filename.c_str()); + DLOG_F(ERROR, "Could not open file \"{}\"!", filename); return false; } - DLOG_F(INFO, "Opened file \"%s\"", filename.c_str()); + DLOG_F(INFO, "Opened file \"{}\"", filename); return true; } @@ -100,7 +100,7 @@ namespace Lithium::File std::stringstream buffer; buffer << m_file.rdbuf(); contents = buffer.str(); - DLOG_F(INFO, "Read contents of file \"%s\"", m_filename.c_str()); + DLOG_F(INFO, "Read contents of file \"{}\"", m_filename); return true; } @@ -112,7 +112,7 @@ namespace Lithium::File return false; } m_file << contents; - DLOG_F(INFO, "Wrote contents to file \"%s\"", m_filename.c_str()); + DLOG_F(INFO, "Wrote contents to file \"{}\"", m_filename); return true; } @@ -120,21 +120,21 @@ namespace Lithium::File { if (!fileExists(oldFilename)) { - DLOG_F(ERROR, "File \"%s\" does not exist!", oldFilename.c_str()); + DLOG_F(ERROR, "File \"{}\" does not exist!", oldFilename); return false; } if (fileExists(newFilename)) { - DLOG_F(ERROR, "File \"%s\" already exists!", newFilename.c_str()); + DLOG_F(ERROR, "File \"{}\" already exists!", newFilename); return false; } int result = std::rename(oldFilename.c_str(), newFilename.c_str()); if (result != 0) { - DLOG_F(ERROR, "Could not move file from \"%s\" to \"%s\"!", oldFilename.c_str(), newFilename.c_str()); + DLOG_F(ERROR, "Could not move file from \"{}\" to \"{}\"!", oldFilename, newFilename); return false; } - DLOG_F(INFO, "Moved file from \"%s\" to \"%s\"", oldFilename.c_str(), newFilename.c_str()); + DLOG_F(INFO, "Moved file from \"{}\" to \"{}\"", oldFilename, newFilename); return true; } @@ -142,15 +142,15 @@ namespace Lithium::File { if (!fileExists(filename)) { - DLOG_F(ERROR, "File \"%s\" does not exist!", filename.c_str()); + DLOG_F(ERROR, "File \"{}\" does not exist!", filename); return false; } if (std::remove(filename.c_str()) != 0) { - DLOG_F(ERROR, "Could not delete file \"%s\"!", filename.c_str()); + DLOG_F(ERROR, "Could not delete file \"{}\"!", filename); return false; } - DLOG_F(INFO, "Deleted file \"%s\"", filename.c_str()); + DLOG_F(INFO, "Deleted file \"{}\"", filename); return true; } @@ -166,11 +166,11 @@ namespace Lithium::File m_file.seekg(0, m_file.beg); if (fileSize == -1) { - DLOG_F(ERROR, "Could not get file size of \"%s\"!", m_filename.c_str()); + DLOG_F(ERROR, "Could not get file size of \"{}\"!", m_filename); } else { - DLOG_F(INFO, "File size of \"%s\" is %ld bytes", m_filename.c_str(), fileSize); + DLOG_F(INFO, "File size of \"{}\" is %ld bytes", m_filename, fileSize); } return fileSize; } @@ -226,7 +226,7 @@ namespace Lithium::File sha256Stream << std::setw(2) << static_cast(hash[i]); } - DLOG_F(INFO, "SHA-256 value for file \"%s\" is %s", m_filename.c_str(), sha256Stream.str().c_str()); + DLOG_F(INFO, "SHA-256 value for file \"{}\" is {}", m_filename, sha256Stream.str()); return sha256Stream.str(); } @@ -235,13 +235,13 @@ namespace Lithium::File size_t pos = filename.find_last_of("/\\"); if (pos == std::string::npos) { - DLOG_F(ERROR, "Could not get directory of file \"%s\"", filename.c_str()); + DLOG_F(ERROR, "Could not get directory of file \"{}\"", filename); return ""; } else { std::string directory = filename.substr(0, pos); - DLOG_F(INFO, "Directory of file \"%s\" is \"%s\"", filename.c_str(), directory.c_str()); + DLOG_F(INFO, "Directory of file \"{}\" is \"{}\"", filename, directory); return directory; } } diff --git a/src/modules/io/io.cpp b/src/modules/io/io.cpp index dd704d59..4617e72f 100644 --- a/src/modules/io/io.cpp +++ b/src/modules/io/io.cpp @@ -59,12 +59,12 @@ namespace Lithium::File try { fs::create_directory(path); - DLOG_F(INFO, "Directory created: %s", path.c_str()); + DLOG_F(INFO, "Directory created: {}", path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to create directory %s: %s", path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to create directory {}: {}", path, ex.what()); } return false; } @@ -74,12 +74,12 @@ namespace Lithium::File try { fs::remove_all(path); - DLOG_F(INFO, "Directory removed: %s", path.c_str()); + DLOG_F(INFO, "Directory removed: {}", path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to remove directory %s: %s", path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to remove directory {}: {}", path, ex.what()); } return false; } @@ -89,12 +89,12 @@ namespace Lithium::File try { fs::rename(old_path, new_path); - DLOG_F(INFO, "Directory renamed from %s to %s", old_path.c_str(), new_path.c_str()); + DLOG_F(INFO, "Directory renamed from {} to {}", old_path, new_path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to rename directory from %s to %s: %s", old_path.c_str(), new_path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to rename directory from {} to {}: {}", old_path, new_path, ex.what()); } return false; } @@ -104,12 +104,12 @@ namespace Lithium::File try { fs::rename(old_path, new_path); - DLOG_F(INFO, "Directory moved from %s to %s", old_path.c_str(), new_path.c_str()); + DLOG_F(INFO, "Directory moved from {} to {}", old_path, new_path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to move directory from %s to %s: %s", old_path.c_str(), new_path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to move directory from {} to {}: {}", old_path, new_path, ex.what()); } return false; } @@ -119,12 +119,12 @@ namespace Lithium::File try { fs::copy_file(src_path, dst_path); - DLOG_F(INFO, "File copied from %s to %s", src_path.c_str(), dst_path.c_str()); + DLOG_F(INFO, "File copied from {} to {}", src_path, dst_path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to copy file from %s to %s: %s", src_path.c_str(), dst_path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to copy file from {} to {}: {}", src_path, dst_path, ex.what()); } return false; } @@ -134,12 +134,12 @@ namespace Lithium::File try { fs::rename(src_path, dst_path); - DLOG_F(INFO, "File moved from %s to %s", src_path.c_str(), dst_path.c_str()); + DLOG_F(INFO, "File moved from {} to {}", src_path, dst_path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to move file from %s to %s: %s", src_path.c_str(), dst_path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to move file from {} to {}: {}", src_path, dst_path, ex.what()); } return false; } @@ -149,12 +149,12 @@ namespace Lithium::File try { fs::rename(old_path, new_path); - DLOG_F(INFO, "File renamed from %s to %s", old_path.c_str(), new_path.c_str()); + DLOG_F(INFO, "File renamed from {} to {}", old_path, new_path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to rename file from %s to %s: %s", old_path.c_str(), new_path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to rename file from {} to {}: {}", old_path, new_path, ex.what()); } return false; } @@ -164,12 +164,12 @@ namespace Lithium::File try { fs::remove(path); - DLOG_F(INFO, "File removed: %s", path.c_str()); + DLOG_F(INFO, "File removed: {}", path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to remove file %s: %s", path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to remove file {}: {}", path, ex.what()); } return false; } @@ -179,12 +179,12 @@ namespace Lithium::File try { fs::create_symlink(target_path, symlink_path); - DLOG_F(INFO, "Symlink created from %s to %s", target_path.c_str(), symlink_path.c_str()); + DLOG_F(INFO, "Symlink created from {} to {}", target_path, symlink_path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to create symlink from %s to %s: %s", target_path.c_str(), symlink_path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to create symlink from {} to {}: {}", target_path, symlink_path, ex.what()); } return false; } @@ -194,12 +194,12 @@ namespace Lithium::File try { fs::remove(path); - DLOG_F(INFO, "Symlink removed: %s", path.c_str()); + DLOG_F(INFO, "Symlink removed: {}", path); return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to remove symlink %s: %s", path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to remove symlink {}: {}", path, ex.what()); } return false; } @@ -212,7 +212,7 @@ namespace Lithium::File } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to get file size of %s: %s", path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to get file size of {}: {}", path, ex.what()); return 0; } } @@ -225,17 +225,17 @@ namespace Lithium::File { if (entry.is_directory()) { - DLOG_F(INFO, "Directory: %s", entry.path().string().c_str()); + DLOG_F(INFO, "Directory: {}", entry.path().string()); } else { - DLOG_F(INFO, "File: %s", entry.path().string().c_str()); + DLOG_F(INFO, "File: {}", entry.path().string()); } } } catch (const std::exception &ex) { - DLOG_F(ERROR, "Failed to traverse directory %s: %s", path.c_str(), ex.what()); + DLOG_F(ERROR, "Failed to traverse directory {}: {}", path, ex.what()); } } diff --git a/src/modules/module/compiler.cpp b/src/modules/module/compiler.cpp index b23e52df..996a5e6f 100644 --- a/src/modules/module/compiler.cpp +++ b/src/modules/module/compiler.cpp @@ -30,14 +30,14 @@ Description: Compiler **************************************************/ #include "compiler.hpp" -#include + #include #include -#include #include #include #include +#include "nlohmann/json.hpp" #include "loguru/loguru.hpp" using json = nlohmann::json; @@ -55,182 +55,185 @@ namespace fs = std::filesystem; #define CMD_SUFFIX ".so" #endif -bool Compiler::CompileToSharedLibrary(const std::string &code, const std::string &moduleName, const std::string &functionName) +namespace Lithium { - DLOG_F(ERROR, "Compiling module %s::%s...", moduleName.c_str(), functionName.c_str()); - // 参数校验 - if (code.empty() || moduleName.empty() || functionName.empty()) + bool Compiler::CompileToSharedLibrary(const std::string &code, const std::string &moduleName, const std::string &functionName) { - DLOG_F(ERROR, "Invalid parameters."); - return false; - } + DLOG_F(INFO, "Compiling module {}::{}...", moduleName, functionName); - // Check if the module is already compiled and cached - auto cachedResult = cache_.find(moduleName + "::" + functionName); - if (cachedResult != cache_.end()) - { - DLOG_F(WARNING, "Module %s::%s is already compiled, returning cached result.", moduleName.c_str(), functionName.c_str()); - return true; - } + // 参数校验 + if (code.empty() || moduleName.empty() || functionName.empty()) + { + DLOG_F(ERROR, "Invalid parameters."); + return false; + } - // Create output directory if it does not exist - const std::string outputDir = "modules/global/"; - if (!fs::exists(outputDir)) - { - DLOG_F(WARNING, "Output directory does not exist, creating it: %s", outputDir.c_str()); - try + // Check if the module is already compiled and cached + auto cachedResult = cache_.find(moduleName + "::" + functionName); + if (cachedResult != cache_.end()) { - fs::create_directories(outputDir); + DLOG_F(WARNING, "Module {}::{} is already compiled, returning cached result.", moduleName, functionName); + return true; } - catch (const std::exception &e) + + // Create output directory if it does not exist + const std::string outputDir = "modules/global/"; + if (!fs::exists(outputDir)) { - DLOG_F(ERROR, "Failed to create output directory: %s", e.what()); - return false; + DLOG_F(WARNING, "Output directory does not exist, creating it: {}", outputDir); + try + { + fs::create_directories(outputDir); + } + catch (const std::exception &e) + { + DLOG_F(ERROR, "Failed to create output directory: {}", e.what()); + return false; + } } - } - // Read compile options from JSON file - std::string compileOptions = "-shared -fPIC -x c++ "; - std::ifstream compileOptionFile("compile_options.json"); - if (compileOptionFile.is_open()) - { - json compileOptionsJson; - try + // Read compile options from JSON file + std::string compileOptions = "-shared -fPIC -x c++ "; + std::ifstream compileOptionFile("compile_options.json"); + if (compileOptionFile.is_open()) { - compileOptionFile >> compileOptionsJson; - if (compileOptionsJson.contains("optimization_level") && compileOptionsJson.contains("cplus_version") && compileOptionsJson.contains("warnings")) + json compileOptionsJson; + try { - compileOptions = compileOptionsJson["optimization_level"].get() + " " + - compileOptionsJson["cplus_version"].get() + " " + - compileOptionsJson["warnings"].get() + " "; + compileOptionFile >> compileOptionsJson; + if (compileOptionsJson.contains("optimization_level") && compileOptionsJson.contains("cplus_version") && compileOptionsJson.contains("warnings")) + { + compileOptions = compileOptionsJson["optimization_level"].get() + " " + + compileOptionsJson["cplus_version"].get() + " " + + compileOptionsJson["warnings"].get() + " "; + } + else + { + DLOG_F(ERROR, "Invalid format in compile_options.json."); + return false; + } } - else + catch (const std::exception &e) { - DLOG_F(ERROR, "Invalid format in compile_options.json."); + DLOG_F(ERROR, "Error reading compile_options.json: {}", e.what()); return false; } } - catch (const std::exception &e) + + // Specify output file path + std::string output = outputDir + moduleName + CMD_SUFFIX; + + // Syntax and semantic checking + std::stringstream syntaxCheckCmd; + syntaxCheckCmd << COMPILER << " -fsyntax-only -x c++ -"; + std::string syntaxCheckOutput; + if (RunShellCommand(syntaxCheckCmd.str(), code, syntaxCheckOutput) != 0) { - DLOG_F(ERROR, "Error reading compile_options.json: %s", e.what()); + DLOG_F(ERROR, "Syntax error in C++ code: {}", syntaxCheckOutput); return false; } - } - // Specify output file path - std::string output = outputDir + moduleName + CMD_SUFFIX; + // Compile code + std::string compilationOutput; + std::string cmd = std::string(COMPILER) + " " + compileOptions + " - " + " -o " + output; + DLOG_F(INFO, "{}", cmd); - // Syntax and semantic checking - std::stringstream syntaxCheckCmd; - syntaxCheckCmd << COMPILER << " -fsyntax-only -x c++ -"; - std::string syntaxCheckOutput; - if (RunShellCommand(syntaxCheckCmd.str(), code, syntaxCheckOutput) != 0) - { - DLOG_F(ERROR, "Syntax error in C++ code: %s", syntaxCheckOutput.c_str()); - return false; - } + int exitCode = RunShellCommand(cmd, code, compilationOutput); + if (exitCode != 0) + { + DLOG_F(ERROR, "Failed to compile C++ code: {}", compilationOutput); + return false; + } - // Compile code - std::string compilationOutput; - std::string cmd = std::string(COMPILER) + " " + compileOptions + " - " + " -o " + output; - DLOG_F(INFO, "%s", cmd.c_str()); + // Cache compiled module + cache_[moduleName + "::" + functionName] = output; - int exitCode = RunShellCommand(cmd, code, compilationOutput); - if (exitCode != 0) - { - DLOG_F(ERROR, "Failed to compile C++ code: %s", compilationOutput.c_str()); + /* + // Load the compiled module + if(m_App.GetModuleLoader()->LoadModule(output, moduleName)) { + LOG_S(INFO) << "Module " << moduleName << "::" << functionName << " compiled successfully."; + return true; + } else { + DLOG_F(ERROR, "Failed to load the compiled module: {}", output); + return false; + } + */ return false; } - // Cache compiled module - cache_[moduleName + "::" + functionName] = output; + bool Compiler::CopyFile_(const std::string &source, const std::string &destination) + { + std::ifstream src(source, std::ios::binary); + if (!src) + { + // spdlog::error("Failed to open file for copy: {}", source); + return false; + } - /* - // Load the compiled module - if(m_App.GetModuleLoader()->LoadModule(output, moduleName)) { - LOG_S(INFO) << "Module " << moduleName << "::" << functionName << " compiled successfully."; - return true; - } else { - DLOG_F(ERROR, "Failed to load the compiled module: %s", output.c_str()); - return false; - } - */ - return false; -} + std::ofstream dst(destination, std::ios::binary); + if (!dst) + { + // spdlog::error("Failed to create file for copy: {}", destination); + return false; + } -bool Compiler::CopyFile_(const std::string &source, const std::string &destination) -{ - std::ifstream src(source, std::ios::binary); - if (!src) - { - // spdlog::error("Failed to open file for copy: {}", source); - return false; + dst << src.rdbuf(); + return true; } - std::ofstream dst(destination, std::ios::binary); - if (!dst) + int Compiler::RunShellCommand(const std::string &command, const std::string &input, std::string &output) { - // spdlog::error("Failed to create file for copy: {}", destination); - return false; - } - - dst << src.rdbuf(); - return true; -} - -int Compiler::RunShellCommand(const std::string &command, const std::string &input, std::string &output) -{ - int exitCode = -1; + int exitCode = -1; #ifdef _WIN32 - HANDLE hStdoutRead; - - STARTUPINFO si = {sizeof(si)}; - PROCESS_INFORMATION pi; - HANDLE hStdinRead, hStdoutWrite; - SECURITY_ATTRIBUTES sa; - sa.nLength = sizeof(sa); - sa.lpSecurityDescriptor = NULL; - sa.bInheritHandle = TRUE; - if (!CreatePipe(&hStdinRead, &hStdoutWrite, &sa, 0)) - { - DLOG_F(ERROR, "Failed to create input pipe for shell command: %s", command.c_str()); - return exitCode; - } - if (!SetHandleInformation(hStdoutWrite, HANDLE_FLAG_INHERIT, 0)) - { - DLOG_F(ERROR, "Failed to set input handle information for shell command: %s", command.c_str()); - return exitCode; - } - if (!SetHandleInformation(hStdoutRead, HANDLE_FLAG_INHERIT, 0)) - { - DLOG_F(ERROR, "Failed to set output handle information for shell command: %s", command.c_str()); - return exitCode; - } - si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; - si.wShowWindow = SW_HIDE; - si.hStdInput = hStdinRead; - si.hStdOutput = hStdoutWrite; - si.hStdError = hStdoutWrite; + HANDLE hStdoutRead; + + STARTUPINFO si = {sizeof(si)}; + PROCESS_INFORMATION pi; + HANDLE hStdinRead, hStdoutWrite; + SECURITY_ATTRIBUTES sa; + sa.nLength = sizeof(sa); + sa.lpSecurityDescriptor = NULL; + sa.bInheritHandle = TRUE; + if (!CreatePipe(&hStdinRead, &hStdoutWrite, &sa, 0)) + { + DLOG_F(ERROR, "Failed to create input pipe for shell command: {}", command); + return exitCode; + } + if (!SetHandleInformation(hStdoutWrite, HANDLE_FLAG_INHERIT, 0)) + { + DLOG_F(ERROR, "Failed to set input handle information for shell command: {}", command); + return exitCode; + } + if (!SetHandleInformation(hStdoutRead, HANDLE_FLAG_INHERIT, 0)) + { + DLOG_F(ERROR, "Failed to set output handle information for shell command: {}", command); + return exitCode; + } + si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; + si.wShowWindow = SW_HIDE; + si.hStdInput = hStdinRead; + si.hStdOutput = hStdoutWrite; + si.hStdError = hStdoutWrite; - std::vector commandBuffer(command.begin(), command.end()); - commandBuffer.push_back('\0'); + std::vector commandBuffer(command.begin(), command.end()); + commandBuffer.push_back('\0'); - if (!CreateProcess(NULL, &commandBuffer[0], NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) - { - DLOG_F(ERROR, "Failed to launch shell command: %s", command.c_str()); + if (!CreateProcess(NULL, &commandBuffer[0], NULL, NULL, TRUE, 0, NULL, NULL, &si, &pi)) + { + DLOG_F(ERROR, "Failed to launch shell command: {}", command); + CloseHandle(hStdinRead); + CloseHandle(hStdoutWrite); + CloseHandle(hStdoutRead); + CloseHandle(hStdoutWrite); + return exitCode; + } CloseHandle(hStdinRead); CloseHandle(hStdoutWrite); - CloseHandle(hStdoutRead); - CloseHandle(hStdoutWrite); - return exitCode; - } - CloseHandle(hStdinRead); - CloseHandle(hStdoutWrite); - // Read the command output - std::thread outputThread([&]() - { + // Read the command output + std::thread outputThread([&]() + { char buffer[4096]; DWORD bytesRead; while (ReadFile(hStdoutRead, buffer, sizeof(buffer), &bytesRead, NULL)) @@ -238,38 +241,39 @@ int Compiler::RunShellCommand(const std::string &command, const std::string &inp output.append(buffer, bytesRead); } }); - // Write the command input - DWORD bytesWritten; - if (!WriteFile(hStdoutWrite, input.c_str(), input.size(), &bytesWritten, NULL)) - { - DLOG_F(ERROR, "Failed to write input for shell command: %s", command.c_str()); - return exitCode; - } - CloseHandle(hStdoutWrite); + // Write the command input + DWORD bytesWritten; + if (!WriteFile(hStdoutWrite, input, input.size(), &bytesWritten, NULL)) + { + DLOG_F(ERROR, "Failed to write input for shell command: {}", command); + return exitCode; + } + CloseHandle(hStdoutWrite); - // Wait for the command to finish - WaitForSingleObject(pi.hProcess, INFINITE); - GetExitCodeProcess(pi.hProcess, (LPDWORD)&exitCode); + // Wait for the command to finish + WaitForSingleObject(pi.hProcess, INFINITE); + GetExitCodeProcess(pi.hProcess, (LPDWORD)&exitCode); - // Clean up - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - CloseHandle(hStdoutRead); - outputThread.join(); + // Clean up + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + CloseHandle(hStdoutRead); + outputThread.join(); #else - FILE *pipe = popen(command.c_str(), "w"); - if (!pipe) - { - DLOG_F(ERROR, "Failed to popen shell command: %s", command.c_str()); - return exitCode; - } + FILE *pipe = popen(command.c_str(), "w"); + if (!pipe) + { + DLOG_F(ERROR, "Failed to popen shell command: {}", command); + return exitCode; + } - fwrite(input.c_str(), 1, input.size(), pipe); - fclose(pipe); + fwrite(input.c_str(), 1, input.size(), pipe); + fclose(pipe); - exitCode = WEXITSTATUS(pclose(pipe)); + exitCode = WEXITSTATUS(pclose(pipe)); #endif - return exitCode; -} \ No newline at end of file + return exitCode; + } +} diff --git a/src/modules/module/compiler.hpp b/src/modules/module/compiler.hpp index 9e8083ce..796a520b 100644 --- a/src/modules/module/compiler.hpp +++ b/src/modules/module/compiler.hpp @@ -32,40 +32,54 @@ Description: Compiler #pragma once #include + +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif -class Compiler +namespace Lithium { -public: - /** - * \brief 编译 C++ 代码为共享库,并加载到内存中 - * - * \param code 要编译的代码 - * \param moduleName 模块名 - * \param functionName 入口函数名 - * \return 编译是否成功 - */ - bool CompileToSharedLibrary(const std::string &code, const std::string &moduleName, const std::string &functionName); - -private: - /** - * \brief 复制文件 - * - * \param source 源文件路径 - * \param destination 目标文件路径 - * \return 是否复制成功 - */ - bool CopyFile_(const std::string &source, const std::string &destination); - - /** - * \brief 运行外部 shell 命令,并将标准输入输出流转发到命令的标准输入输出流中 - * - * \param command 要运行的命令 - * \param inputStream 标准输入流 - * \param outputStream 标准输出流 - * \return 命令运行的返回值 - */ - int RunShellCommand(const std::string &command, const std::string &input, std::string &output); - - std::unordered_map cache_; -}; + + class Compiler + { + public: + /** + * \brief 编译 C++ 代码为共享库,并加载到内存中 + * + * \param code 要编译的代码 + * \param moduleName 模块名 + * \param functionName 入口函数名 + * \return 编译是否成功 + */ + bool CompileToSharedLibrary(const std::string &code, const std::string &moduleName, const std::string &functionName); + + private: + /** + * \brief 复制文件 + * + * \param source 源文件路径 + * \param destination 目标文件路径 + * \return 是否复制成功 + */ + bool CopyFile_(const std::string &source, const std::string &destination); + + /** + * \brief 运行外部 shell 命令,并将标准输入输出流转发到命令的标准输入输出流中 + * + * \param command 要运行的命令 + * \param inputStream 标准输入流 + * \param outputStream 标准输出流 + * \return 命令运行的返回值 + */ + int RunShellCommand(const std::string &command, const std::string &input, std::string &output); + +#if ENABLE_FASTHASH + emhash8::HashMap cache_; +#else + std::unordered_map cache_; +#endif + }; + +} diff --git a/src/modules/module/modloader.cpp b/src/modules/module/modloader.cpp index cebf0be5..aa3e1adf 100644 --- a/src/modules/module/modloader.cpp +++ b/src/modules/module/modloader.cpp @@ -39,7 +39,7 @@ Description: C++ and Modules Loader #include #include -#include +#include "thread/thread.hpp" namespace fs = std::filesystem; @@ -64,7 +64,7 @@ namespace Lithium * @return json - A JSON object containing the configuration information or an error message. * 包含配置信息或错误消息的JSON对象。 */ - nlohmann::json read_config_file(const std::string &file_path) + json read_config_file(const std::string &file_path) { try { @@ -72,12 +72,12 @@ namespace Lithium std::ifstream file_stream(file_path); if (!file_stream.is_open()) { - DLOG_F(ERROR, "Failed to open config file %s", file_path.c_str()); + DLOG_F(ERROR, "Failed to open config file {}", file_path); return {{"error", "Failed to open config file"}}; } // Read the configuration file content into a JSON object - nlohmann::json config = nlohmann::json::parse(file_stream); + json config = json::parse(file_stream); // Close the file stream file_stream.close(); @@ -85,12 +85,12 @@ namespace Lithium } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to read config file %s: %s", file_path.c_str(), e.what()); + DLOG_F(ERROR, "Failed to read config file {}: {}", file_path, e.what()); return {{"error", "Failed to read config file"}}; } } - nlohmann::json iterator_modules_dir(const std::string &dir_name) + json iterator_modules_dir(const std::string &dir_name) { if (dir_name == "") { @@ -111,12 +111,12 @@ namespace Lithium } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to create modules directory: %s", e.what()); + DLOG_F(ERROR, "Failed to create modules directory: {}", e.what()); return {{"error", "Failed to create modules directory"}}; } // Create a JSON object to store module information - nlohmann::json config; + json config; try { @@ -135,21 +135,21 @@ namespace Lithium config[dir.path().string()]["path"] = dir.path().string(); config[dir.path().string()]["config"] = info_file.string(); // Read the module configuration from the info.json file and append to the JSON object - nlohmann::json module_config = read_config_file(info_file.string()); + json module_config = read_config_file(info_file.string()); config[dir.path().string()]["name"] = module_config["name"]; config[dir.path().string()]["version"] = module_config["version"]; config[dir.path().string()]["author"] = module_config["author"]; config[dir.path().string()]["license"] = module_config.value("license", ""); config[dir.path().string()]["description"] = module_config.value("description", ""); // Debug message - DLOG_F(INFO, "Module found: %s, config file: %s", dir.path().string().c_str(), info_file.string().c_str()); + DLOG_F(INFO, "Module found: {}, config file: {}", dir.path().string(), info_file.string()); } } } } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to iterate modules directory: %s", e.what()); + DLOG_F(ERROR, "Failed to iterate modules directory: {}", e.what()); return {{"error", "Failed to iterate modules directory"}}; } if (config.empty()) @@ -268,8 +268,8 @@ namespace Lithium DLOG_F(ERROR, "Directory name is empty"); return false; } - const nlohmann::json dir_info = iterator_modules_dir(dir_name); - DLOG_F(INFO, "%s", dir_info.dump(4).c_str()); + const json dir_info = iterator_modules_dir(dir_name); + DLOG_F(INFO, "{}", dir_info.dump(4)); if (!dir_info.empty()) { if (dir_info["message"].get() != "No module found") @@ -295,7 +295,7 @@ namespace Lithium // Check if the library file exists if (!std::filesystem::exists(path)) { - DLOG_F(ERROR, "Library %s does not exist", path.c_str()); + DLOG_F(ERROR, "Library {} does not exist", path); return false; } @@ -303,7 +303,7 @@ namespace Lithium void *handle = LOAD_LIBRARY(path.c_str()); if (!handle) { - DLOG_F(ERROR, "Failed to load library %s: %s", path.c_str(), LOAD_ERROR()); + DLOG_F(ERROR, "Failed to load library {}: {}", path, LOAD_ERROR()); return false; } @@ -312,7 +312,7 @@ namespace Lithium std::string config_file_path = p.replace_extension(".json").string(); if (std::filesystem::exists(config_file_path)) { - nlohmann::json config; + json config; std::ifstream config_file(config_file_path); config_file >> config; @@ -323,17 +323,17 @@ namespace Lithium std::string author = config["author"].get(); std::string license = config.value("license", ""); - DLOG_F(INFO, "Loaded Module : %s version %s written by %s%s", - config.value("name", "Unknown").c_str(), version.c_str(), author.c_str(), license.empty() ? "" : (" under " + license).c_str()); + DLOG_F(INFO, "Loaded Module : {} version {} written by {}{}", + config.value("name", "Unknown"), version, author, license.empty() ? "" : (" under " + license)); } else { - DLOG_F(WARNING, "Missing required fields in %s", config_file_path.c_str()); + DLOG_F(WARNING, "Missing required fields in {}", config_file_path); } } else { - DLOG_F(WARNING, "Config file %s does not exist", config_file_path.c_str()); + DLOG_F(WARNING, "Config file {} does not exist", config_file_path); } // Store the library handle in handles_ map with the module name as key @@ -342,7 +342,7 @@ namespace Lithium } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to load library %s: %s", path.c_str(), e.what()); + DLOG_F(ERROR, "Failed to load library {}: {}", path, e.what()); return false; } } @@ -355,13 +355,13 @@ namespace Lithium auto it = handles_.find(filename); if (it == handles_.end()) { - DLOG_F(ERROR, "Module %s is not loaded", filename.c_str()); + DLOG_F(ERROR, "Module {} is not loaded", filename); return false; } if (!it->second) { - DLOG_F(ERROR, "Module %s's handle is null", filename.c_str()); + DLOG_F(ERROR, "Module {}'s handle is null", filename); return false; } @@ -369,19 +369,19 @@ namespace Lithium int result = UNLOAD_LIBRARY(it->second); if (result == 0) { - DLOG_F(INFO, "Unloaded module : %s", filename.c_str()); + DLOG_F(INFO, "Unloaded module : {}", filename); handles_.erase(it); return true; } else { - DLOG_F(ERROR, "Failed to unload module %s", filename.c_str()); + DLOG_F(ERROR, "Failed to unload module {}", filename); return false; } } catch (const std::exception &e) { - DLOG_F(ERROR, "%s", e.what()); + DLOG_F(ERROR, "{}", e.what()); return false; } } @@ -391,14 +391,24 @@ namespace Lithium void *handle = LOAD_LIBRARY(name.c_str()); if (handle == nullptr) { - DLOG_F(ERROR, "Module %s does not exist.", name.c_str()); + DLOG_F(ERROR, "Module {} does not exist.", name); return false; } - DLOG_F(INFO, "Module %s is existing.", name.c_str()); + DLOG_F(INFO, "Module {} is existing.", name); UNLOAD_LIBRARY(handle); return true; } + void *ModuleLoader::GetHandle(const std::string &name) const + { + auto it = handles_.find(name); + if (it == handles_.end()) + { + return nullptr; + } + return it->second; + } + bool ModuleLoader::HasModule(const std::string &name) const { return handles_.count(name) > 0; @@ -426,7 +436,7 @@ namespace Lithium } else { - DLOG_F(ERROR, "Enabled file not found for module %s", module_name.c_str()); + DLOG_F(ERROR, "Enabled file not found for module {}", module_name); return false; } } @@ -442,7 +452,7 @@ namespace Lithium std::string module_path = GetModulePath(module_name); if (module_path.empty()) { - DLOG_F(ERROR, "Module path not found for module %s", module_name.c_str()); + DLOG_F(ERROR, "Module path not found for module {}", module_name); return false; } std::string disabled_file = module_path + ".disabled"; @@ -454,7 +464,7 @@ namespace Lithium } else { - DLOG_F(ERROR, "Failed to disable module %s", module_name.c_str()); + DLOG_F(ERROR, "Failed to disable module {}", module_name); return false; } } diff --git a/src/modules/module/modloader.hpp b/src/modules/module/modloader.hpp index 3a815eea..43f44906 100644 --- a/src/modules/module/modloader.hpp +++ b/src/modules/module/modloader.hpp @@ -32,9 +32,13 @@ Description: C++ and Modules Loader #pragma once #include -#include #include #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else +#include +#endif /* #ifdef _WIN32 @@ -60,14 +64,18 @@ Description: C++ and Modules Loader #endif */ -#include "nlohmann/json_fwd.hpp" +#include "nlohmann/json.hpp" #include "loguru/loguru.hpp" - -#include "thread/thread.hpp" #include "error/error_code.hpp" +using json = nlohmann::json; + namespace Lithium { + namespace Thread + { + class ThreadManager; + } /** * @brief Traverse the "modules" directory and create a JSON object containing the information of all modules. @@ -85,24 +93,81 @@ namespace Lithium * @return json - A JSON object containing the module information or an error message. * 包含模块信息或错误消息的JSON对象。 */ - nlohmann::json iterator_modules_dir(const std::string &dir_name); + json iterator_modules_dir(const std::string &dir_name); class ModuleLoader { public: + /** + * @brief 默认构造函数,创建一个空的 ModuleLoader 对象。 + */ ModuleLoader(); + + /** + * @brief 使用给定的目录名称参数构造 ModuleLoader 对象。 + * + * @param dir_name 模块所在的目录名称。 + */ ModuleLoader(const std::string &dir_name); + + /** + * @brief 使用给定的线程管理器参数构造 ModuleLoader 对象。 + * + * @param threadManager 线程管理器的共享指针。 + */ ModuleLoader(std::shared_ptr threadManager); + + /** + * @brief 使用给定的目录名称和线程管理器参数构造 ModuleLoader 对象。 + * + * @param dir_name 模块所在的目录名称。 + * @param threadManager 线程管理器的共享指针。 + */ ModuleLoader(const std::string &dir_name, std::shared_ptr threadManager); + /** + * @brief 析构函数,释放 ModuleLoader 对象。 + */ ~ModuleLoader(); - public: + /** + * @brief 创建一个共享的 ModuleLoader 指针对象。 + * + * @return 新创建的共享 ModuleLoader 指针对象。 + */ static std::shared_ptr createShared(); + + /** + * @brief 使用给定的目录名称参数创建一个共享的 ModuleLoader 指针对象。 + * + * @param dir_name 模块所在的目录名称。 + * @return 新创建的共享 ModuleLoader 指针对象。 + */ static std::shared_ptr createShared(const std::string &dir_name); + + /** + * @brief 使用给定的线程管理器参数创建一个共享的 ModuleLoader 指针对象。 + * + * @param threadManager 线程管理器的共享指针。 + * @return 新创建的共享 ModuleLoader 指针对象。 + */ static std::shared_ptr createShared(std::shared_ptr threadManager); + + /** + * @brief 使用给定的目录名称和线程管理器参数创建一个共享的 ModuleLoader 指针对象。 + * + * @param dir_name 模块所在的目录名称。 + * @param threadManager 线程管理器的共享指针。 + * @return 新创建的共享 ModuleLoader 指针对象。 + */ static std::shared_ptr createShared(const std::string &dir_name, std::shared_ptr threadManager); + /** + * @brief 根据给定的目录名称加载模块。 + * + * @param dir_name 模块所在的目录名称。 + * @return 如果成功加载则返回 true,否则返回 false。 + */ bool LoadOnInit(const std::string &dir_name); /** @@ -116,7 +181,7 @@ namespace Lithium * @return true if the loading is successful, false otherwise. */ bool LoadModule(const std::string &path, const std::string &name); - + /** * @brief 卸载指定名称的动态库 * @@ -187,7 +252,7 @@ namespace Lithium * @return std::shared_ptr 返回实例对象的智能指针,如果获取失败则返回nullptr */ template - std::shared_ptr GetInstance(const std::string &module_name, const nlohmann::json &config, + std::shared_ptr GetInstance(const std::string &module_name, const json &config, const std::string &symbol_name) { auto handle_it = handles_.find(module_name); @@ -197,7 +262,7 @@ namespace Lithium return nullptr; } - auto get_instance_func = GetFunction (*)(const nlohmann::json &)>(module_name, symbol_name); + auto get_instance_func = GetFunction (*)(const json &)>(module_name, symbol_name); if (!get_instance_func) { DLOG_F(ERROR, "Failed to get symbol %s from module %s: %s", symbol_name.c_str(), module_name.c_str(), dlerror()); @@ -220,29 +285,44 @@ namespace Lithium * std::shared_ptr plugin = GetInstancePointer(module_name, config, "GetPluginInstance"); */ template - std::shared_ptr GetInstancePointer(const std::string &module_name, const nlohmann::json &config, const std::string &instance_function_name) + std::shared_ptr GetInstancePointer(const std::string &module_name, const json &config, const std::string &instance_function_name) { return GetInstance(module_name, config, instance_function_name); } public: - void *GetHandle(const std::string &name) const - { - auto it = handles_.find(name); - if (it == handles_.end()) - { - return nullptr; - } - return it->second; - } + /** + * @brief 获取给定名称的句柄。 + * + * @param name 句柄名称。 + * @return 对应名称的句柄指针,如果未找到则返回空指针。 + */ + void *GetHandle(const std::string &name) const; - std::string GetModulePath(const std::string& module_name); + /** + * @brief 获取给定模块名称的模块路径。 + * + * @param module_name 模块名称。 + * @return 对应模块名称的模块路径。 + */ + std::string GetModulePath(const std::string &module_name); + /** + * @brief 获取所有存在的模块名称。 + * + * @return 存在的模块名称的向量。 + */ const std::vector GetAllExistedModules() const; private: +#if ENABLE_FASTHASH + emhash8::HashMap handles_; + emhash8::HashMap disabled_modules_; +#else std::unordered_map handles_; - std::shared_ptr m_ThreadManager; std::unordered_map disabled_modules_; +#endif + + std::shared_ptr m_ThreadManager; }; } \ No newline at end of file diff --git a/src/modules/plugin/exe_plugin.hpp b/src/modules/plugin/exe_plugin.hpp index 783e9704..c6f5d64a 100644 --- a/src/modules/plugin/exe_plugin.hpp +++ b/src/modules/plugin/exe_plugin.hpp @@ -29,8 +29,7 @@ Description: Executable Plugin **************************************************/ -#ifndef EXECUTABLE_PLUGIN_H -#define EXECUTABLE_PLUGIN_H +#pragma once #include "plugin.hpp" @@ -45,5 +44,3 @@ class ExecutablePlugin : public Plugin private: std::shared_ptr m_ProcessManager; }; - -#endif diff --git a/src/modules/plugin/plugin_manager.cpp b/src/modules/plugin/plugin_manager.cpp index 37695335..ef474db0 100644 --- a/src/modules/plugin/plugin_manager.cpp +++ b/src/modules/plugin/plugin_manager.cpp @@ -34,6 +34,8 @@ Description: Plugin Manager #include "exe_plugin.hpp" #include "script_plugin.hpp" +#include "modules/system/process.hpp" + #include "loguru/loguru.hpp" namespace Lithium diff --git a/src/modules/plugin/plugin_manager.hpp b/src/modules/plugin/plugin_manager.hpp index fa297ad7..e2e781a5 100644 --- a/src/modules/plugin/plugin_manager.hpp +++ b/src/modules/plugin/plugin_manager.hpp @@ -31,19 +31,27 @@ Description: Plugin Manager #pragma once -#include #include #include #include #include #include -#include "plugin.hpp" +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else +#include +#endif -#include "modules/system/process.hpp" +#include "plugin.hpp" namespace Lithium { + namespace Process + { + class ProcessManager; + } // namespace Process + /** * @class PluginManager * @brief 插件管理器类,用于加载、卸载和运行插件 @@ -98,8 +106,13 @@ namespace Lithium void GetPluginInfo(const std::string &pluginName) const; private: - mutable std::mutex mutex_; ///< 互斥锁,用于保护plugins_的访问 - std::map> plugins_; ///< 已加载的插件容器,以插件名称为键值存储 + mutable std::mutex mutex_; ///< 互斥锁,用于保护plugins_的访问 +#if ENABLE_FASTHASH + emhash8::HashMap> plugins_; +#else + std::unordered_map> plugins_; ///< 已加载的插件容器,以插件名称为键值存储 +#endif + std::string GetPluginType(const std::shared_ptr &plugin) const; ///< 获取插件类型的辅助函数 std::shared_ptr m_ProcessManager; diff --git a/src/modules/plugin/script_plugin.hpp b/src/modules/plugin/script_plugin.hpp index 503722e0..7f0b8ef4 100644 --- a/src/modules/plugin/script_plugin.hpp +++ b/src/modules/plugin/script_plugin.hpp @@ -29,8 +29,7 @@ Description: Script Plugin **************************************************/ -#ifndef SCRIPT_PLUGIN_H -#define SCRIPT_PLUGIN_H +#pragma once #include "plugin.hpp" @@ -45,5 +44,3 @@ class ScriptPlugin : public Plugin private: std::shared_ptr m_ProcessManager; }; - -#endif diff --git a/src/modules/script/script_manager.cpp b/src/modules/script/script_manager.cpp index a7a89a22..1bb98065 100644 --- a/src/modules/script/script_manager.cpp +++ b/src/modules/script/script_manager.cpp @@ -172,7 +172,7 @@ namespace Lithium } else { - DLOG_F(ERROR, "Failed to open script file: %s", filename.c_str()); + DLOG_F(ERROR, "Failed to open script file: {}", filename); return false; } return true; @@ -186,7 +186,7 @@ namespace Lithium } catch (chaiscript::exception::eval_error &e) { - DLOG_F(ERROR, "Failed to eval %s : %s", e.filename.c_str(), e.what()); + DLOG_F(ERROR, "Failed to eval {} : {}", e.filename, e.what()); return false; }; return true; @@ -200,7 +200,7 @@ namespace Lithium } catch (chaiscript::exception::eval_error &e) { - DLOG_F(ERROR, "Failed to run %s : %s", e.filename.c_str(), e.what()); + DLOG_F(ERROR, "Failed to run {} : {}", e.filename, e.what()); return false; } return true; @@ -216,7 +216,7 @@ namespace Lithium } catch (chaiscript::exception::eval_error &e) { - DLOG_F(ERROR, "Failed to run: %s", e.what()); + DLOG_F(ERROR, "Failed to run: {}", e.what()); return false; } } diff --git a/src/modules/search/ongc.cpp b/src/modules/search/ongc.cpp index c0594377..cd8ff4c3 100644 --- a/src/modules/search/ongc.cpp +++ b/src/modules/search/ongc.cpp @@ -34,9 +34,13 @@ Description: C++ Version of PyOngc #include #include #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include -#include +#include "nlohmann/json.hpp" using json = nlohmann::json; diff --git a/src/modules/server/commander.hpp b/src/modules/server/commander.hpp index 8b0ffb4a..75e0a74d 100644 --- a/src/modules/server/commander.hpp +++ b/src/modules/server/commander.hpp @@ -32,7 +32,11 @@ Description: Commander #pragma once #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include #include "nlohmann/json.hpp" @@ -60,7 +64,7 @@ class CommandDispatcher * @param instance 处理命令的对象指针。 */ template - void RegisterHandler(const std::string &name,const json (ClassType::*handler)(const json &), ClassType *instance) + void RegisterHandler(const std::string &name, const json (ClassType::*handler)(const json &), ClassType *instance) { auto hash_value = Djb2Hash(name.c_str()); handlers_[hash_value] = std::bind(handler, instance, std::placeholders::_1); @@ -88,7 +92,11 @@ class CommandDispatcher * * 键值为哈希值,值为命令处理程序本身。 */ +#if ENABLE_FASTHASH + emhash8::HashMap handlers_; +#else std::unordered_map handlers_; +#endif /** * @brief Djb2Hash 函数是一个字符串哈希函数,用于将字符串转换成哈希值。 @@ -99,7 +107,6 @@ class CommandDispatcher static std::size_t Djb2Hash(const char *str); }; - /** * @brief 类 VCommandDispatcher 负责命令的派发和处理。 */ @@ -122,7 +129,7 @@ class VCommandDispatcher * @param instance 处理命令的对象指针。 */ template - void RegisterHandler(const std::string &name,void (ClassType::*handler)(const json &), ClassType *instance) + void RegisterHandler(const std::string &name, void (ClassType::*handler)(const json &), ClassType *instance) { auto hash_value = Djb2Hash(name.c_str()); handlers_[hash_value] = std::bind(handler, instance, std::placeholders::_1); @@ -150,7 +157,11 @@ class VCommandDispatcher * * 键值为哈希值,值为命令处理程序本身。 */ +#if ENABLE_FASTHASH + emhash8::HashMap handlers_; +#else std::unordered_map handlers_; +#endif /** * @brief Djb2Hash 函数是一个字符串哈希函数,用于将字符串转换成哈希值。 diff --git a/src/modules/server/message_bus.hpp b/src/modules/server/message_bus.hpp index 5b229913..777ed01f 100644 --- a/src/modules/server/message_bus.hpp +++ b/src/modules/server/message_bus.hpp @@ -36,7 +36,11 @@ Description: Main Message Bus #include #include #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include #include #include @@ -140,8 +144,13 @@ class MessageBus void StartProcessingThread() { std::type_index typeIndex = typeid(T); +#if __cplusplus >= 202002L processingThreads_.emplace(typeIndex, std::jthread([&]() { +#else + processingThreads_.emplace(typeIndex, std::thread([&]() + { +#endif while (isRunning_.load()) { std::pair message; bool hasMessage = false; @@ -210,7 +219,9 @@ class MessageBus auto it = processingThreads_.find(typeIndex); if (it != processingThreads_.end()) { +#if __cplusplus >= 202002L it->second.request_stop(); +#endif it->second.join(); processingThreads_.erase(it); DLOG_F(INFO, "Processing thread for type %s stopped", typeid(T).name()); @@ -223,7 +234,9 @@ class MessageBus messageAvailableFlag_.notify_one(); for (auto &thread : processingThreads_) { +#if __cplusplus >= 202002L thread.second.request_stop(); +#endif thread.second.join(); } processingThreads_.clear(); @@ -238,9 +251,18 @@ class MessageBus std::condition_variable messageAvailableFlag_; std::mutex waitingMutex_; #if __cplusplus >= 202002L +#if ENABLE_FASTHASH + emhash8::HashMap processingThreads_; +#else std::unordered_map processingThreads_; +#endif +#else +#if ENABLE_FASTHASH + emhash8::HashMap processingThreads_; #else std::unordered_map processingThreads_; +#endif + #endif std::atomic isRunning_{true}; diff --git a/src/modules/task/task_generator.cpp b/src/modules/task/task_generator.cpp index b281e403..01e96900 100644 --- a/src/modules/task/task_generator.cpp +++ b/src/modules/task/task_generator.cpp @@ -53,7 +53,7 @@ namespace Lithium { if (!fs::exists(macroFileName)) { - DLOG_F(ERROR, "Macro file not found : %s", macroFileName.c_str()); + DLOG_F(ERROR, "Macro file not found : {}", macroFileName); return false; } try @@ -64,13 +64,13 @@ namespace Lithium } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to parse file %s , error : %s", macroFileName.c_str(), e.what()); + DLOG_F(ERROR, "Failed to parse file {} , error : {}", macroFileName, e.what()); return false; } } catch (const std::exception &e) { - DLOG_F(ERROR, "Error while loading macro file: %s", e.what()); + DLOG_F(ERROR, "Error while loading macro file: {}", e.what()); return false; } @@ -83,7 +83,7 @@ namespace Lithium { if (!fs::is_directory(folderPath)) { - DLOG_F(ERROR, "Invalid folder path: %s", folderPath.c_str()); + DLOG_F(ERROR, "Invalid folder path: {}", folderPath); return false; } @@ -96,7 +96,7 @@ namespace Lithium std::ifstream file(filePath); if (!file) { - DLOG_F(ERROR, "Failed to open macro file: %s", filePath.c_str()); + DLOG_F(ERROR, "Failed to open macro file: {}", filePath); continue; } @@ -107,7 +107,7 @@ namespace Lithium } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to parse macro file: %s, error: %s", filePath.c_str(), e.what()); + DLOG_F(ERROR, "Failed to parse macro file: {}, error: {}", filePath, e.what()); continue; } @@ -123,7 +123,7 @@ namespace Lithium } else { - DLOG_F(ERROR, "Invalid macro file format: %s", filePath.c_str()); + DLOG_F(ERROR, "Invalid macro file format: {}", filePath); continue; } } @@ -131,7 +131,7 @@ namespace Lithium } catch (const std::exception &e) { - DLOG_F(ERROR, "Error while loading macros from folder: %s", e.what()); + DLOG_F(ERROR, "Error while loading macros from folder: {}", e.what()); return false; } @@ -187,14 +187,14 @@ namespace Lithium std::ifstream file(jsonFileName); if (!file) { - DLOG_F(ERROR, "Failed to open JSON file: %s", jsonFileName.c_str()); + DLOG_F(ERROR, "Failed to open JSON file: {}", jsonFileName); return false; } file >> jsonTasks; } catch (const std::exception &e) { - DLOG_F(ERROR, "Error while parsing JSON file: %s", e.what()); + DLOG_F(ERROR, "Error while parsing JSON file: {}", e.what()); return false; } @@ -208,14 +208,14 @@ namespace Lithium std::ofstream jsonFile(jsonFileName); if (!jsonFile) { - DLOG_F(ERROR, "Failed to open JSON file: %s", jsonFileName.c_str()); + DLOG_F(ERROR, "Failed to open JSON file: {}", jsonFileName); return; } jsonFile << jsonTasks.dump(4); // 使用四个空格缩进 } catch (const std::exception &e) { - DLOG_F(ERROR, "Error while saving JSON file: %s", e.what()); + DLOG_F(ERROR, "Error while saving JSON file: {}", e.what()); return; } } diff --git a/src/modules/task/task_generator.hpp b/src/modules/task/task_generator.hpp index 62450945..75bc117d 100644 --- a/src/modules/task/task_generator.hpp +++ b/src/modules/task/task_generator.hpp @@ -33,7 +33,11 @@ Description: Task Generator #define TASK_GENERATOR_ENABLE +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include #include "modules/device/device_manager.hpp" diff --git a/src/modules/task/task_manager.cpp b/src/modules/task/task_manager.cpp index a21f87e4..d6f24997 100644 --- a/src/modules/task/task_manager.cpp +++ b/src/modules/task/task_manager.cpp @@ -48,7 +48,7 @@ namespace Lithium::Task } m_TaskList.push_back(task); m_TaskMap[task->get_name()] = task; - DLOG_F(INFO, "Task added: %s", task->get_name().c_str()); + DLOG_F(INFO, "Task added: {}", task->get_name()); return true; } @@ -68,7 +68,7 @@ namespace Lithium::Task auto it = m_TaskList.begin() + position; m_TaskList.insert(it, task); - DLOG_F(INFO, "Task inserted at position %d: %s", position, task->get_name().c_str()); + DLOG_F(INFO, "Task inserted at position %d: {}", position, task->get_name()); return true; } @@ -83,7 +83,7 @@ namespace Lithium::Task { if (task->Execute()) { - DLOG_F(INFO, "Task executed: %s", task->get_name().c_str()); + DLOG_F(INFO, "Task executed: {}", task->get_name()); it = m_TaskList.erase(it); } else @@ -93,12 +93,12 @@ namespace Lithium::Task } catch (const std::exception &ex) { - DLOG_F(ERROR, "Error: Failed to execute task %s - %s", task->get_name().c_str(), ex.what()); + DLOG_F(ERROR, "Error: Failed to execute task {} - {}", task->get_name(), ex.what()); ++it; } catch (...) { - DLOG_F(ERROR, "Error: Failed to execute task %s", task->get_name().c_str()); + DLOG_F(ERROR, "Error: Failed to execute task {}", task->get_name()); ++it; } } @@ -124,21 +124,21 @@ namespace Lithium::Task { if (it->second->Execute()) { - DLOG_F(INFO, "Task executed: %s", it->second->get_name().c_str()); + DLOG_F(INFO, "Task executed: {}", it->second->get_name()); } else { - DLOG_F(ERROR, "Error: Failed to execute task %s", it->second->get_name().c_str()); + DLOG_F(ERROR, "Error: Failed to execute task {}", it->second->get_name()); } return true; } catch (const std::exception &ex) { - DLOG_F(ERROR, "Error: Failed to execute task %s - %s", it->second->get_name().c_str(), ex.what()); + DLOG_F(ERROR, "Error: Failed to execute task {} - {}", it->second->get_name(), ex.what()); } catch (...) { - DLOG_F(ERROR, "Error: Failed to execute task %s", it->second->get_name().c_str()); + DLOG_F(ERROR, "Error: Failed to execute task {}", it->second->get_name()); } } else @@ -163,7 +163,7 @@ namespace Lithium::Task } m_TaskList[index] = task; - DLOG_F(INFO, "Task modified at index %d: %s", index, task->get_name().c_str()); + DLOG_F(INFO, "Task modified at index %d: {}", index, task->get_name()); return true; } @@ -173,7 +173,7 @@ namespace Lithium::Task if (it != m_TaskMap.end() && task) { it->second = task; - DLOG_F(INFO, "Task modified : %s", task->get_name().c_str()); + DLOG_F(INFO, "Task modified : {}", task->get_name()); return true; } return false; @@ -190,7 +190,7 @@ namespace Lithium::Task auto it = m_TaskList.begin() + index; auto task = *it; m_TaskList.erase(it); - DLOG_F(INFO, "Task deleted at index %d: %s", index, task->get_name().c_str()); + DLOG_F(INFO, "Task deleted at index %d: {}", index, task->get_name()); return true; } @@ -202,7 +202,7 @@ namespace Lithium::Task auto task = it->second; m_TaskList.erase(std::remove(m_TaskList.begin(), m_TaskList.end(), task), m_TaskList.end()); m_TaskMap.erase(it); - DLOG_F(INFO, "Task deleted: %s", task->get_name().c_str()); + DLOG_F(INFO, "Task deleted: {}", task->get_name()); return true; } DLOG_F(ERROR, "Error: Task not found!"); @@ -214,7 +214,7 @@ namespace Lithium::Task auto it = findTaskByName(name); if (it != m_TaskMap.end()) { - DLOG_F(INFO, "Task found: %s", it->second->get_name().c_str()); + DLOG_F(INFO, "Task found: {}", it->second->get_name()); return true; } else @@ -253,7 +253,7 @@ namespace Lithium::Task outputFile << jsonArray.dump(4); outputFile.close(); - DLOG_F(INFO, "Tasks saved to JSON file: %s", m_FileName.c_str()); + DLOG_F(INFO, "Tasks saved to JSON file: {}", m_FileName); return true; } diff --git a/src/modules/task/task_manager.hpp b/src/modules/task/task_manager.hpp index 7909b02b..76f08e99 100644 --- a/src/modules/task/task_manager.hpp +++ b/src/modules/task/task_manager.hpp @@ -34,7 +34,11 @@ Description: Task Manager #include #include #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include #include diff --git a/src/modules/task/task_stack.cpp b/src/modules/task/task_stack.cpp index a215d1c7..77e857eb 100644 --- a/src/modules/task/task_stack.cpp +++ b/src/modules/task/task_stack.cpp @@ -52,7 +52,6 @@ namespace Lithium::Task if (exclusiveTasks.find(taskName) != exclusiveTasks.end()) { // The task being added is mutually exclusive with an existing task - std::cout << "Cannot add task '" << taskName << "'. It is mutually exclusive with task '" << existingTaskName << "'." << std::endl; canInsert = false; break; } diff --git a/src/modules/task/task_stack.hpp b/src/modules/task/task_stack.hpp index 2cafa8d9..e0e9309c 100644 --- a/src/modules/task/task_stack.hpp +++ b/src/modules/task/task_stack.hpp @@ -34,7 +34,11 @@ Description: Task Stack #include #include #include +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include #include diff --git a/src/modules/web/downloader.cpp b/src/modules/web/downloader.cpp index cedb9f8f..e11f5c4c 100644 --- a/src/modules/web/downloader.cpp +++ b/src/modules/web/downloader.cpp @@ -46,7 +46,7 @@ DownloadManager::DownloadManager(const std::string &task_file) : task_file_(task std::ifstream infile(task_file_); if (!infile) { - DLOG_F(ERROR, "Failed to open task file %s", task_file_.c_str()); + DLOG_F(ERROR, "Failed to open task file {}", task_file_); throw std::runtime_error("Failed to open task file."); } while (infile >> std::ws && !infile.eof()) @@ -62,7 +62,7 @@ DownloadManager::DownloadManager(const std::string &task_file) : task_file_(task } catch (const std::exception &e) { - DLOG_F(ERROR, "Error: %s", e.what()); + DLOG_F(ERROR, "Error: {}", e.what()); throw; } } @@ -79,7 +79,7 @@ void DownloadManager::add_task(const std::string &url, const std::string &filepa std::ofstream outfile(task_file_, std::ios_base::app); if (!outfile) { - DLOG_F(ERROR, "Failed to open task file %s", task_file_.c_str()); + DLOG_F(ERROR, "Failed to open task file {}", task_file_); throw std::runtime_error("Failed to open task file."); } outfile << url << " " << filepath << std::endl; @@ -87,7 +87,7 @@ void DownloadManager::add_task(const std::string &url, const std::string &filepa } catch (const std::exception &e) { - DLOG_F(ERROR, "Error: %s", e.what()); + DLOG_F(ERROR, "Error: {}", e.what()); throw; } tasks_.push_back({url, filepath, false, false, 0, priority}); @@ -126,7 +126,7 @@ void DownloadManager::pause_task(size_t index) } tasks_[index].paused = true; - DLOG_F(INFO, "Paused task %s - %s", tasks_[index].url.c_str(), tasks_[index].filepath.c_str()); + DLOG_F(INFO, "Paused task {} - {}", tasks_[index].url, tasks_[index].filepath); } void DownloadManager::resume_task(size_t index) @@ -142,7 +142,7 @@ void DownloadManager::resume_task(size_t index) // 如果任务未完成,则重新下载 if (!tasks_[index].completed) { - DLOG_F(INFO, "Resumed task %s - %s", tasks_[index].url.c_str(), tasks_[index].filepath.c_str()); + DLOG_F(INFO, "Resumed task {} - {}", tasks_[index].url, tasks_[index].filepath); } } @@ -210,18 +210,18 @@ void DownloadManager::run(size_t download_speed) void DownloadManager::download_task(DownloadTask &task, size_t download_speed) { - httplib::Client cli(task.url.c_str()); + httplib::Client cli(task.url); auto res = cli.Get("/"); if (!res || res->status != 200) { - DLOG_F(ERROR, "Failed to download %s", task.url.c_str()); + DLOG_F(ERROR, "Failed to download {}", task.url); return; } std::ofstream outfile(task.filepath, std::ofstream::binary | std::ofstream::app); if (!outfile) { - DLOG_F(ERROR, "Failed to open file %s", task.filepath.c_str()); + DLOG_F(ERROR, "Failed to open file {}", task.filepath); return; } @@ -277,7 +277,7 @@ void DownloadManager::download_task(DownloadTask &task, size_t download_speed) if (task.completed) { - DLOG_F(INFO, "Downloaded file %s", task.filepath.c_str()); + DLOG_F(INFO, "Downloaded file {}", task.filepath); } } @@ -288,7 +288,7 @@ void DownloadManager::save_task_list_to_file() std::ofstream outfile(task_file_); if (!outfile) { - DLOG_F(INFO, "Failed to open task file %s", task_file_.c_str()); + DLOG_F(INFO, "Failed to open task file {}", task_file_); throw std::runtime_error("Failed to open task file."); } for (const auto &task : tasks_) @@ -299,7 +299,7 @@ void DownloadManager::save_task_list_to_file() } catch (const std::exception &e) { - DLOG_F(ERROR, "Error: %s", e.what()); + DLOG_F(ERROR, "Error: {}", e.what()); throw; } } \ No newline at end of file diff --git a/src/modules/web/httpclient.cpp b/src/modules/web/httpclient.cpp index 4e21be51..4f09afee 100644 --- a/src/modules/web/httpclient.cpp +++ b/src/modules/web/httpclient.cpp @@ -44,38 +44,38 @@ using namespace httplib; HttpClient::HttpClient(const std::string &host, int port) : host_(host), port_(port), ssl_enabled_(false) { - DLOG_F(INFO, "Initializing HttpClient for %s:%d", host_.c_str(), port_); + DLOG_F(INFO, "Initializing HttpClient for {}:%d", host_, port_); } bool HttpClient::SendGetRequest(const std::string &path, const std::map ¶ms, json &response, std::string &err) { - Client client(host_.c_str(), port_); + Client client(host_, port_); if (ssl_enabled_) { client.enable_server_certificate_verification(true); - client.set_ca_cert_path(ca_cert_path_.c_str()); + client.set_ca_cert_path(ca_cert_path_); if (!client_cert_path_.empty() && !client_key_path_.empty()) { - // client.set_client_cert_and_key(client_cert_path_.c_str(), client_key_path_.c_str()); + // client.set_client_cert_and_key(client_cert_path_, client_key_path_); } } - auto res = client.Get(path.c_str()); + auto res = client.Get(path); if (!res || res->status != 200) { err = res ? res->body : "Unknown error"; - DLOG_F(ERROR, "Failed to send GET request to %s%s. Error message: %s", host_.c_str(), path.c_str(), err.c_str()); + DLOG_F(ERROR, "Failed to send GET request to {}{}. Error message: {}", host_, path, err); return false; } try { response = json::parse(res->body); - DLOG_F(INFO, "Received response from %s%s: %s", host_.c_str(), path.c_str(), response.dump().c_str()); + DLOG_F(INFO, "Received response from {}{}: {}", host_, path, response.dump()); } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to parse response from %s%s. Error message: %s", host_.c_str(), path.c_str(), e.what()); + DLOG_F(ERROR, "Failed to parse response from {}{}. Error message: {}", host_, path, e.what()); return false; } @@ -84,33 +84,33 @@ bool HttpClient::SendGetRequest(const std::string &path, const std::map ¶ms, const json &data, json &response, std::string &err) { - Client client(host_.c_str(), port_); + Client client(host_, port_); if (ssl_enabled_) { // client.enable_server_certificate_verification(true); - client.set_ca_cert_path(ca_cert_path_.c_str()); + client.set_ca_cert_path(ca_cert_path_); if (!client_cert_path_.empty() && !client_key_path_.empty()) { - // client.set_client_cert_and_key(client_cert_path_.c_str(), client_key_path_.c_str()); + // client.set_client_cert_and_key(client_cert_path_, client_key_path_); } } - auto res = client.Post(path.c_str()); + auto res = client.Post(path); if (!res || res->status != 200) { err = res ? res->body : "Unknown error"; - DLOG_F(ERROR, "Failed to send POST request to %s%s, data %s. Error message: %s", host_.c_str(), path.c_str(), data.dump().c_str(), err.c_str()); + DLOG_F(ERROR, "Failed to send POST request to {}{}, data {}. Error message: {}", host_, path, data.dump(), err); return false; } try { response = json::parse(res->body); - DLOG_F(INFO, "Received response from %s%s: %s", host_.c_str(), path.c_str(), response.dump().c_str()); + DLOG_F(INFO, "Received response from {}{}: {}", host_, path, response.dump()); } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to parse response from %s%s. Error message: %s", host_.c_str(), path.c_str(), e.what()); + DLOG_F(ERROR, "Failed to parse response from {}{}. Error message: {}", host_, path, e.what()); return false; } @@ -119,33 +119,33 @@ bool HttpClient::SendPostRequest(const std::string &path, const std::map ¶ms, const json &data, json &response, std::string &err) { - Client client(host_.c_str(), port_); + Client client(host_, port_); if (ssl_enabled_) { // client.enable_server_certificate_verification(true); - client.set_ca_cert_path(ca_cert_path_.c_str()); + client.set_ca_cert_path(ca_cert_path_); if (!client_cert_path_.empty() && !client_key_path_.empty()) { - // client.set_client_cert_and_key(client_cert_path_.c_str(), client_key_path_.c_str()); + // client.set_client_cert_and_key(client_cert_path_, client_key_path_); } } - auto res = client.Put(path.c_str()); + auto res = client.Put(path); if (!res || res->status != 200) { err = res ? res->body : "Unknown error"; - DLOG_F(ERROR, "Failed to send PUT request to %s%s, data %s. Error message: %s", host_.c_str(), path.c_str(), data.dump().c_str(), err.c_str()); + DLOG_F(ERROR, "Failed to send PUT request to {}{}, data {}. Error message: {}", host_, path, data.dump(), err); return false; } try { response = json::parse(res->body); - DLOG_F(INFO, "Received response from %s%s: %s", host_.c_str(), path.c_str(), response.dump().c_str()); + DLOG_F(INFO, "Received response from {}{}: {}", host_, path, response.dump()); } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to parse response from %s%s. Error message: %s", host_.c_str(), path.c_str(), e.what()); + DLOG_F(ERROR, "Failed to parse response from {}{}. Error message: {}", host_, path, e.what()); return false; } @@ -154,33 +154,33 @@ bool HttpClient::SendPutRequest(const std::string &path, const std::map ¶ms, json &response, std::string &err) { - Client client(host_.c_str(), port_); + Client client(host_, port_); if (ssl_enabled_) { // client.enable_server_certificate_verification(true); - client.set_ca_cert_path(ca_cert_path_.c_str()); + client.set_ca_cert_path(ca_cert_path_); if (!client_cert_path_.empty() && !client_key_path_.empty()) { - // client.set_client_cert_and_key(client_cert_path_.c_str(), client_key_path_.c_str()); + // client.set_client_cert_and_key(client_cert_path_, client_key_path_); } } - auto res = client.Delete(path.c_str()); + auto res = client.Delete(path); if (!res || res->status != 200) { err = res ? res->body : "Unknown error"; - DLOG_F(ERROR, "Failed to send DELETE request to %s%s, data %s. Error message: %s", host_.c_str(), path.c_str(), res->body.c_str(), err.c_str()); + DLOG_F(ERROR, "Failed to send DELETE request to {}{}, data {}. Error message: {}", host_, path, res->body, err); return false; } try { response = json::parse(res->body); - DLOG_F(INFO, "Received response from %s%s: %s", host_.c_str(), path.c_str(), response.dump().c_str()); + DLOG_F(INFO, "Received response from {}{}: {}", host_, path, response.dump()); } catch (const std::exception &e) { - DLOG_F(ERROR, "Failed to parse response from %s%s. Error message: %s", host_.c_str(), path.c_str(), e.what()); + DLOG_F(ERROR, "Failed to parse response from {}{}. Error message: {}", host_, path, e.what()); return false; } @@ -209,24 +209,24 @@ void HttpClient::SetClientKeyPath(const std::string &path) bool HttpClient::ScanPort(int start_port, int end_port, std::vector &open_ports) { - DLOG_F(INFO, "Scanning ports from %d to %d on %s:%d", start_port, end_port, host_.c_str(), port_); + DLOG_F(INFO, "Scanning ports from %d to %d on {}:%d", start_port, end_port, host_, port_); open_ports.clear(); - Client client(host_.c_str(), port_); + Client client(host_, port_); for (int port = start_port; port <= end_port; port++) { #if __cplusplus >= 202002L - auto res = client.Head(std::format("/{}", port).c_str()); + auto res = client.Head(std::format("/{}", port)); #else auto path = "/" + std::to_string(port); - auto res = client.Head(path.c_str()); + auto res = client.Head(path); #endif if (res && res->status == 200) { open_ports.push_back(port); - DLOG_F(INFO, "Port %d is open on %s:%d", port, host_.c_str(), port_); + DLOG_F(INFO, "Port %d is open on {}:%d", port, host_, port_); } } @@ -235,13 +235,13 @@ bool HttpClient::ScanPort(int start_port, int end_port, std::vector &open_p bool HttpClient::CheckServerStatus(std::string &status) { - DLOG_F(INFO, "Checking server status on %s:%d", host_.c_str(), port_); - Client client(host_.c_str(), port_); + DLOG_F(INFO, "Checking server status on {}:%d", host_, port_); + Client client(host_, port_); auto res = client.Head("/"); if (!res || res->status != 200) { status = res ? std::to_string(res->status) : "Unknown error"; - DLOG_F(ERROR, "Failed to check server status on %s:%d with error message: %s", host_.c_str(), port_, status.c_str()); + DLOG_F(ERROR, "Failed to check server status on {}:%d with error message: {}", host_, port_, status); return false; } diff --git a/src/modules/web/httpclient.hpp b/src/modules/web/httpclient.hpp index e19bec01..815cc64c 100644 --- a/src/modules/web/httpclient.hpp +++ b/src/modules/web/httpclient.hpp @@ -34,7 +34,7 @@ Description: Http Client #include #include #include -#include +#include "nlohmann/json.hpp" using json = nlohmann::json; diff --git a/src/modules/web/utils.cpp b/src/modules/web/utils.cpp index e028f1de..55d07976 100644 --- a/src/modules/web/utils.cpp +++ b/src/modules/web/utils.cpp @@ -187,7 +187,7 @@ bool CheckAndKillProgramOnPort(int port) int sockfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if (sockfd < 0) { - DLOG_F(ERROR, "Failed to create socket: %s", strerror(errno)); + DLOG_F(ERROR, "Failed to create socket: {}", strerror(errno)); #ifdef _WIN32 WSACleanup(); #endif @@ -225,7 +225,7 @@ bool CheckAndKillProgramOnPort(int port) FILE *fp = popen(cmd.c_str(), "r"); if (fp == nullptr) { - DLOG_F(ERROR, "Failed to execute command: %s", cmd.c_str()); + DLOG_F(ERROR, "Failed to execute command: {}", cmd); close(sockfd); #ifdef _WIN32 WSACleanup(); @@ -245,17 +245,17 @@ bool CheckAndKillProgramOnPort(int port) // 如果获取到了 PID,则杀死该进程 if (!pid_str.empty()) { - DLOG_F(INFO, "Killing the process on port(%d): PID=%s", port, pid_str.c_str()); + DLOG_F(INFO, "Killing the process on port(%d): PID={}", port, pid_str); #ifdef _WIN32 #ifdef __cpp_lib_format - ret = std::system(std::format("taskkill /F /PID {}", pid_str).c_str()); + ret = std::system(std::format("taskkill /F /PID {}", pid_str)); #else - ret = std::system(fmt::format("taskkill /F /PID {}", pid_str).c_str()); + ret = std::system(fmt::format("taskkill /F /PID {}", pid_str)); #endif #else #ifdef __cpp_lib_format - int ret = std::system(std::format("kill {}", pid_str).c_str()); + int ret = std::system(std::format("kill {}", pid_str)); #else int ret = std::system(fmt::format("kill {}", pid_str).c_str()); #endif @@ -263,7 +263,7 @@ bool CheckAndKillProgramOnPort(int port) if (ret != 0) { - DLOG_F(ERROR, "Failed to kill the process: %s", pid_str.c_str()); + DLOG_F(ERROR, "Failed to kill the process: {}", pid_str); close(sockfd); #ifdef _WIN32 WSACleanup(); @@ -271,7 +271,7 @@ bool CheckAndKillProgramOnPort(int port) return false; } - DLOG_F(INFO, "The process(%s) is killed successfully", pid_str.c_str()); + DLOG_F(INFO, "The process({}) is killed successfully", pid_str); } else { @@ -285,7 +285,7 @@ bool CheckAndKillProgramOnPort(int port) } else { - DLOG_F(ERROR, "Failed to bind socket: %s", strerror(errno)); + DLOG_F(ERROR, "Failed to bind socket: {}", strerror(errno)); close(sockfd); #ifdef _WIN32 WSACleanup(); diff --git a/src/websocket/device/WsDeviceHub.hpp b/src/websocket/device/WsDeviceHub.hpp index 545fe3d6..d33aecb5 100644 --- a/src/websocket/device/WsDeviceHub.hpp +++ b/src/websocket/device/WsDeviceHub.hpp @@ -4,7 +4,11 @@ #include "WsDeviceInstance.hpp" +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif class WsDeviceHub { diff --git a/src/websocket/device/WsDeviceServer.hpp b/src/websocket/device/WsDeviceServer.hpp index eea7091b..af2622aa 100644 --- a/src/websocket/device/WsDeviceServer.hpp +++ b/src/websocket/device/WsDeviceServer.hpp @@ -12,7 +12,11 @@ #include "oatpp-websocket/ConnectionHandler.hpp" #endif +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include class WsDeviceServer : public oatpp::websocket::AsyncConnectionHandler::SocketInstanceListener diff --git a/src/websocket/plugin/WsPluginHub.hpp b/src/websocket/plugin/WsPluginHub.hpp index 42fdee0f..65d53f33 100644 --- a/src/websocket/plugin/WsPluginHub.hpp +++ b/src/websocket/plugin/WsPluginHub.hpp @@ -4,7 +4,11 @@ #include "WsPluginInstance.hpp" +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif class WsPluginHub { diff --git a/src/websocket/plugin/WsPluginServer.hpp b/src/websocket/plugin/WsPluginServer.hpp index a7303f8b..0a492167 100644 --- a/src/websocket/plugin/WsPluginServer.hpp +++ b/src/websocket/plugin/WsPluginServer.hpp @@ -12,7 +12,11 @@ #include "oatpp-websocket/ConnectionHandler.hpp" #endif +#if ENABLE_FASTHASH +#include "emhash/hash_table8.hpp" +#else #include +#endif #include class WsPluginServer : public oatpp::websocket::AsyncConnectionHandler::SocketInstanceListener