2021-09-16 04:50:06 +00:00
|
|
|
/*
|
2021-10-04 19:59:10 +00:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2021-09-16 04:50:06 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stratosphere.hpp>
|
2021-09-16 07:07:06 +00:00
|
|
|
#include "sprofile_srv_types.hpp"
|
2021-09-16 06:10:11 +00:00
|
|
|
#include "sprofile_srv_profile_update_observer_impl.hpp"
|
2021-09-16 23:14:26 +00:00
|
|
|
#include "sprofile_srv_profile_importer.hpp"
|
2021-09-16 04:50:06 +00:00
|
|
|
|
|
|
|
namespace ams::sprofile::srv {
|
|
|
|
|
|
|
|
class ProfileManager {
|
|
|
|
public:
|
|
|
|
struct SaveDataInfo {
|
|
|
|
u64 id;
|
|
|
|
const char *mount_name;
|
|
|
|
size_t size;
|
|
|
|
size_t journal_size;
|
|
|
|
u32 flags;
|
|
|
|
};
|
|
|
|
private:
|
|
|
|
private:
|
2021-09-16 07:07:06 +00:00
|
|
|
os::SdkMutex m_general_mutex{};
|
|
|
|
os::SdkMutex m_fs_mutex{};
|
2021-09-16 04:50:06 +00:00
|
|
|
SaveDataInfo m_save_data_info;
|
2021-09-16 06:10:11 +00:00
|
|
|
bool m_save_file_mounted;
|
2021-09-16 23:14:26 +00:00
|
|
|
util::optional<ProfileImporter> m_profile_importer;
|
2021-09-16 07:07:06 +00:00
|
|
|
os::SdkMutex m_profile_importer_mutex{};
|
|
|
|
util::optional<ProfileMetadata> m_profile_metadata;
|
|
|
|
os::SdkMutex m_profile_metadata_mutex{};
|
2021-09-16 23:14:26 +00:00
|
|
|
util::optional<ServiceProfile> m_service_profile;
|
2021-09-16 07:07:06 +00:00
|
|
|
os::SdkMutex m_service_profile_mutex{};
|
2021-09-16 06:10:11 +00:00
|
|
|
ProfileUpdateObserverManager m_update_observer_manager;
|
2021-09-16 04:50:06 +00:00
|
|
|
public:
|
|
|
|
ProfileManager(const SaveDataInfo &save_data_info);
|
|
|
|
public:
|
2021-09-16 06:10:11 +00:00
|
|
|
void InitializeSaveData();
|
2021-09-16 07:07:06 +00:00
|
|
|
Result ResetSaveData();
|
|
|
|
|
2021-09-16 23:14:26 +00:00
|
|
|
Result OpenProfileImporter();
|
2021-10-30 00:38:44 +00:00
|
|
|
void CloseProfileImporter();
|
|
|
|
|
2021-09-16 23:14:26 +00:00
|
|
|
Result ImportProfile(const sprofile::srv::ProfileDataForImportData &data);
|
|
|
|
Result Commit();
|
|
|
|
Result ImportMetadata(const sprofile::srv::ProfileMetadataForImportMetadata &data);
|
|
|
|
|
2021-09-16 07:07:06 +00:00
|
|
|
Result LoadPrimaryMetadata(ProfileMetadata *out);
|
2021-09-16 06:10:11 +00:00
|
|
|
|
2021-09-16 23:14:26 +00:00
|
|
|
Result GetSigned64(s64 *out, Identifier profile, Identifier key);
|
|
|
|
Result GetUnsigned64(u64 *out, Identifier profile, Identifier key);
|
|
|
|
Result GetSigned32(s32 *out, Identifier profile, Identifier key);
|
|
|
|
Result GetUnsigned32(u32 *out, Identifier profile, Identifier key);
|
|
|
|
Result GetByte(u8 *out, Identifier profile, Identifier key);
|
|
|
|
|
|
|
|
Result GetRaw(u8 *out_type, u64 *out_value, Identifier profile, Identifier key);
|
|
|
|
|
2021-09-16 06:10:11 +00:00
|
|
|
ProfileUpdateObserverManager &GetUpdateObserverManager() { return m_update_observer_manager; }
|
2021-09-16 04:50:06 +00:00
|
|
|
private:
|
2021-09-16 23:14:26 +00:00
|
|
|
Result CommitImpl();
|
|
|
|
|
|
|
|
void OnCommitted();
|
|
|
|
|
|
|
|
Result GetDataEntry(ProfileDataEntry *out, Identifier profile, Identifier key);
|
|
|
|
|
|
|
|
Result LoadProfile(Identifier profile);
|
|
|
|
|
|
|
|
Result EnsurePrimaryDirectories();
|
|
|
|
Result EnsureTemporaryDirectories();
|
2021-09-16 04:50:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|