[Revert] Restore project state to 79ae4b6

This commit is contained in:
xiaozhou233 committed 2026-04-22 13:08:39 +08:00
1 parent 601c999023
commit 08ec414094
6 files changed
+13 -137

No files matched your search

@@ -4,7 +4,6 @@
#include <vector>
#include <string>
#include <modules/IModule.hpp>
#include <JuiceAgent/Config.hpp>
namespace JuiceAgent::Core::Modules {
@@ -21,8 +20,6 @@ public:
IModule* find_module(const std::string& name);
bool loadAllRegisteredModules();
private:
std::vector<std::unique_ptr<IModule>> _modules;
};
+11 -54
View File
@@ -1,68 +1,25 @@
#pragma once
#include <modules/IModule.hpp>
#include <functional>
#include <unordered_map>
#include <memory>
#include <string>
#include <vector>
namespace JuiceAgent::Core::Modules {
class ModuleRegistry {
class JarLoaderModule : public IModule {
public:
using Creator = std::function<std::unique_ptr<IModule>()>;
JarLoaderModule() = default;
~JarLoaderModule() override = default;
static void registerModule(const std::string& name, Creator creator) {
getRegistry()[name] = creator;
std::string name() const override {
return "JarLoader";
}
static std::unique_ptr<IModule> createModule(const std::string& name) {
auto& reg = getRegistry();
auto it = reg.find(name);
if (it != reg.end()) {
return it->second();
}
return nullptr;
}
static std::vector<std::string> getRegisteredModuleNames() {
std::vector<std::string> names;
auto& reg = getRegistry();
for (const auto& pair : reg) {
names.push_back(pair.first);
}
return names;
}
bool init() override;
bool start() override;
void stop() override;
private:
static std::unordered_map<std::string, Creator>& getRegistry() {
static std::unordered_map<std::string, Creator> registry;
return registry;
}
bool _initialized = false;
bool _running = false;
};
#define DEFINE_MODULE(ModuleName) \
class ModuleName##Module : public IModule { \
public: \
ModuleName##Module() = default; \
~ModuleName##Module() override = default; \
\
std::string name() const override { \
return #ModuleName; \
} \
\
bool init() override; \
bool start() override; \
void stop() override; \
\
private: \
bool _initialized = false; \
bool _running = false; \
};
DEFINE_MODULE(JarLoader)
DEFINE_MODULE(Example)
} // namespace JuiceAgent::Core::Modules
}