diff options
| author | 2019-06-26 19:05:04 -0400 | |
|---|---|---|
| committer | 2019-06-26 19:05:04 -0400 | |
| commit | 49af3bcdcba76decc8aec5b6812eac04e488e47f (patch) | |
| tree | 6b46afffc64470d57f48c9551b30ee4feed97b2f | |
| parent | Merge pull request #2548 from DarkLordZach/applet-shopn (diff) | |
| download | yuzu-49af3bcdcba76decc8aec5b6812eac04e488e47f.tar.gz yuzu-49af3bcdcba76decc8aec5b6812eac04e488e47f.tar.xz yuzu-49af3bcdcba76decc8aec5b6812eac04e488e47f.zip | |
pm: Implement pm:info GetTitleId
Searches the process list for a process with the specified ID, returning the title ID if it exists.
| -rw-r--r-- | src/core/hle/service/pm/pm.cpp | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/src/core/hle/service/pm/pm.cpp b/src/core/hle/service/pm/pm.cpp index ebcc41a43..b6a7d3474 100644 --- a/src/core/hle/service/pm/pm.cpp +++ b/src/core/hle/service/pm/pm.cpp | |||
| @@ -8,6 +8,26 @@ | |||
| 8 | 8 | ||
| 9 | namespace Service::PM { | 9 | namespace Service::PM { |
| 10 | 10 | ||
| 11 | namespace { | ||
| 12 | |||
| 13 | constexpr ResultCode ERROR_PROCESS_NOT_FOUND{ErrorModule::PM, 1}; | ||
| 14 | |||
| 15 | constexpr u64 NO_PROCESS_FOUND_PID{0}; | ||
| 16 | |||
| 17 | std::optional<Kernel::SharedPtr<Kernel::Process>> SearchProcessList( | ||
| 18 | const std::vector<Kernel::SharedPtr<Kernel::Process>>& process_list, | ||
| 19 | std::function<bool(const Kernel::SharedPtr<Kernel::Process>&)> predicate) { | ||
| 20 | const auto iter = std::find_if(process_list.begin(), process_list.end(), predicate); | ||
| 21 | |||
| 22 | if (iter == process_list.end()) { | ||
| 23 | return std::nullopt; | ||
| 24 | } | ||
| 25 | |||
| 26 | return *iter; | ||
| 27 | } | ||
| 28 | |||
| 29 | } // Anonymous namespace | ||
| 30 | |||
| 11 | class BootMode final : public ServiceFramework<BootMode> { | 31 | class BootMode final : public ServiceFramework<BootMode> { |
| 12 | public: | 32 | public: |
| 13 | explicit BootMode() : ServiceFramework{"pm:bm"} { | 33 | explicit BootMode() : ServiceFramework{"pm:bm"} { |
| @@ -60,12 +80,37 @@ public: | |||
| 60 | 80 | ||
| 61 | class Info final : public ServiceFramework<Info> { | 81 | class Info final : public ServiceFramework<Info> { |
| 62 | public: | 82 | public: |
| 63 | explicit Info() : ServiceFramework{"pm:info"} { | 83 | explicit Info(const std::vector<Kernel::SharedPtr<Kernel::Process>>& process_list) |
| 84 | : ServiceFramework{"pm:info"}, process_list(process_list) { | ||
| 64 | static const FunctionInfo functions[] = { | 85 | static const FunctionInfo functions[] = { |
| 65 | {0, nullptr, "GetTitleId"}, | 86 | {0, &Info::GetTitleId, "GetTitleId"}, |
| 66 | }; | 87 | }; |
| 67 | RegisterHandlers(functions); | 88 | RegisterHandlers(functions); |
| 68 | } | 89 | } |
| 90 | |||
| 91 | private: | ||
| 92 | void GetTitleId(Kernel::HLERequestContext& ctx) { | ||
| 93 | IPC::RequestParser rp{ctx}; | ||
| 94 | const auto process_id = rp.PopRaw<u64>(); | ||
| 95 | |||
| 96 | LOG_DEBUG(Service_PM, "called, process_id={:016X}", process_id); | ||
| 97 | |||
| 98 | const auto process = SearchProcessList(process_list, [process_id](const auto& process) { | ||
| 99 | return process->GetProcessID() == process_id; | ||
| 100 | }); | ||
| 101 | |||
| 102 | if (!process.has_value()) { | ||
| 103 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 104 | rb.Push(ERROR_PROCESS_NOT_FOUND); | ||
| 105 | return; | ||
| 106 | } | ||
| 107 | |||
| 108 | IPC::ResponseBuilder rb{ctx, 4}; | ||
| 109 | rb.Push(RESULT_SUCCESS); | ||
| 110 | rb.Push((*process)->GetTitleID()); | ||
| 111 | } | ||
| 112 | |||
| 113 | const std::vector<Kernel::SharedPtr<Kernel::Process>>& process_list; | ||
| 69 | }; | 114 | }; |
| 70 | 115 | ||
| 71 | class Shell final : public ServiceFramework<Shell> { | 116 | class Shell final : public ServiceFramework<Shell> { |