From ca5638a1426ce560f3896b3ff0d3efd02b654585 Mon Sep 17 00:00:00 2001 From: Zach Hilman Date: Tue, 18 Dec 2018 09:07:25 -0500 Subject: common: Extract UUID to its own class Since the Mii database uses UUIDs very similar to the Accounts database, it makes no sense to not share code between them. --- src/core/hle/service/acc/profile_manager.h | 66 ++++++++---------------------- 1 file changed, 17 insertions(+), 49 deletions(-) (limited to 'src/core/hle/service/acc/profile_manager.h') diff --git a/src/core/hle/service/acc/profile_manager.h b/src/core/hle/service/acc/profile_manager.h index c4ce2e0b3..fd7abb541 100644 --- a/src/core/hle/service/acc/profile_manager.h +++ b/src/core/hle/service/acc/profile_manager.h @@ -9,47 +9,15 @@ #include "common/common_types.h" #include "common/swap.h" +#include "common/uuid.h" #include "core/hle/result.h" namespace Service::Account { constexpr std::size_t MAX_USERS = 8; -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{{lo, hi}} {} - - explicit operator bool() const { - return uuid != INVALID_UUID; - } - - bool operator==(const UUID& rhs) const { - return uuid == rhs.uuid; - } - - bool operator!=(const UUID& rhs) const { - return !operator==(rhs); - } - - // TODO(ogniK): Properly generate uuids based on RFC-4122 - static UUID Generate(); - - // Set the UUID to {0,0} to be considered an invalid user - void Invalidate() { - uuid = INVALID_UUID; - } - - std::string Format() const; - std::string FormatSwitch() const; -}; -static_assert(sizeof(UUID) == 16, "UUID is an invalid size!"); constexpr std::size_t profile_username_size = 32; using ProfileUsername = std::array; -using UserIDArray = std::array; +using UserIDArray = std::array; /// Contains extra data related to a user. /// TODO: RE this structure @@ -66,7 +34,7 @@ static_assert(sizeof(ProfileData) == 0x80, "ProfileData structure has incorrect /// 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; + Common::UUID user_uuid; ProfileUsername username; u64 creation_time; ProfileData data; // TODO(ognik): Work out what this is @@ -74,7 +42,7 @@ struct ProfileInfo { }; struct ProfileBase { - UUID user_uuid; + Common::UUID user_uuid; u64_le timestamp; ProfileUsername username; @@ -96,33 +64,33 @@ public: ~ProfileManager(); ResultCode AddUser(const ProfileInfo& user); - ResultCode CreateNewUser(UUID uuid, const ProfileUsername& username); - ResultCode CreateNewUser(UUID uuid, const std::string& username); - std::optional GetUser(std::size_t index) const; - std::optional GetUserIndex(const UUID& uuid) const; + ResultCode CreateNewUser(Common::UUID uuid, const ProfileUsername& username); + ResultCode CreateNewUser(Common::UUID uuid, const std::string& username); + std::optional GetUser(std::size_t index) const; + std::optional GetUserIndex(const Common::UUID& uuid) const; std::optional GetUserIndex(const ProfileInfo& user) const; bool GetProfileBase(std::optional index, ProfileBase& profile) const; - bool GetProfileBase(UUID uuid, ProfileBase& profile) const; + bool GetProfileBase(Common::UUID uuid, ProfileBase& profile) const; bool GetProfileBase(const ProfileInfo& user, ProfileBase& profile) const; bool GetProfileBaseAndData(std::optional index, ProfileBase& profile, ProfileData& data) const; - bool GetProfileBaseAndData(UUID uuid, ProfileBase& profile, ProfileData& data) const; + bool GetProfileBaseAndData(Common::UUID uuid, ProfileBase& profile, ProfileData& data) const; bool GetProfileBaseAndData(const ProfileInfo& user, ProfileBase& profile, ProfileData& data) const; std::size_t GetUserCount() const; std::size_t GetOpenUserCount() const; - bool UserExists(UUID uuid) const; + bool UserExists(Common::UUID uuid) const; bool UserExistsIndex(std::size_t index) const; - void OpenUser(UUID uuid); - void CloseUser(UUID uuid); + void OpenUser(Common::UUID uuid); + void CloseUser(Common::UUID uuid); UserIDArray GetOpenUsers() const; UserIDArray GetAllUsers() const; - UUID GetLastOpenedUser() const; + Common::UUID GetLastOpenedUser() const; bool CanSystemRegisterUser() const; - bool RemoveUser(UUID uuid); - bool SetProfileBase(UUID uuid, const ProfileBase& profile_new); + bool RemoveUser(Common::UUID uuid); + bool SetProfileBase(Common::UUID uuid, const ProfileBase& profile_new); private: void ParseUserSaveFile(); @@ -132,7 +100,7 @@ private: std::array profiles{}; std::size_t user_count = 0; - UUID last_opened_user{INVALID_UUID}; + Common::UUID last_opened_user{Common::INVALID_UUID}; }; }; // namespace Service::Account -- cgit v1.2.3