diff options
| author | 2018-08-08 23:41:12 +1000 | |
|---|---|---|
| committer | 2018-08-08 23:41:12 +1000 | |
| commit | 03d7faf58390216729eb828b08be7e5f0ef82727 (patch) | |
| tree | 07fd1fb940cf6893bf66a000f495807ba637d9eb /src/core/hle/service | |
| parent | began initial implementation of "ProfileManager" (diff) | |
| download | yuzu-03d7faf58390216729eb828b08be7e5f0ef82727.tar.gz yuzu-03d7faf58390216729eb828b08be7e5f0ef82727.tar.xz yuzu-03d7faf58390216729eb828b08be7e5f0ef82727.zip | |
GetProfileBase and GetProfileBaseAndData added
Diffstat (limited to 'src/core/hle/service')
| -rw-r--r-- | src/core/hle/service/acc/acc.cpp | 77 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 60 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 13 |
3 files changed, 106 insertions, 44 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index 8efaf6171..92141f61c 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -27,19 +27,13 @@ struct UserData { | |||
| 27 | }; | 27 | }; |
| 28 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); | 28 | static_assert(sizeof(UserData) == 0x80, "UserData structure has incorrect size"); |
| 29 | 29 | ||
| 30 | struct ProfileBase { | ||
| 31 | UUID user_id; | ||
| 32 | u64 timestamp; | ||
| 33 | std::array<u8, 0x20> username; | ||
| 34 | }; | ||
| 35 | static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase structure has incorrect size"); | ||
| 36 | |||
| 37 | // TODO(ogniK): Generate a real user id based on username, md5(username) maybe? | 30 | // TODO(ogniK): Generate a real user id based on username, md5(username) maybe? |
| 38 | static UUID DEFAULT_USER_ID{1ull, 0ull}; | 31 | static UUID DEFAULT_USER_ID{1ull, 0ull}; |
| 39 | 32 | ||
| 40 | class IProfile final : public ServiceFramework<IProfile> { | 33 | class IProfile final : public ServiceFramework<IProfile> { |
| 41 | public: | 34 | public: |
| 42 | explicit IProfile(UUID user_id) : ServiceFramework("IProfile"), user_id(user_id) { | 35 | explicit IProfile(UUID user_id, ProfileManager& profile_manager) |
| 36 | : ServiceFramework("IProfile"), user_id(user_id), profile_manager(profile_manager) { | ||
| 43 | static const FunctionInfo functions[] = { | 37 | static const FunctionInfo functions[] = { |
| 44 | {0, &IProfile::Get, "Get"}, | 38 | {0, &IProfile::Get, "Get"}, |
| 45 | {1, &IProfile::GetBase, "GetBase"}, | 39 | {1, &IProfile::GetBase, "GetBase"}, |
| @@ -51,40 +45,41 @@ public: | |||
| 51 | 45 | ||
| 52 | private: | 46 | private: |
| 53 | void Get(Kernel::HLERequestContext& ctx) { | 47 | void Get(Kernel::HLERequestContext& ctx) { |
| 54 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 48 | LOG_INFO(Service_ACC, "called user_id={}", user_id.Format()); |
| 55 | ProfileBase profile_base{}; | 49 | ProfileBase profile_base{}; |
| 56 | profile_base.user_id = user_id; | 50 | std::array<u8, MAX_DATA> data{}; |
| 57 | if (Settings::values.username.size() > profile_base.username.size()) { | 51 | /*if (Settings::values.username.size() > profile_base.username.size()) { |
| 58 | std::copy_n(Settings::values.username.begin(), profile_base.username.size(), | 52 | std::copy_n(Settings::values.username.begin(), profile_base.username.size(), |
| 59 | profile_base.username.begin()); | 53 | profile_base.username.begin()); |
| 60 | } else { | 54 | } else { |
| 61 | std::copy(Settings::values.username.begin(), Settings::values.username.end(), | 55 | std::copy(Settings::values.username.begin(), Settings::values.username.end(), |
| 62 | profile_base.username.begin()); | 56 | profile_base.username.begin()); |
| 57 | }*/ | ||
| 58 | if (profile_manager.GetProfileBaseAndData(user_id, profile_base, data)) { | ||
| 59 | ctx.WriteBuffer(data); | ||
| 60 | IPC::ResponseBuilder rb{ctx, 16}; | ||
| 61 | rb.Push(RESULT_SUCCESS); | ||
| 62 | rb.PushRaw(profile_base); | ||
| 63 | } else { | ||
| 64 | IPC::ResponseBuilder rb{ctx, 2}; | ||
| 65 | rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code | ||
| 63 | } | 66 | } |
| 64 | |||
| 65 | IPC::ResponseBuilder rb{ctx, 16}; | ||
| 66 | rb.Push(RESULT_SUCCESS); | ||
| 67 | rb.PushRaw(profile_base); | ||
| 68 | } | 67 | } |
| 69 | 68 | ||
| 70 | void GetBase(Kernel::HLERequestContext& ctx) { | 69 | void GetBase(Kernel::HLERequestContext& ctx) { |
| 71 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 70 | LOG_INFO(Service_ACC, "called user_id={}", user_id.Format()); |
| 72 | |||
| 73 | // TODO(Subv): Retrieve this information from somewhere. | ||
| 74 | ProfileBase profile_base{}; | 71 | ProfileBase profile_base{}; |
| 75 | profile_base.user_id = user_id; | 72 | if (profile_manager.GetProfileBase(user_id, profile_base)) { |
| 76 | if (Settings::values.username.size() > profile_base.username.size()) { | 73 | IPC::ResponseBuilder rb{ctx, 16}; |
| 77 | std::copy_n(Settings::values.username.begin(), profile_base.username.size(), | 74 | rb.Push(RESULT_SUCCESS); |
| 78 | profile_base.username.begin()); | 75 | rb.PushRaw(profile_base); |
| 79 | } else { | 76 | } else { |
| 80 | std::copy(Settings::values.username.begin(), Settings::values.username.end(), | 77 | IPC::ResponseBuilder rb{ctx, 2}; |
| 81 | profile_base.username.begin()); | 78 | rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code |
| 82 | } | 79 | } |
| 83 | IPC::ResponseBuilder rb{ctx, 16}; | ||
| 84 | rb.Push(RESULT_SUCCESS); | ||
| 85 | rb.PushRaw(profile_base); | ||
| 86 | } | 80 | } |
| 87 | 81 | ||
| 82 | ProfileManager& profile_manager; | ||
| 88 | UUID user_id; ///< The user id this profile refers to. | 83 | UUID user_id; ///< The user id this profile refers to. |
| 89 | }; | 84 | }; |
| 90 | 85 | ||
| @@ -139,29 +134,32 @@ void Module::Interface::GetUserExistence(Kernel::HLERequestContext& ctx) { | |||
| 139 | } | 134 | } |
| 140 | 135 | ||
| 141 | void Module::Interface::ListAllUsers(Kernel::HLERequestContext& ctx) { | 136 | void Module::Interface::ListAllUsers(Kernel::HLERequestContext& ctx) { |
| 142 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 137 | LOG_INFO(Service_ACC, "called"); |
| 143 | // TODO(Subv): There is only one user for now. | 138 | ctx.WriteBuffer(profile_manager->GetAllUsers()); |
| 144 | const std::vector<UUID> user_ids = {DEFAULT_USER_ID}; | ||
| 145 | ctx.WriteBuffer(user_ids); | ||
| 146 | IPC::ResponseBuilder rb{ctx, 2}; | 139 | IPC::ResponseBuilder rb{ctx, 2}; |
| 147 | rb.Push(RESULT_SUCCESS); | 140 | rb.Push(RESULT_SUCCESS); |
| 148 | } | 141 | } |
| 149 | 142 | ||
| 150 | void Module::Interface::ListOpenUsers(Kernel::HLERequestContext& ctx) { | 143 | void Module::Interface::ListOpenUsers(Kernel::HLERequestContext& ctx) { |
| 151 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | 144 | LOG_INFO(Service_ACC, "called"); |
| 152 | // TODO(Subv): There is only one user for now. | 145 | ctx.WriteBuffer(profile_manager->GetOpenUsers()); |
| 153 | const std::vector<UUID> user_ids = {DEFAULT_USER_ID}; | ||
| 154 | ctx.WriteBuffer(user_ids); | ||
| 155 | IPC::ResponseBuilder rb{ctx, 2}; | 146 | IPC::ResponseBuilder rb{ctx, 2}; |
| 156 | rb.Push(RESULT_SUCCESS); | 147 | rb.Push(RESULT_SUCCESS); |
| 157 | } | 148 | } |
| 158 | 149 | ||
| 150 | void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) { | ||
| 151 | LOG_INFO(Service_ACC, "called"); | ||
| 152 | IPC::ResponseBuilder rb{ctx, 6}; | ||
| 153 | rb.Push(RESULT_SUCCESS); | ||
| 154 | rb.PushRaw<UUID>(profile_manager->GetLastOpennedUser()); | ||
| 155 | } | ||
| 156 | |||
| 159 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { | 157 | void Module::Interface::GetProfile(Kernel::HLERequestContext& ctx) { |
| 160 | IPC::RequestParser rp{ctx}; | 158 | IPC::RequestParser rp{ctx}; |
| 161 | UUID user_id = rp.PopRaw<UUID>(); | 159 | UUID user_id = rp.PopRaw<UUID>(); |
| 162 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; | 160 | IPC::ResponseBuilder rb{ctx, 2, 0, 1}; |
| 163 | rb.Push(RESULT_SUCCESS); | 161 | rb.Push(RESULT_SUCCESS); |
| 164 | rb.PushIpcInterface<IProfile>(user_id); | 162 | rb.PushIpcInterface<IProfile>(user_id, *profile_manager); |
| 165 | LOG_DEBUG(Service_ACC, "called user_id={}", user_id.Format()); | 163 | LOG_DEBUG(Service_ACC, "called user_id={}", user_id.Format()); |
| 166 | } | 164 | } |
| 167 | 165 | ||
| @@ -178,13 +176,6 @@ void Module::Interface::GetBaasAccountManagerForApplication(Kernel::HLERequestCo | |||
| 178 | LOG_DEBUG(Service_ACC, "called"); | 176 | LOG_DEBUG(Service_ACC, "called"); |
| 179 | } | 177 | } |
| 180 | 178 | ||
| 181 | void Module::Interface::GetLastOpenedUser(Kernel::HLERequestContext& ctx) { | ||
| 182 | LOG_WARNING(Service_ACC, "(STUBBED) called"); | ||
| 183 | IPC::ResponseBuilder rb{ctx, 6}; | ||
| 184 | rb.Push(RESULT_SUCCESS); | ||
| 185 | rb.PushRaw(DEFAULT_USER_ID); | ||
| 186 | } | ||
| 187 | |||
| 188 | Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) | 179 | Module::Interface::Interface(std::shared_ptr<Module> module, const char* name) |
| 189 | : ServiceFramework(name), module(std::move(module)) {} | 180 | : ServiceFramework(name), module(std::move(module)) {} |
| 190 | 181 | ||
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index 8819c5703..925022018 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -43,10 +43,13 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20> usernam | |||
| 43 | prof_inf.username = username; | 43 | prof_inf.username = username; |
| 44 | prof_inf.data = std::array<u8, MAX_DATA>(); | 44 | prof_inf.data = std::array<u8, MAX_DATA>(); |
| 45 | prof_inf.creation_time = 0x0; | 45 | prof_inf.creation_time = 0x0; |
| 46 | prof_inf.is_open = false; | ||
| 46 | return AddUser(prof_inf); | 47 | return AddUser(prof_inf); |
| 47 | } | 48 | } |
| 48 | 49 | ||
| 49 | size_t ProfileManager::GetUserIndex(UUID uuid) { | 50 | size_t ProfileManager::GetUserIndex(UUID uuid) { |
| 51 | if (!uuid) | ||
| 52 | return -1; | ||
| 50 | for (unsigned i = 0; i < user_count; i++) | 53 | for (unsigned i = 0; i < user_count; i++) |
| 51 | if (profiles[i].user_uuid == uuid) | 54 | if (profiles[i].user_uuid == uuid) |
| 52 | return i; | 55 | return i; |
| @@ -86,4 +89,61 @@ bool ProfileManager::UserExists(UUID uuid) { | |||
| 86 | return (GetUserIndex(uuid) != -1); | 89 | return (GetUserIndex(uuid) != -1); |
| 87 | } | 90 | } |
| 88 | 91 | ||
| 92 | void ProfileManager::OpenUser(UUID uuid) { | ||
| 93 | auto idx = GetUserIndex(uuid); | ||
| 94 | if (idx == -1) | ||
| 95 | return; | ||
| 96 | profiles[idx].is_open = true; | ||
| 97 | last_openned_user = uuid; | ||
| 98 | } | ||
| 99 | |||
| 100 | void ProfileManager::CloseUser(UUID uuid) { | ||
| 101 | auto idx = GetUserIndex(uuid); | ||
| 102 | if (idx == -1) | ||
| 103 | return; | ||
| 104 | profiles[idx].is_open = false; | ||
| 105 | } | ||
| 106 | |||
| 107 | std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() { | ||
| 108 | std::array<UUID, MAX_USERS> output; | ||
| 109 | for (unsigned i = 0; i < user_count; i++) { | ||
| 110 | output[i] = profiles[i].user_uuid; | ||
| 111 | } | ||
| 112 | return output; | ||
| 113 | } | ||
| 114 | |||
| 115 | std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() { | ||
| 116 | std::array<UUID, MAX_USERS> output; | ||
| 117 | unsigned user_idx = 0; | ||
| 118 | for (unsigned i = 0; i < user_count; i++) { | ||
| 119 | if (profiles[i].is_open) { | ||
| 120 | output[i++] = profiles[i].user_uuid; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | return output; | ||
| 124 | } | ||
| 125 | |||
| 126 | const UUID& ProfileManager::GetLastOpennedUser() { | ||
| 127 | return last_openned_user; | ||
| 128 | } | ||
| 129 | |||
| 130 | bool ProfileManager::GetProfileBaseAndData(size_t index, ProfileBase& profile, | ||
| 131 | std::array<u8, MAX_DATA>& data) { | ||
| 132 | if (GetProfileBase(index, profile)) { | ||
| 133 | std::memcpy(data.data(), profiles[index].data.data(), MAX_DATA); | ||
| 134 | return true; | ||
| 135 | } | ||
| 136 | return false; | ||
| 137 | } | ||
| 138 | bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile, | ||
| 139 | std::array<u8, MAX_DATA>& data) { | ||
| 140 | auto idx = GetUserIndex(uuid); | ||
| 141 | return GetProfileBaseAndData(idx, profile, data); | ||
| 142 | } | ||
| 143 | |||
| 144 | bool ProfileManager::GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, | ||
| 145 | std::array<u8, MAX_DATA>& data) { | ||
| 146 | return GetProfileBaseAndData(user.user_uuid, profile, data); | ||
| 147 | } | ||
| 148 | |||
| 89 | }; // namespace Service::Account | 149 | }; // namespace Service::Account |
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index 5aa73a030..cb6239cc1 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h | |||
| @@ -54,7 +54,8 @@ struct ProfileInfo { | |||
| 54 | UUID user_uuid; | 54 | UUID user_uuid; |
| 55 | std::array<u8, 0x20> username; | 55 | std::array<u8, 0x20> username; |
| 56 | u64 creation_time; | 56 | u64 creation_time; |
| 57 | std::array<u8, MAX_DATA> data; | 57 | std::array<u8, MAX_DATA> data; // TODO(ognik): Work out what this is |
| 58 | bool is_open; | ||
| 58 | }; | 59 | }; |
| 59 | 60 | ||
| 60 | struct ProfileBase { | 61 | struct ProfileBase { |
| @@ -83,14 +84,24 @@ public: | |||
| 83 | bool GetProfileBase(size_t index, ProfileBase& profile); | 84 | bool GetProfileBase(size_t index, ProfileBase& profile); |
| 84 | bool GetProfileBase(UUID uuid, ProfileBase& profile); | 85 | bool GetProfileBase(UUID uuid, ProfileBase& profile); |
| 85 | bool GetProfileBase(ProfileInfo user, ProfileBase& profile); | 86 | bool GetProfileBase(ProfileInfo user, ProfileBase& profile); |
| 87 | bool GetProfileBaseAndData(size_t index, ProfileBase& profile, std::array<u8, MAX_DATA>& data); | ||
| 88 | bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, std::array<u8, MAX_DATA>& data); | ||
| 89 | bool GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, | ||
| 90 | std::array<u8, MAX_DATA>& data); | ||
| 86 | size_t GetUserCount(); | 91 | size_t GetUserCount(); |
| 87 | bool UserExists(UUID uuid); | 92 | bool UserExists(UUID uuid); |
| 93 | void OpenUser(UUID uuid); | ||
| 94 | void CloseUser(UUID uuid); | ||
| 95 | std::array<UUID, MAX_USERS> GetOpenUsers(); | ||
| 96 | std::array<UUID, MAX_USERS> GetAllUsers(); | ||
| 97 | const UUID& GetLastOpennedUser(); | ||
| 88 | 98 | ||
| 89 | private: | 99 | private: |
| 90 | std::array<ProfileInfo, MAX_USERS> profiles{}; | 100 | std::array<ProfileInfo, MAX_USERS> profiles{}; |
| 91 | size_t user_count = 0; | 101 | size_t user_count = 0; |
| 92 | size_t AddToProfiles(const ProfileInfo& profile); | 102 | size_t AddToProfiles(const ProfileInfo& profile); |
| 93 | bool RemoveProfileAtIdx(size_t index); | 103 | bool RemoveProfileAtIdx(size_t index); |
| 104 | UUID last_openned_user{0, 0}; | ||
| 94 | }; | 105 | }; |
| 95 | using ProfileManagerPtr = std::unique_ptr<ProfileManager>; | 106 | using ProfileManagerPtr = std::unique_ptr<ProfileManager>; |
| 96 | 107 | ||