From 6a302aff691a85776377d1b8017284ed92a1ebab Mon Sep 17 00:00:00 2001 From: momo5502 Date: Wed, 23 Apr 2025 15:30:36 +0200 Subject: [PATCH] Add nlohmann json --- .gitmodules | 4 ++++ deps/CMakeLists.txt | 4 ++++ deps/json | 1 + src/debugger/CMakeLists.txt | 1 + src/debugger/main.cpp | 28 +++++++++++++++++++++++----- 5 files changed, 33 insertions(+), 5 deletions(-) create mode 160000 deps/json diff --git a/.gitmodules b/.gitmodules index ce0fdeaf..5571083f 100644 --- a/.gitmodules +++ b/.gitmodules @@ -18,3 +18,7 @@ [submodule "deps/gtest-parallel"] path = deps/gtest-parallel url = https://github.com/google/gtest-parallel.git +[submodule "deps/json"] + path = deps/json + url = https://github.com/nlohmann/json.git + branch = master diff --git a/deps/CMakeLists.txt b/deps/CMakeLists.txt index 5ed0c395..28155aed 100644 --- a/deps/CMakeLists.txt +++ b/deps/CMakeLists.txt @@ -3,6 +3,10 @@ add_subdirectory(unicorn) ########################################## +add_subdirectory(json) + +########################################## + add_library(reflect INTERFACE) target_include_directories(reflect INTERFACE "${CMAKE_CURRENT_LIST_DIR}/reflect" diff --git a/deps/json b/deps/json new file mode 160000 index 00000000..55f93686 --- /dev/null +++ b/deps/json @@ -0,0 +1 @@ +Subproject commit 55f93686c01528224f448c19128836e7df245f72 diff --git a/src/debugger/CMakeLists.txt b/src/debugger/CMakeLists.txt index ac49ed03..bc63c072 100644 --- a/src/debugger/CMakeLists.txt +++ b/src/debugger/CMakeLists.txt @@ -16,6 +16,7 @@ endif() target_link_libraries(debugger PRIVATE windows-emulator + nlohmann_json ) set_property(GLOBAL PROPERTY VS_STARTUP_PROJECT debugger) diff --git a/src/debugger/main.cpp b/src/debugger/main.cpp index d47b87cd..2cfcab79 100644 --- a/src/debugger/main.cpp +++ b/src/debugger/main.cpp @@ -2,6 +2,7 @@ #include #include +#include #ifdef OS_EMSCRIPTEN #include @@ -73,18 +74,35 @@ namespace #endif } - void handle_messages() + void send_object(const nlohmann::json& json) + { + const std::string res = json.dump(); + send_message(res); + } + + nlohmann::json receive_object() + { + auto message = receive_message(); + if (message.empty()) + { + return {}; + } + + return nlohmann::json::parse(message); + } + + void handle_messages(windows_emulator& win_emu) { while (true) { suspend_execution(0ms); - const auto message = receive_message(); - if (message.empty()) + const auto message = receive_object(); + if (message.is_null()) { break; } - puts(message.c_str()); + puts(message.dump().c_str()); } } @@ -144,7 +162,7 @@ namespace windows_emulator win_emu{app_settings, settings}; win_emu.callbacks.on_thread_switch = [&] { - handle_messages(); // + handle_messages(win_emu); // }; return run_emulation(win_emu);