diff options
Diffstat (limited to 'src/core')
| -rw-r--r-- | src/core/hle/service/acc/acc.cpp | 7 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.cpp | 60 | ||||
| -rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 20 |
3 files changed, 47 insertions, 40 deletions
diff --git a/src/core/hle/service/acc/acc.cpp b/src/core/hle/service/acc/acc.cpp index c9ab8311e..b94dda9ea 100644 --- a/src/core/hle/service/acc/acc.cpp +++ b/src/core/hle/service/acc/acc.cpp | |||
| @@ -54,6 +54,8 @@ private: | |||
| 54 | rb.Push(RESULT_SUCCESS); | 54 | rb.Push(RESULT_SUCCESS); |
| 55 | rb.PushRaw(profile_base); | 55 | rb.PushRaw(profile_base); |
| 56 | } else { | 56 | } else { |
| 57 | LOG_ERROR(Service_ACC, "Failed to get profile base and data for user={}", | ||
| 58 | user_id.Format()); | ||
| 57 | IPC::ResponseBuilder rb{ctx, 2}; | 59 | IPC::ResponseBuilder rb{ctx, 2}; |
| 58 | rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code | 60 | rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code |
| 59 | } | 61 | } |
| @@ -67,6 +69,7 @@ private: | |||
| 67 | rb.Push(RESULT_SUCCESS); | 69 | rb.Push(RESULT_SUCCESS); |
| 68 | rb.PushRaw(profile_base); | 70 | rb.PushRaw(profile_base); |
| 69 | } else { | 71 | } else { |
| 72 | LOG_ERROR(Service_ACC, "Failed to get profile base for user={}", user_id.Format()); | ||
| 70 | IPC::ResponseBuilder rb{ctx, 2}; | 73 | IPC::ResponseBuilder rb{ctx, 2}; |
| 71 | rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code | 74 | rb.Push(ResultCode(-1)); // TODO(ogniK): Get actual error code |
| 72 | } | 75 | } |
| @@ -93,7 +96,7 @@ private: | |||
| 93 | rb.Push<u32>(jpeg_size); | 96 | rb.Push<u32>(jpeg_size); |
| 94 | } | 97 | } |
| 95 | 98 | ||
| 96 | ProfileManager& profile_manager; | 99 | const ProfileManager& profile_manager; |
| 97 | UUID user_id; ///< The user id this profile refers to. | 100 | UUID user_id; ///< The user id this profile refers to. |
| 98 | }; | 101 | }; |
| 99 | 102 | ||
| @@ -202,7 +205,7 @@ void Module::Interface::GetBaasAccountManagerForApplication(Kernel::HLERequestCo | |||
| 202 | Module::Interface::Interface(std::shared_ptr<Module> module, | 205 | Module::Interface::Interface(std::shared_ptr<Module> module, |
| 203 | std::shared_ptr<ProfileManager> profile_manager, const char* name) | 206 | std::shared_ptr<ProfileManager> profile_manager, const char* name) |
| 204 | : ServiceFramework(name), module(std::move(module)), | 207 | : ServiceFramework(name), module(std::move(module)), |
| 205 | profile_manager(std::make_shared<ProfileManager>(*profile_manager)) {} | 208 | profile_manager(std::move(profile_manager)) {} |
| 206 | 209 | ||
| 207 | void InstallInterfaces(SM::ServiceManager& service_manager) { | 210 | void InstallInterfaces(SM::ServiceManager& service_manager) { |
| 208 | auto module = std::make_shared<Module>(); | 211 | auto module = std::make_shared<Module>(); |
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp index e8f6884d1..ee13ae3cd 100644 --- a/src/core/hle/service/acc/profile_manager.cpp +++ b/src/core/hle/service/acc/profile_manager.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2 or any later version | 2 | // Licensed under GPLv2 or any later version |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <boost/optional.hpp> | ||
| 5 | #include "core/hle/service/acc/profile_manager.h" | 6 | #include "core/hle/service/acc/profile_manager.h" |
| 6 | #include "core/settings.h" | 7 | #include "core/settings.h" |
| 7 | 8 | ||
| @@ -12,20 +13,21 @@ constexpr ResultCode ERROR_USER_ALREADY_EXISTS(ErrorModule::Account, -2); | |||
| 12 | constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); | 13 | constexpr ResultCode ERROR_ARGUMENT_IS_NULL(ErrorModule::Account, 20); |
| 13 | 14 | ||
| 14 | ProfileManager::ProfileManager() { | 15 | ProfileManager::ProfileManager() { |
| 16 | // TODO(ogniK): Create the default user we have for now until loading/saving users is added | ||
| 15 | auto user_uuid = UUID{1, 0}; | 17 | auto user_uuid = UUID{1, 0}; |
| 16 | CreateNewUser(user_uuid, Settings::values.username); | 18 | CreateNewUser(user_uuid, Settings::values.username); |
| 17 | OpenUser(user_uuid); | 19 | OpenUser(user_uuid); |
| 18 | } | 20 | } |
| 19 | 21 | ||
| 20 | size_t ProfileManager::AddToProfiles(const ProfileInfo& user) { | 22 | boost::optional<size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) { |
| 21 | if (user_count >= MAX_USERS) { | 23 | if (user_count >= MAX_USERS) { |
| 22 | return std::numeric_limits<size_t>::max(); | 24 | return boost::none; |
| 23 | } | 25 | } |
| 24 | profiles[user_count] = std::move(user); | 26 | profiles[user_count] = std::move(user); |
| 25 | return user_count++; | 27 | return user_count++; |
| 26 | } | 28 | } |
| 27 | 29 | ||
| 28 | bool ProfileManager::RemoveProfileAtIdx(size_t index) { | 30 | bool ProfileManager::RemoveProfileAtIndex(size_t index) { |
| 29 | if (index >= MAX_USERS || index >= user_count) { | 31 | if (index >= MAX_USERS || index >= user_count) { |
| 30 | return false; | 32 | return false; |
| 31 | } | 33 | } |
| @@ -38,7 +40,7 @@ bool ProfileManager::RemoveProfileAtIdx(size_t index) { | |||
| 38 | } | 40 | } |
| 39 | 41 | ||
| 40 | ResultCode ProfileManager::AddUser(ProfileInfo user) { | 42 | ResultCode ProfileManager::AddUser(ProfileInfo user) { |
| 41 | if (AddToProfiles(user) == std::numeric_limits<size_t>::max()) { | 43 | if (AddToProfiles(user) == boost::none) { |
| 42 | return ERROR_TOO_MANY_USERS; | 44 | return ERROR_TOO_MANY_USERS; |
| 43 | } | 45 | } |
| 44 | return RESULT_SUCCESS; | 46 | return RESULT_SUCCESS; |
| @@ -58,13 +60,13 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& userna | |||
| 58 | [&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) { | 60 | [&uuid](const ProfileInfo& profile) { return uuid == profile.user_uuid; })) { |
| 59 | return ERROR_USER_ALREADY_EXISTS; | 61 | return ERROR_USER_ALREADY_EXISTS; |
| 60 | } | 62 | } |
| 61 | ProfileInfo prof_inf; | 63 | ProfileInfo profile; |
| 62 | prof_inf.user_uuid = std::move(uuid); | 64 | profile.user_uuid = std::move(uuid); |
| 63 | prof_inf.username = std::move(username); | 65 | profile.username = std::move(username); |
| 64 | prof_inf.data = std::array<u8, MAX_DATA>(); | 66 | profile.data = {}; |
| 65 | prof_inf.creation_time = 0x0; | 67 | profile.creation_time = 0x0; |
| 66 | prof_inf.is_open = false; | 68 | profile.is_open = false; |
| 67 | return AddUser(prof_inf); | 69 | return AddUser(profile); |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) { | 72 | ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) { |
| @@ -77,28 +79,27 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) | |||
| 77 | return CreateNewUser(uuid, username_output); | 79 | return CreateNewUser(uuid, username_output); |
| 78 | } | 80 | } |
| 79 | 81 | ||
| 80 | size_t ProfileManager::GetUserIndex(const UUID& uuid) const { | 82 | boost::optional<size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { |
| 81 | if (!uuid) { | 83 | if (!uuid) { |
| 82 | return std::numeric_limits<size_t>::max(); | 84 | return boost::none; |
| 83 | } | 85 | } |
| 84 | auto iter = std::find_if(profiles.begin(), profiles.end(), | 86 | auto iter = std::find_if(profiles.begin(), profiles.end(), |
| 85 | [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; }); | 87 | [&uuid](const ProfileInfo& p) { return p.user_uuid == uuid; }); |
| 86 | if (iter == profiles.end()) { | 88 | if (iter == profiles.end()) { |
| 87 | return std::numeric_limits<size_t>::max(); | 89 | return boost::none; |
| 88 | } | 90 | } |
| 89 | return static_cast<size_t>(std::distance(profiles.begin(), iter)); | 91 | return static_cast<size_t>(std::distance(profiles.begin(), iter)); |
| 90 | } | 92 | } |
| 91 | 93 | ||
| 92 | size_t ProfileManager::GetUserIndex(ProfileInfo user) const { | 94 | boost::optional<size_t> ProfileManager::GetUserIndex(ProfileInfo user) const { |
| 93 | return GetUserIndex(user.user_uuid); | 95 | return GetUserIndex(user.user_uuid); |
| 94 | } | 96 | } |
| 95 | 97 | ||
| 96 | bool ProfileManager::GetProfileBase(size_t index, ProfileBase& profile) const { | 98 | bool ProfileManager::GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const { |
| 97 | if (index >= MAX_USERS) { | 99 | if (index == boost::none || index >= MAX_USERS) { |
| 98 | profile.Invalidate(); | ||
| 99 | return false; | 100 | return false; |
| 100 | } | 101 | } |
| 101 | const auto& prof_info = profiles[index]; | 102 | const auto& prof_info = profiles[index.get()]; |
| 102 | profile.user_uuid = prof_info.user_uuid; | 103 | profile.user_uuid = prof_info.user_uuid; |
| 103 | profile.username = prof_info.username; | 104 | profile.username = prof_info.username; |
| 104 | profile.timestamp = prof_info.creation_time; | 105 | profile.timestamp = prof_info.creation_time; |
| @@ -124,24 +125,24 @@ size_t ProfileManager::GetOpenUserCount() const { | |||
| 124 | } | 125 | } |
| 125 | 126 | ||
| 126 | bool ProfileManager::UserExists(UUID uuid) const { | 127 | bool ProfileManager::UserExists(UUID uuid) const { |
| 127 | return (GetUserIndex(uuid) != std::numeric_limits<size_t>::max()); | 128 | return (GetUserIndex(uuid) != boost::none); |
| 128 | } | 129 | } |
| 129 | 130 | ||
| 130 | void ProfileManager::OpenUser(UUID uuid) { | 131 | void ProfileManager::OpenUser(UUID uuid) { |
| 131 | auto idx = GetUserIndex(uuid); | 132 | auto idx = GetUserIndex(uuid); |
| 132 | if (idx == std::numeric_limits<size_t>::max()) { | 133 | if (idx == boost::none) { |
| 133 | return; | 134 | return; |
| 134 | } | 135 | } |
| 135 | profiles[idx].is_open = true; | 136 | profiles[idx.get()].is_open = true; |
| 136 | last_opened_user = uuid; | 137 | last_opened_user = uuid; |
| 137 | } | 138 | } |
| 138 | 139 | ||
| 139 | void ProfileManager::CloseUser(UUID uuid) { | 140 | void ProfileManager::CloseUser(UUID uuid) { |
| 140 | auto idx = GetUserIndex(uuid); | 141 | auto idx = GetUserIndex(uuid); |
| 141 | if (idx == std::numeric_limits<size_t>::max()) { | 142 | if (idx == boost::none) { |
| 142 | return; | 143 | return; |
| 143 | } | 144 | } |
| 144 | profiles[idx].is_open = false; | 145 | profiles[idx.get()].is_open = false; |
| 145 | } | 146 | } |
| 146 | 147 | ||
| 147 | std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const { | 148 | std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const { |
| @@ -166,22 +167,23 @@ UUID ProfileManager::GetLastOpenedUser() const { | |||
| 166 | return last_opened_user; | 167 | return last_opened_user; |
| 167 | } | 168 | } |
| 168 | 169 | ||
| 169 | bool ProfileManager::GetProfileBaseAndData(size_t index, ProfileBase& profile, | 170 | bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, |
| 170 | std::array<u8, MAX_DATA>& data) { | 171 | std::array<u8, MAX_DATA>& data) const { |
| 171 | if (GetProfileBase(index, profile)) { | 172 | if (GetProfileBase(index, profile)) { |
| 172 | std::memcpy(data.data(), profiles[index].data.data(), MAX_DATA); | 173 | std::memcpy(data.data(), profiles[index.get()].data.data(), MAX_DATA); |
| 173 | return true; | 174 | return true; |
| 174 | } | 175 | } |
| 175 | return false; | 176 | return false; |
| 176 | } | 177 | } |
| 178 | |||
| 177 | bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile, | 179 | bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile, |
| 178 | std::array<u8, MAX_DATA>& data) { | 180 | std::array<u8, MAX_DATA>& data) const { |
| 179 | auto idx = GetUserIndex(uuid); | 181 | auto idx = GetUserIndex(uuid); |
| 180 | return GetProfileBaseAndData(idx, profile, data); | 182 | return GetProfileBaseAndData(idx, profile, data); |
| 181 | } | 183 | } |
| 182 | 184 | ||
| 183 | bool ProfileManager::GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, | 185 | bool ProfileManager::GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, |
| 184 | std::array<u8, MAX_DATA>& data) { | 186 | std::array<u8, MAX_DATA>& data) const { |
| 185 | return GetProfileBaseAndData(user.user_uuid, profile, data); | 187 | return GetProfileBaseAndData(user.user_uuid, profile, data); |
| 186 | } | 188 | } |
| 187 | 189 | ||
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index 1815d520d..d86a7a226 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h | |||
| @@ -5,6 +5,7 @@ | |||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include "boost/optional.hpp" | ||
| 8 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 9 | #include "common/swap.h" | 10 | #include "common/swap.h" |
| 10 | #include "core/hle/result.h" | 11 | #include "core/hle/result.h" |
| @@ -82,15 +83,17 @@ public: | |||
| 82 | ResultCode AddUser(ProfileInfo user); | 83 | ResultCode AddUser(ProfileInfo user); |
| 83 | ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username); | 84 | ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username); |
| 84 | ResultCode CreateNewUser(UUID uuid, const std::string& username); | 85 | ResultCode CreateNewUser(UUID uuid, const std::string& username); |
| 85 | size_t GetUserIndex(const UUID& uuid) const; | 86 | boost::optional<size_t> GetUserIndex(const UUID& uuid) const; |
| 86 | size_t GetUserIndex(ProfileInfo user) const; | 87 | boost::optional<size_t> GetUserIndex(ProfileInfo user) const; |
| 87 | bool GetProfileBase(size_t index, ProfileBase& profile) const; | 88 | bool GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const; |
| 88 | bool GetProfileBase(UUID uuid, ProfileBase& profile) const; | 89 | bool GetProfileBase(UUID uuid, ProfileBase& profile) const; |
| 89 | bool GetProfileBase(ProfileInfo user, ProfileBase& profile) const; | 90 | bool GetProfileBase(ProfileInfo user, ProfileBase& profile) const; |
| 90 | bool GetProfileBaseAndData(size_t index, ProfileBase& profile, std::array<u8, MAX_DATA>& data); | 91 | bool GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, |
| 91 | bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, std::array<u8, MAX_DATA>& data); | 92 | std::array<u8, MAX_DATA>& data) const; |
| 93 | bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, | ||
| 94 | std::array<u8, MAX_DATA>& data) const; | ||
| 92 | bool GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, | 95 | bool GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, |
| 93 | std::array<u8, MAX_DATA>& data); | 96 | std::array<u8, MAX_DATA>& data) const; |
| 94 | size_t GetUserCount() const; | 97 | size_t GetUserCount() const; |
| 95 | size_t GetOpenUserCount() const; | 98 | size_t GetOpenUserCount() const; |
| 96 | bool UserExists(UUID uuid) const; | 99 | bool UserExists(UUID uuid) const; |
| @@ -105,10 +108,9 @@ public: | |||
| 105 | private: | 108 | private: |
| 106 | std::array<ProfileInfo, MAX_USERS> profiles{}; | 109 | std::array<ProfileInfo, MAX_USERS> profiles{}; |
| 107 | size_t user_count = 0; | 110 | size_t user_count = 0; |
| 108 | size_t AddToProfiles(const ProfileInfo& profile); | 111 | boost::optional<size_t> AddToProfiles(const ProfileInfo& profile); |
| 109 | bool RemoveProfileAtIdx(size_t index); | 112 | bool RemoveProfileAtIndex(size_t index); |
| 110 | UUID last_opened_user{0, 0}; | 113 | UUID last_opened_user{0, 0}; |
| 111 | }; | 114 | }; |
| 112 | using ProfileManagerPtr = std::unique_ptr<ProfileManager>; | ||
| 113 | 115 | ||
| 114 | }; // namespace Service::Account | 116 | }; // namespace Service::Account |