summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar David Marcec2018-08-12 01:51:31 +1000
committerGravatar David Marcec2018-08-12 01:51:31 +1000
commit2592e41301b39db27730b148e7dbfd41d83864c2 (patch)
treedd3595851c65c982757b58d438545edf8acc60ad /src
parentCode cleanup for profile manager (diff)
downloadyuzu-2592e41301b39db27730b148e7dbfd41d83864c2.tar.gz
yuzu-2592e41301b39db27730b148e7dbfd41d83864c2.tar.xz
yuzu-2592e41301b39db27730b148e7dbfd41d83864c2.zip
Added better explanations in the profile manager
Diffstat (limited to 'src')
-rw-r--r--src/core/hle/service/acc/profile_manager.cpp32
-rw-r--r--src/core/hle/service/acc/profile_manager.h3
2 files changed, 34 insertions, 1 deletions
diff --git a/src/core/hle/service/acc/profile_manager.cpp b/src/core/hle/service/acc/profile_manager.cpp
index ee13ae3cd..62c2121fa 100644
--- a/src/core/hle/service/acc/profile_manager.cpp
+++ b/src/core/hle/service/acc/profile_manager.cpp
@@ -19,6 +19,8 @@ ProfileManager::ProfileManager() {
19 OpenUser(user_uuid); 19 OpenUser(user_uuid);
20} 20}
21 21
22/// After a users creation it needs to be "registered" to the system. AddToProfiles handles the
23/// internal management of the users profiles
22boost::optional<size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) { 24boost::optional<size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) {
23 if (user_count >= MAX_USERS) { 25 if (user_count >= MAX_USERS) {
24 return boost::none; 26 return boost::none;
@@ -27,6 +29,7 @@ boost::optional<size_t> ProfileManager::AddToProfiles(const ProfileInfo& user) {
27 return user_count++; 29 return user_count++;
28} 30}
29 31
32/// Deletes a specific profile based on it's profile index
30bool ProfileManager::RemoveProfileAtIndex(size_t index) { 33bool ProfileManager::RemoveProfileAtIndex(size_t index) {
31 if (index >= MAX_USERS || index >= user_count) { 34 if (index >= MAX_USERS || index >= user_count) {
32 return false; 35 return false;
@@ -39,6 +42,7 @@ bool ProfileManager::RemoveProfileAtIndex(size_t index) {
39 return true; 42 return true;
40} 43}
41 44
45/// Helper function to register a user to the system
42ResultCode ProfileManager::AddUser(ProfileInfo user) { 46ResultCode ProfileManager::AddUser(ProfileInfo user) {
43 if (AddToProfiles(user) == boost::none) { 47 if (AddToProfiles(user) == boost::none) {
44 return ERROR_TOO_MANY_USERS; 48 return ERROR_TOO_MANY_USERS;
@@ -46,6 +50,8 @@ ResultCode ProfileManager::AddUser(ProfileInfo user) {
46 return RESULT_SUCCESS; 50 return RESULT_SUCCESS;
47} 51}
48 52
53/// Create a new user on the system. If the uuid of the user already exists, the user is not
54/// created.
49ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& username) { 55ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& username) {
50 if (user_count == MAX_USERS) { 56 if (user_count == MAX_USERS) {
51 return ERROR_TOO_MANY_USERS; 57 return ERROR_TOO_MANY_USERS;
@@ -62,13 +68,16 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, std::array<u8, 0x20>& userna
62 } 68 }
63 ProfileInfo profile; 69 ProfileInfo profile;
64 profile.user_uuid = std::move(uuid); 70 profile.user_uuid = std::move(uuid);
65 profile.username = std::move(username); 71 profile.username = username;
66 profile.data = {}; 72 profile.data = {};
67 profile.creation_time = 0x0; 73 profile.creation_time = 0x0;
68 profile.is_open = false; 74 profile.is_open = false;
69 return AddUser(profile); 75 return AddUser(profile);
70} 76}
71 77
78/// Creates a new user on the system. This function allows a much simpler method of registration
79/// specifically by allowing an std::string for the username. This is required specifically since
80/// we're loading a string straight from the config
72ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) { 81ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) {
73 std::array<u8, 0x20> username_output; 82 std::array<u8, 0x20> username_output;
74 if (username.size() > username_output.size()) { 83 if (username.size() > username_output.size()) {
@@ -79,6 +88,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username)
79 return CreateNewUser(uuid, username_output); 88 return CreateNewUser(uuid, username_output);
80} 89}
81 90
91/// Returns a users profile index based on their user id.
82boost::optional<size_t> ProfileManager::GetUserIndex(const UUID& uuid) const { 92boost::optional<size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
83 if (!uuid) { 93 if (!uuid) {
84 return boost::none; 94 return boost::none;
@@ -91,10 +101,12 @@ boost::optional<size_t> ProfileManager::GetUserIndex(const UUID& uuid) const {
91 return static_cast<size_t>(std::distance(profiles.begin(), iter)); 101 return static_cast<size_t>(std::distance(profiles.begin(), iter));
92} 102}
93 103
104/// Returns a users profile index based on their profile
94boost::optional<size_t> ProfileManager::GetUserIndex(ProfileInfo user) const { 105boost::optional<size_t> ProfileManager::GetUserIndex(ProfileInfo user) const {
95 return GetUserIndex(user.user_uuid); 106 return GetUserIndex(user.user_uuid);
96} 107}
97 108
109/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
98bool ProfileManager::GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const { 110bool ProfileManager::GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const {
99 if (index == boost::none || index >= MAX_USERS) { 111 if (index == boost::none || index >= MAX_USERS) {
100 return false; 112 return false;
@@ -106,28 +118,37 @@ bool ProfileManager::GetProfileBase(boost::optional<size_t> index, ProfileBase&
106 return true; 118 return true;
107} 119}
108 120
121/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
109bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const { 122bool ProfileManager::GetProfileBase(UUID uuid, ProfileBase& profile) const {
110 auto idx = GetUserIndex(uuid); 123 auto idx = GetUserIndex(uuid);
111 return GetProfileBase(idx, profile); 124 return GetProfileBase(idx, profile);
112} 125}
113 126
127/// Returns the data structure used by the switch when GetProfileBase is called on acc:*
114bool ProfileManager::GetProfileBase(ProfileInfo user, ProfileBase& profile) const { 128bool ProfileManager::GetProfileBase(ProfileInfo user, ProfileBase& profile) const {
115 return GetProfileBase(user.user_uuid, profile); 129 return GetProfileBase(user.user_uuid, profile);
116} 130}
117 131
132/// Returns the current user count on the system. We keep a variable which tracks the count so we
133/// don't have to loop the internal profile array every call.
118size_t ProfileManager::GetUserCount() const { 134size_t ProfileManager::GetUserCount() const {
119 return user_count; 135 return user_count;
120} 136}
121 137
138/// Lists the current "opened" users on the system. Users are typically not open until they sign
139/// into something or pick a profile. As of right now users should all be open until qlaunch is
140/// booting
122size_t ProfileManager::GetOpenUserCount() const { 141size_t ProfileManager::GetOpenUserCount() const {
123 return std::count_if(profiles.begin(), profiles.end(), 142 return std::count_if(profiles.begin(), profiles.end(),
124 [](const ProfileInfo& p) { return p.is_open; }); 143 [](const ProfileInfo& p) { return p.is_open; });
125} 144}
126 145
146/// Checks if a user id exists in our profile manager
127bool ProfileManager::UserExists(UUID uuid) const { 147bool ProfileManager::UserExists(UUID uuid) const {
128 return (GetUserIndex(uuid) != boost::none); 148 return (GetUserIndex(uuid) != boost::none);
129} 149}
130 150
151/// Opens a specific user
131void ProfileManager::OpenUser(UUID uuid) { 152void ProfileManager::OpenUser(UUID uuid) {
132 auto idx = GetUserIndex(uuid); 153 auto idx = GetUserIndex(uuid);
133 if (idx == boost::none) { 154 if (idx == boost::none) {
@@ -137,6 +158,7 @@ void ProfileManager::OpenUser(UUID uuid) {
137 last_opened_user = uuid; 158 last_opened_user = uuid;
138} 159}
139 160
161/// Closes a specific user
140void ProfileManager::CloseUser(UUID uuid) { 162void ProfileManager::CloseUser(UUID uuid) {
141 auto idx = GetUserIndex(uuid); 163 auto idx = GetUserIndex(uuid);
142 if (idx == boost::none) { 164 if (idx == boost::none) {
@@ -145,6 +167,7 @@ void ProfileManager::CloseUser(UUID uuid) {
145 profiles[idx.get()].is_open = false; 167 profiles[idx.get()].is_open = false;
146} 168}
147 169
170/// Gets all valid user ids on the system
148std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const { 171std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const {
149 std::array<UUID, MAX_USERS> output; 172 std::array<UUID, MAX_USERS> output;
150 std::transform(profiles.begin(), profiles.end(), output.begin(), 173 std::transform(profiles.begin(), profiles.end(), output.begin(),
@@ -152,6 +175,8 @@ std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const {
152 return output; 175 return output;
153} 176}
154 177
178/// Get all the open users on the system and zero out the rest of the data. This is specifically
179/// needed for GetOpenUsers and we need to ensure the rest of the output buffer is zero'd out
155std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() const { 180std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() const {
156 std::array<UUID, MAX_USERS> output; 181 std::array<UUID, MAX_USERS> output;
157 std::transform(profiles.begin(), profiles.end(), output.begin(), [](const ProfileInfo& p) { 182 std::transform(profiles.begin(), profiles.end(), output.begin(), [](const ProfileInfo& p) {
@@ -163,10 +188,12 @@ std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() const {
163 return output; 188 return output;
164} 189}
165 190
191/// Returns the last user which was opened
166UUID ProfileManager::GetLastOpenedUser() const { 192UUID ProfileManager::GetLastOpenedUser() const {
167 return last_opened_user; 193 return last_opened_user;
168} 194}
169 195
196/// Return the users profile base and the unknown arbitary data.
170bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, 197bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile,
171 std::array<u8, MAX_DATA>& data) const { 198 std::array<u8, MAX_DATA>& data) const {
172 if (GetProfileBase(index, profile)) { 199 if (GetProfileBase(index, profile)) {
@@ -176,17 +203,20 @@ bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, Profil
176 return false; 203 return false;
177} 204}
178 205
206/// Return the users profile base and the unknown arbitary data.
179bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile, 207bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile,
180 std::array<u8, MAX_DATA>& data) const { 208 std::array<u8, MAX_DATA>& data) const {
181 auto idx = GetUserIndex(uuid); 209 auto idx = GetUserIndex(uuid);
182 return GetProfileBaseAndData(idx, profile, data); 210 return GetProfileBaseAndData(idx, profile, data);
183} 211}
184 212
213/// Return the users profile base and the unknown arbitary data.
185bool ProfileManager::GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, 214bool ProfileManager::GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile,
186 std::array<u8, MAX_DATA>& data) const { 215 std::array<u8, MAX_DATA>& data) const {
187 return GetProfileBaseAndData(user.user_uuid, profile, data); 216 return GetProfileBaseAndData(user.user_uuid, profile, data);
188} 217}
189 218
219/// Returns if the system is allowing user registrations or not
190bool ProfileManager::CanSystemRegisterUser() const { 220bool ProfileManager::CanSystemRegisterUser() const {
191 return false; // TODO(ogniK): Games shouldn't have 221 return false; // TODO(ogniK): Games shouldn't have
192 // access to user registration, when we 222 // access to user registration, when we
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h
index d86a7a226..908519095 100644
--- a/src/core/hle/service/acc/profile_manager.h
+++ b/src/core/hle/service/acc/profile_manager.h
@@ -42,6 +42,8 @@ struct UUID {
42 uuid[1] = (static_cast<u64>(std::rand()) << 32) | std::rand(); 42 uuid[1] = (static_cast<u64>(std::rand()) << 32) | std::rand();
43 return *this; 43 return *this;
44 } 44 }
45
46 // Set the UUID to {0,0} to be considered an invalid user
45 void Invalidate() { 47 void Invalidate() {
46 uuid = INVALID_UUID; 48 uuid = INVALID_UUID;
47 } 49 }
@@ -66,6 +68,7 @@ struct ProfileBase {
66 u64_le timestamp; 68 u64_le timestamp;
67 std::array<u8, 0x20> username; 69 std::array<u8, 0x20> username;
68 70
71 // Zero out all the fields to make the profile slot considered "Empty"
69 void Invalidate() { 72 void Invalidate() {
70 user_uuid.Invalidate(); 73 user_uuid.Invalidate();
71 timestamp = 0; 74 timestamp = 0;