yuzu-emu
/
yuzu-mainline
Archived
1
0
Fork 0

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.
This commit is contained in:
Lioncash 2018-08-20 18:02:16 -04:00
parent f9a26d468c
commit 38cd4e9c61
2 changed files with 22 additions and 19 deletions

View File

@ -62,7 +62,7 @@ ResultCode ProfileManager::AddUser(const ProfileInfo& user) {
/// Create a new user on the system. If the uuid of the user already exists, the user is not /// Create a new user on the system. If the uuid of the user already exists, the user is not
/// created. /// created.
ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::array<u8, 0x20>& username) { ResultCode ProfileManager::CreateNewUser(UUID uuid, const ProfileUsername& username) {
if (user_count == MAX_USERS) { if (user_count == MAX_USERS) {
return ERROR_TOO_MANY_USERS; return ERROR_TOO_MANY_USERS;
} }
@ -89,7 +89,7 @@ ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::array<u8, 0x20>&
/// specifically by allowing an std::string for the username. This is required specifically since /// specifically by allowing an std::string for the username. This is required specifically since
/// we're loading a string straight from the config /// we're loading a string straight from the config
ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) { ResultCode ProfileManager::CreateNewUser(UUID uuid, const std::string& username) {
std::array<u8, 0x20> username_output; ProfileUsername username_output;
if (username.size() > username_output.size()) { if (username.size() > username_output.size()) {
std::copy_n(username.begin(), username_output.size(), username_output.begin()); std::copy_n(username.begin(), username_output.size(), username_output.begin());
} else { } else {
@ -178,8 +178,8 @@ void ProfileManager::CloseUser(UUID uuid) {
} }
/// Gets all valid user ids on the system /// Gets all valid user ids on the system
std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const { UserIDArray ProfileManager::GetAllUsers() const {
std::array<UUID, MAX_USERS> output; UserIDArray output;
std::transform(profiles.begin(), profiles.end(), output.begin(), std::transform(profiles.begin(), profiles.end(), output.begin(),
[](const ProfileInfo& p) { return p.user_uuid; }); [](const ProfileInfo& p) { return p.user_uuid; });
return output; return output;
@ -187,8 +187,8 @@ std::array<UUID, MAX_USERS> ProfileManager::GetAllUsers() const {
/// Get all the open users on the system and zero out the rest of the data. This is specifically /// Get all the open users on the system and zero out the rest of the data. This is specifically
/// needed for GetOpenUsers and we need to ensure the rest of the output buffer is zero'd out /// needed for GetOpenUsers and we need to ensure the rest of the output buffer is zero'd out
std::array<UUID, MAX_USERS> ProfileManager::GetOpenUsers() const { UserIDArray ProfileManager::GetOpenUsers() const {
std::array<UUID, MAX_USERS> output; UserIDArray output;
std::transform(profiles.begin(), profiles.end(), output.begin(), [](const ProfileInfo& p) { std::transform(profiles.begin(), profiles.end(), output.begin(), [](const ProfileInfo& p) {
if (p.is_open) if (p.is_open)
return p.user_uuid; return p.user_uuid;
@ -205,7 +205,7 @@ UUID ProfileManager::GetLastOpenedUser() const {
/// Return the users profile base and the unknown arbitary data. /// Return the users profile base and the unknown arbitary data.
bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile,
std::array<u8, MAX_DATA>& data) const { ProfileData& data) const {
if (GetProfileBase(index, profile)) { if (GetProfileBase(index, profile)) {
std::memcpy(data.data(), profiles[index.get()].data.data(), MAX_DATA); std::memcpy(data.data(), profiles[index.get()].data.data(), MAX_DATA);
return true; return true;
@ -215,14 +215,14 @@ bool ProfileManager::GetProfileBaseAndData(boost::optional<size_t> index, Profil
/// Return the users profile base and the unknown arbitary data. /// Return the users profile base and the unknown arbitary data.
bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile, bool ProfileManager::GetProfileBaseAndData(UUID uuid, ProfileBase& profile,
std::array<u8, MAX_DATA>& data) const { ProfileData& data) const {
auto idx = GetUserIndex(uuid); auto idx = GetUserIndex(uuid);
return GetProfileBaseAndData(idx, profile, data); return GetProfileBaseAndData(idx, profile, data);
} }
/// Return the users profile base and the unknown arbitary data. /// Return the users profile base and the unknown arbitary data.
bool ProfileManager::GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, bool ProfileManager::GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
std::array<u8, MAX_DATA>& data) const { ProfileData& data) const {
return GetProfileBaseAndData(user.user_uuid, profile, data); return GetProfileBaseAndData(user.user_uuid, profile, data);
} }

View File

@ -48,20 +48,24 @@ struct UUID {
}; };
static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); static_assert(sizeof(UUID) == 16, "UUID is an invalid size!");
using ProfileUsername = std::array<u8, 0x20>;
using ProfileData = std::array<u8, MAX_DATA>;
using UserIDArray = std::array<UUID, MAX_USERS>;
/// This holds general information about a users profile. This is where we store all the information /// This holds general information about a users profile. This is where we store all the information
/// based on a specific user /// based on a specific user
struct ProfileInfo { struct ProfileInfo {
UUID user_uuid; UUID user_uuid;
std::array<u8, 0x20> username; ProfileUsername username;
u64 creation_time; u64 creation_time;
std::array<u8, MAX_DATA> data; // TODO(ognik): Work out what this is ProfileData data; // TODO(ognik): Work out what this is
bool is_open; bool is_open;
}; };
struct ProfileBase { struct ProfileBase {
UUID user_uuid; UUID user_uuid;
u64_le timestamp; u64_le timestamp;
std::array<u8, 0x20> username; ProfileUsername username;
// Zero out all the fields to make the profile slot considered "Empty" // Zero out all the fields to make the profile slot considered "Empty"
void Invalidate() { void Invalidate() {
@ -79,7 +83,7 @@ class ProfileManager {
public: public:
ProfileManager(); // TODO(ogniK): Load from system save ProfileManager(); // TODO(ogniK): Load from system save
ResultCode AddUser(const ProfileInfo& user); ResultCode AddUser(const ProfileInfo& user);
ResultCode CreateNewUser(UUID uuid, const std::array<u8, 0x20>& username); ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username);
ResultCode CreateNewUser(UUID uuid, const std::string& username); ResultCode CreateNewUser(UUID uuid, const std::string& username);
boost::optional<size_t> GetUserIndex(const UUID& uuid) const; boost::optional<size_t> GetUserIndex(const UUID& uuid) const;
boost::optional<size_t> GetUserIndex(const ProfileInfo& user) const; boost::optional<size_t> GetUserIndex(const ProfileInfo& user) const;
@ -87,18 +91,17 @@ public:
bool GetProfileBase(UUID uuid, ProfileBase& profile) const; bool GetProfileBase(UUID uuid, ProfileBase& profile) const;
bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const;
bool GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, bool GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile,
std::array<u8, MAX_DATA>& data) const; ProfileData& data) const;
bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const;
std::array<u8, MAX_DATA>& data) const;
bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile,
std::array<u8, MAX_DATA>& data) const; ProfileData& data) const;
size_t GetUserCount() const; size_t GetUserCount() const;
size_t GetOpenUserCount() const; size_t GetOpenUserCount() const;
bool UserExists(UUID uuid) const; bool UserExists(UUID uuid) const;
void OpenUser(UUID uuid); void OpenUser(UUID uuid);
void CloseUser(UUID uuid); void CloseUser(UUID uuid);
std::array<UUID, MAX_USERS> GetOpenUsers() const; UserIDArray GetOpenUsers() const;
std::array<UUID, MAX_USERS> GetAllUsers() const; UserIDArray GetAllUsers() const;
UUID GetLastOpenedUser() const; UUID GetLastOpenedUser() const;
bool CanSystemRegisterUser() const; bool CanSystemRegisterUser() const;