diff options
| author | 2019-03-25 20:31:16 -0400 | |
|---|---|---|
| committer | 2019-06-10 00:03:11 -0400 | |
| commit | 5ddc9cede5bc286f4be54c4510ed36f88e0d2756 (patch) | |
| tree | e65c3717979d746148da3211b522e31495d1f3d5 /src | |
| parent | yuzu_tester: Add SDL2-based EmuWindow that doesn't show the window (diff) | |
| download | yuzu-5ddc9cede5bc286f4be54c4510ed36f88e0d2756.tar.gz yuzu-5ddc9cede5bc286f4be54c4510ed36f88e0d2756.tar.xz yuzu-5ddc9cede5bc286f4be54c4510ed36f88e0d2756.zip | |
yuzu_tester: Add 'yuzutest' service
Diffstat (limited to 'src')
| -rw-r--r-- | src/yuzu_tester/service/yuzutest.cpp | 104 | ||||
| -rw-r--r-- | src/yuzu_tester/service/yuzutest.h | 19 |
2 files changed, 123 insertions, 0 deletions
diff --git a/src/yuzu_tester/service/yuzutest.cpp b/src/yuzu_tester/service/yuzutest.cpp new file mode 100644 index 000000000..026582027 --- /dev/null +++ b/src/yuzu_tester/service/yuzutest.cpp | |||
| @@ -0,0 +1,104 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <memory> | ||
| 6 | #include "common/string_util.h" | ||
| 7 | #include "core/hle/ipc_helpers.h" | ||
| 8 | #include "core/hle/service/service.h" | ||
| 9 | #include "core/hle/service/sm/sm.h" | ||
| 10 | #include "yuzu_tester/service/yuzutest.h" | ||
| 11 | |||
| 12 | namespace Service::Yuzu { | ||
| 13 | |||
| 14 | constexpr u64 SERVICE_VERSION = 1; | ||
| 15 | |||
| 16 | class YuzuTest final : public ServiceFramework<YuzuTest> { | ||
| 17 | public: | ||
| 18 | explicit YuzuTest(std::string data, std::function<void(u32, std::string)> finish_callback) | ||
| 19 | : ServiceFramework{"yuzutest"}, data(std::move(data)), | ||
| 20 | finish_callback(std::move(finish_callback)) { | ||
| 21 | static const FunctionInfo functions[] = { | ||
| 22 | {0, &YuzuTest::Initialize, "Initialize"}, | ||
| 23 | {1, &YuzuTest::GetServiceVersion, "GetServiceVersion"}, | ||
| 24 | {2, &YuzuTest::GetData, "GetData"}, | ||
| 25 | {3, &YuzuTest::SetResultCode, "SetResultCode"}, | ||
| 26 | {4, &YuzuTest::SetResultData, "SetResultData"}, | ||
| 27 | {5, &YuzuTest::Finish, "Finish"}, | ||
| 28 | }; | ||
| 29 | |||
| 30 | RegisterHandlers(functions); | ||
| 31 | } | ||
| 32 | |||
| 33 | private: | ||
| 34 | void Initialize(Kernel::HLERequestContext& ctx) { | ||
| 35 | LOG_DEBUG(Frontend, "called"); | ||
| 36 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 37 | rb.Push(RESULT_SUCCESS); | ||
| 38 | } | ||
| 39 | |||
| 40 | void GetServiceVersion(Kernel::HLERequestContext& ctx) { | ||
| 41 | LOG_DEBUG(Frontend, "called"); | ||
| 42 | IPC::ResponseBuilder rb{ctx, 4}; | ||
| 43 | rb.Push(RESULT_SUCCESS); | ||
| 44 | rb.Push(SERVICE_VERSION); | ||
| 45 | } | ||
| 46 | |||
| 47 | void GetData(Kernel::HLERequestContext& ctx) { | ||
| 48 | LOG_DEBUG(Frontend, "called"); | ||
| 49 | const auto size = ctx.GetWriteBufferSize(); | ||
| 50 | const auto write_size = std::min(size, data.size()); | ||
| 51 | ctx.WriteBuffer(data.data(), write_size); | ||
| 52 | |||
| 53 | IPC::ResponseBuilder rb{ctx, 3}; | ||
| 54 | rb.Push(RESULT_SUCCESS); | ||
| 55 | rb.Push<u32>(write_size); | ||
| 56 | } | ||
| 57 | |||
| 58 | void SetResultCode(Kernel::HLERequestContext& ctx) { | ||
| 59 | IPC::RequestParser rp{ctx}; | ||
| 60 | const auto code = rp.PopRaw<u32>(); | ||
| 61 | |||
| 62 | LOG_INFO(Frontend, "called with result_code={:08X}", code); | ||
| 63 | result_code = code; | ||
| 64 | |||
| 65 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 66 | rb.Push(RESULT_SUCCESS); | ||
| 67 | } | ||
| 68 | |||
| 69 | void SetResultData(Kernel::HLERequestContext& ctx) { | ||
| 70 | IPC::RequestParser rp{ctx}; | ||
| 71 | const auto buffer = ctx.ReadBuffer(); | ||
| 72 | std::string data = Common::StringFromFixedZeroTerminatedBuffer( | ||
| 73 | reinterpret_cast<const char*>(buffer.data()), buffer.size()); | ||
| 74 | |||
| 75 | LOG_INFO(Frontend, "called with string={}", data); | ||
| 76 | result_string = data; | ||
| 77 | |||
| 78 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 79 | rb.Push(RESULT_SUCCESS); | ||
| 80 | } | ||
| 81 | |||
| 82 | void Finish(Kernel::HLERequestContext& ctx) { | ||
| 83 | LOG_DEBUG(Frontend, "called"); | ||
| 84 | |||
| 85 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 86 | rb.Push(RESULT_SUCCESS); | ||
| 87 | |||
| 88 | finish_callback(result_code, result_string); | ||
| 89 | } | ||
| 90 | |||
| 91 | std::string data; | ||
| 92 | |||
| 93 | u32 result_code = 0; | ||
| 94 | std::string result_string; | ||
| 95 | |||
| 96 | std::function<void(u64, std::string)> finish_callback; | ||
| 97 | }; | ||
| 98 | |||
| 99 | void InstallInterfaces(SM::ServiceManager& sm, std::string data, | ||
| 100 | std::function<void(u32, std::string)> finish_callback) { | ||
| 101 | std::make_shared<YuzuTest>(data, finish_callback)->InstallAsService(sm); | ||
| 102 | } | ||
| 103 | |||
| 104 | } // namespace Service::Yuzu | ||
diff --git a/src/yuzu_tester/service/yuzutest.h b/src/yuzu_tester/service/yuzutest.h new file mode 100644 index 000000000..e68a24544 --- /dev/null +++ b/src/yuzu_tester/service/yuzutest.h | |||
| @@ -0,0 +1,19 @@ | |||
| 1 | // Copyright 2019 yuzu Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <functional> | ||
| 8 | #include <string> | ||
| 9 | |||
| 10 | namespace Service::SM { | ||
| 11 | class ServiceManager; | ||
| 12 | } | ||
| 13 | |||
| 14 | namespace Service::Yuzu { | ||
| 15 | |||
| 16 | void InstallInterfaces(SM::ServiceManager& sm, std::string data, | ||
| 17 | std::function<void(u32, std::string)> finish_callback); | ||
| 18 | |||
| 19 | } // namespace Service::Yuzu | ||