diff options
Diffstat (limited to 'src/core/hle/service/acc/profile_manager.h')
-rw-r--r-- | src/core/hle/service/acc/profile_manager.h | 57 |
1 files changed, 25 insertions, 32 deletions
diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index 314bccbf9..52967844d 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h @@ -5,7 +5,7 @@ #pragma once #include <array> -#include <random> + #include "boost/optional.hpp" #include "common/common_types.h" #include "common/swap.h" @@ -14,23 +14,21 @@ namespace Service::Account { constexpr size_t MAX_USERS = 8; constexpr size_t MAX_DATA = 128; -static const u128 INVALID_UUID = {0, 0}; +constexpr u128 INVALID_UUID{{0, 0}}; struct UUID { // UUIDs which are 0 are considered invalid! u128 uuid = INVALID_UUID; UUID() = default; explicit UUID(const u128& id) : uuid{id} {} - explicit UUID(const u64 lo, const u64 hi) { - uuid[0] = lo; - uuid[1] = hi; - }; + explicit UUID(const u64 lo, const u64 hi) : uuid{{lo, hi}} {} + explicit operator bool() const { - return uuid[0] != INVALID_UUID[0] || uuid[1] != INVALID_UUID[1]; + return uuid != INVALID_UUID; } bool operator==(const UUID& rhs) const { - return std::tie(uuid[0], uuid[1]) == std::tie(rhs.uuid[0], rhs.uuid[1]); + return uuid == rhs.uuid; } bool operator!=(const UUID& rhs) const { @@ -38,15 +36,7 @@ struct UUID { } // TODO(ogniK): Properly generate uuids based on RFC-4122 - const UUID& Generate() { - std::random_device device; - std::mt19937 gen(device()); - std::uniform_int_distribution<uint64_t> distribution(1, - std::numeric_limits<uint64_t>::max()); - uuid[0] = distribution(gen); - uuid[1] = distribution(gen); - return *this; - } + const UUID& Generate(); // Set the UUID to {0,0} to be considered an invalid user void Invalidate() { @@ -58,20 +48,24 @@ struct UUID { }; 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 /// based on a specific user struct ProfileInfo { UUID user_uuid; - std::array<u8, 0x20> username; + ProfileUsername username; 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; }; struct ProfileBase { UUID user_uuid; u64_le timestamp; - std::array<u8, 0x20> username; + ProfileUsername username; // Zero out all the fields to make the profile slot considered "Empty" void Invalidate() { @@ -88,27 +82,26 @@ static_assert(sizeof(ProfileBase) == 0x38, "ProfileBase is an invalid size"); class ProfileManager { public: ProfileManager(); // TODO(ogniK): Load from system save - ResultCode AddUser(ProfileInfo user); - ResultCode CreateNewUser(UUID uuid, std::array<u8, 0x20>& username); + ResultCode AddUser(const ProfileInfo& user); + ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); ResultCode CreateNewUser(UUID uuid, const std::string& username); boost::optional<size_t> GetUserIndex(const UUID& uuid) const; - boost::optional<size_t> GetUserIndex(ProfileInfo user) const; + boost::optional<size_t> GetUserIndex(const ProfileInfo& user) const; bool GetProfileBase(boost::optional<size_t> index, ProfileBase& profile) const; bool GetProfileBase(UUID uuid, ProfileBase& profile) const; - bool GetProfileBase(ProfileInfo user, ProfileBase& profile) const; + bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; bool GetProfileBaseAndData(boost::optional<size_t> index, ProfileBase& profile, - std::array<u8, MAX_DATA>& data) const; - bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, - std::array<u8, MAX_DATA>& data) const; - bool GetProfileBaseAndData(ProfileInfo user, ProfileBase& profile, - std::array<u8, MAX_DATA>& data) const; + ProfileData& data) const; + bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const; + bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, + ProfileData& data) const; size_t GetUserCount() const; size_t GetOpenUserCount() const; bool UserExists(UUID uuid) const; void OpenUser(UUID uuid); void CloseUser(UUID uuid); - std::array<UUID, MAX_USERS> GetOpenUsers() const; - std::array<UUID, MAX_USERS> GetAllUsers() const; + UserIDArray GetOpenUsers() const; + UserIDArray GetAllUsers() const; UUID GetLastOpenedUser() const; bool CanSystemRegisterUser() const; @@ -118,7 +111,7 @@ private: size_t user_count = 0; boost::optional<size_t> AddToProfiles(const ProfileInfo& profile); bool RemoveProfileAtIndex(size_t index); - UUID last_opened_user{0, 0}; + UUID last_opened_user{INVALID_UUID}; }; }; // namespace Service::Account |