summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar Lioncash2018-08-20 18:02:16 -0400
committerGravatar Lioncash2018-08-20 19:48:57 -0400
commit38cd4e9c6100cb21c5b8a621d1ee204d61b031ca (patch)
tree71a12b1c75b455f83fa183201146b1081fe58ce1 /src
parentprofile_manager: Take ProfileInfo by const reference where applicable (diff)
downloadyuzu-38cd4e9c6100cb21c5b8a621d1ee204d61b031ca.tar.gz
yuzu-38cd4e9c6100cb21c5b8a621d1ee204d61b031ca.tar.xz
yuzu-38cd4e9c6100cb21c5b8a621d1ee204d61b031ca.zip
profile_manager: Use type aliases for username data, profile data, and user arrays
Avoids the need to repeatedly specify the whole array type in multiple places.
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp18
-rw-r--r--src/core/hle/service/acc/profile_manager.h23
2 files changed, 22 insertions, 19 deletions
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index beba92f64..f34f5af97 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -62,7 +62,7 @@ ResultCode ProfileManager::AddUser(const ProfileInfo& user) {
62 62
63/// Create a new user on the system. If the uuid of the user already exists, the user is not 63/// Create a new user on the system. If the uuid of the user already exists, the user is not
64/// created. 64/// created.
65ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::array<u8, 0x20>& username) { 65ResultCode ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& username) {
66 if (user_count == MAX_USERS) { 66 if (user_count == MAX_USERS) {
67 return ERROR_TOO_MANY_USERS; 67 return ERROR_TOO_MANY_USERS;
68 } 68 }
@@ -89,7 +89,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::array<u8, 0x20>&
89/// specifically by allowing an std::string for the username. This is required specifically since 89/// specifically by allowing an std::string for the username. This is required specifically since
90/// we're loading a string straight from the config 90/// we're loading a string straight from the config
91ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) { 91ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) {
92 std::array<u8, 0x20> username_output; 92 ProfileUsername username_output;
93 if (username.size() > username_output.size()) { 93 if (username.size() > username_output.size()) {
94 std::copy_n(username.begin(), username_output.size(), username_output.begin()); 94 std::copy_n(username.begin(), username_output.size(), username_output.begin());
95 } else { 95 } else {
@@ -178,8 +178,8 @@ void ProfileManager::CloseUser(UUID uuid) {
178} 178}
179 179
180/// Gets all valid user ids on the system 180/// Gets all valid user ids on the system
181std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const { 181UserIDArray ProfileManager::GetAllUsers() const {
182 std::array<UUID, MAX_USERS> output; 182 UserIDArray output;
183 std::transform(profiles.begin(), profiles.end(), output.begin(), 183 std::transform(profiles.begin(), profiles.end(), output.begin(),
184 [](const ProfileInfo& p) { return p.user_uuid; }); 184 [](const ProfileInfo& p) { return p.user_uuid; });
185 return output; 185 return output;
@@ -187,8 +187,8 @@ std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const {
187 187
188/// Get all the open users on the system and zero out the rest of the data. This is specifically 188/// Get all the open users on the system and zero out the rest of the data. This is specifically
189/// needed for GetOpenUsers and we need to ensure the rest of the output buffer is zero'd out 189/// needed for GetOpenUsers and we need to ensure the rest of the output buffer is zero'd out
190std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() const { 190UserIDArray ProfileManager::GetOpenUsers() const {
191 std::array<UUID, MAX_USERS> output; 191 UserIDArray output;
192 std::transform(profiles.begin(), profiles.end(), output.begin(), [](const ProfileInfo& p) { 192 std::transform(profiles.begin(), profiles.end(), output.begin(), [](const ProfileInfo& p) {
193 if (p.is_open) 193 if (p.is_open)
194 return p.user_uuid; 194 return p.user_uuid;
@@ -205,7 +205,7 @@ UUID ProfileManager::GetLastOpenedUser() const {
205 205
206/// Return the users profile base and the unknown arbitary data. 206/// Return the users profile base and the unknown arbitary data.
207bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, 207bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile,
208 std::array<u8, MAX_DATA>& data) const { 208 ProfileData& data) const {
209 if (GetProfileBase(index, profile)) { 209 if (GetProfileBase(index, profile)) {
210 std::memcpy(data.data(), profiles[index.get()].data.data(), MAX_DATA); 210 std::memcpy(data.data(), profiles[index.get()].data.data(), MAX_DATA);
211 return true; 211 return true;
@@ -215,14 +215,14 @@ bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, Profil
215 215
216/// Return the users profile base and the unknown arbitary data. 216/// Return the users profile base and the unknown arbitary data.
217bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile, 217bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile,
218 std::array<u8, MAX_DATA>& data) const { 218 ProfileData& data) const {
219 auto idx = GetUserIndex(uuid); 219 auto idx = GetUserIndex(uuid);
220 return GetProfileBaseAndData(idx, profile, data); 220 return GetProfileBaseAndData(idx, profile, data);
221} 221}
222 222
223/// Return the users profile base and the unknown arbitary data. 223/// Return the users profile base and the unknown arbitary data.
224bool ProfileManager::GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, 224bool ProfileManager::GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
225 std::array<u8, MAX_DATA>& data) const { 225 ProfileData& data) const {
226 return GetProfileBaseAndData(user.user_uuid, profile, data); 226 return GetProfileBaseAndData(user.user_uuid, profile, data);
227} 227}
228 228
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h
index d38f67188..cb06e6fa6 100644
--- a/src/core/hle/service/acc/profile_manager.h
+++ b/src/core/hle/service/acc/profile_manager.h
@@ -48,20 +48,24 @@ struct UUID {
48}; 48};
49static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); 49static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
50 50
51using ProfileUsername = std::array<u8, 0x20>;
52using ProfileData = std::array<u8, MAX_DATA>;
53using UserIDArray = std::array<UUID, MAX_USERS>;
54
51/// This holds general information about a users profile. This is where we store all the information 55/// This holds general information about a users profile. This is where we store all the information
52/// based on a specific user 56/// based on a specific user
53struct ProfileInfo { 57struct ProfileInfo {
54 UUID user_uuid; 58 UUID user_uuid;
55 std::array<u8, 0x20> username; 59 ProfileUsername username;
56 u64 creation_time; 60 u64 creation_time;
57 std::array<u8, MAX_DATA> data; // TODO(ognik): Work out what this is 61 ProfileData data; // TODO(ognik): Work out what this is
58 bool is_open; 62 bool is_open;
59}; 63};
60 64
61struct ProfileBase { 65struct ProfileBase {
62 UUID user_uuid; 66 UUID user_uuid;
63 u64_le timestamp; 67 u64_le timestamp;
64 std::array<u8, 0x20> username; 68 ProfileUsername username;
65 69
66 // Zero out all the fields to make the profile slot considered "Empty" 70 // Zero out all the fields to make the profile slot considered "Empty"
67 void Invalidate() { 71 void Invalidate() {
@@ -79,7 +83,7 @@ class ProfileManager {
79public: 83public:
80 ProfileManager(); // TODO(ogniK): Load from system save 84 ProfileManager(); // TODO(ogniK): Load from system save
81 ResultCode AddUser(const ProfileInfo& user); 85 ResultCode AddUser(const ProfileInfo& user);
82 ResultCode CreateNewUser(UUID uuid, const std::array<u8, 0x20>& username); 86 ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username);
83 ResultCode CreateNewUser(UUID uuid, const std::string& username); 87 ResultCode CreateNewUser(UUID uuid, const std::string& username);
84 boost::optional<size_t> GetUserIndex(const UUID& uuid) const; 88 boost::optional<size_t> GetUserIndex(const UUID& uuid) const;
85 boost::optional<size_t> GetUserIndex(const ProfileInfo& user) const; 89 boost::optional<size_t> GetUserIndex(const ProfileInfo& user) const;
@@ -87,18 +91,17 @@ public:
87 bool GetProfileBase(UUID uuid, ProfileBase& profile) const; 91 bool GetProfileBase(UUID uuid, ProfileBase& profile) const;
88 bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; 92 bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;
89 bool GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, 93 bool GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile,
90 std::array<u8, MAX_DATA>& data) const; 94 ProfileData& data) const;
91 bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, 95 bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const;
92 std::array<u8, MAX_DATA>& data) const;
93 bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, 96 bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
94 std::array<u8, MAX_DATA>& data) const; 97 ProfileData& data) const;
95 size_t GetUserCount() const; 98 size_t GetUserCount() const;
96 size_t GetOpenUserCount() const; 99 size_t GetOpenUserCount() const;
97 bool UserExists(UUID uuid) const; 100 bool UserExists(UUID uuid) const;
98 void OpenUser(UUID uuid); 101 void OpenUser(UUID uuid);
99 void CloseUser(UUID uuid); 102 void CloseUser(UUID uuid);
100 std::array<UUID, MAX_USERS> GetOpenUsers() const; 103 UserIDArray GetOpenUsers() const;
101 std::array<UUID, MAX_USERS> GetAllUsers() const; 104 UserIDArray GetAllUsers() const;
102 UUID GetLastOpenedUser() const; 105 UUID GetLastOpenedUser() const;
103 106
104 bool CanSystemRegisterUser() const; 107 bool CanSystemRegisterUser() const;