refactor: Replace json with IDataNode in DebugEngine

**Changes:**
- DebugEngine.h: Replace `json` with `std::unique_ptr<IDataNode>`
  - engineConfig: json → std::unique_ptr<IDataNode>
  - getDetailedStatus(): json → std::unique_ptr<IDataNode>

- DebugEngine.cpp: Update implementations
  - Include JsonDataNode/JsonDataValue headers
  - getDetailedStatus() returns JsonDataNode wrapper
  - Message logging adapted for IDataNode (check nullptr instead of dump())
  - Keep json internally for convenience (converted to IDataNode when needed)

**Architecture:**
- Engine uses IDataNode abstraction for external interfaces
- Internal JSON usage preserved for convenience
- Compatible with new IDataTree system

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
StillHammer 2025-10-28 17:01:19 +08:00
parent 6b295e9b17
commit 62e174f43d
2 changed files with 16 additions and 12 deletions

View File

@ -7,13 +7,11 @@
#include <thread>
#include <atomic>
#include <spdlog/spdlog.h>
#include <nlohmann/json.hpp>
#include "IEngine.h"
#include "IModuleSystem.h"
#include "IIO.h"
using json = nlohmann::json;
#include "IDataNode.h"
namespace grove {
@ -48,7 +46,7 @@ private:
size_t frameCount = 0;
// Configuration
json engineConfig;
std::unique_ptr<IDataNode> engineConfig;
// Helper methods
void logEngineStart();
@ -82,7 +80,7 @@ public:
void resumeExecution();
void stepSingleFrame();
bool isPaused() const;
json getDetailedStatus() const;
std::unique_ptr<IDataNode> getDetailedStatus() const;
void setLogLevel(spdlog::level::level_enum level);
};

View File

@ -1,4 +1,7 @@
#include <grove/DebugEngine.h>
#include <grove/JsonDataNode.h>
#include <grove/JsonDataValue.h>
#include <nlohmann/json.hpp>
#include <fstream>
#include <filesystem>
#include <spdlog/sinks/stdout_color_sinks.h>
@ -6,6 +9,8 @@
namespace grove {
using json = nlohmann::json;
DebugEngine::DebugEngine() {
// Create comprehensive logger with multiple sinks
auto console_sink = std::make_shared<spdlog::sinks::stdout_color_sink_mt>();
@ -294,7 +299,7 @@ bool DebugEngine::isPaused() const {
return paused;
}
json DebugEngine::getDetailedStatus() const {
std::unique_ptr<IDataNode> DebugEngine::getDetailedStatus() const {
logger->debug("📊 Detailed status requested");
json status = {
@ -315,8 +320,8 @@ json DebugEngine::getDetailedStatus() const {
status["average_fps"] = frameCount / totalTime;
}
logger->trace("📄 Status JSON: {}", status.dump());
return status;
logger->trace("📄 Status: {}", status.dump());
return std::make_unique<JsonDataNode>("status", status);
}
void DebugEngine::setLogLevel(spdlog::level::level_enum level) {
@ -425,8 +430,9 @@ void DebugEngine::processClientMessages() {
for (int j = 0; j < messagesToProcess; ++j) {
try {
auto message = socket->pullMessage();
logger->debug("📩 Client {} message: topic='{}', data size={}",
i, message.topic, message.data.dump().size());
std::string dataPreview = message.data ? message.data->getData()->toString() : "null";
logger->debug("📩 Client {} message: topic='{}', data present={}",
i, message.topic, message.data != nullptr);
// TODO: Route message to appropriate module or process it
logger->trace("🚧 TODO: Route client message to modules");
@ -451,8 +457,8 @@ void DebugEngine::processCoordinatorMessages() {
for (int i = 0; i < messagesToProcess; ++i) {
try {
auto message = coordinatorSocket->pullMessage();
logger->debug("📩 Coordinator message: topic='{}', data size={}",
message.topic, message.data.dump().size());
logger->debug("📩 Coordinator message: topic='{}', data present={}",
message.topic, message.data != nullptr);
// TODO: Handle coordinator commands (shutdown, config reload, etc.)
logger->trace("🚧 TODO: Handle coordinator commands");