Serialize ArchiveManager and other code review actions

This commit is contained in:
Hamish Milne 2020-03-29 18:56:25 +01:00
parent 04aa351c40
commit 6760ea18b6
43 changed files with 102 additions and 67 deletions

View File

@ -1,3 +1,4 @@
#pragma optimize("", off)
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
@ -544,6 +545,7 @@ void System::serialize(Archive& ar, const unsigned int file_version) {
ar&* cpu_cores[i].get();
}
ar&* service_manager.get();
ar&* archive_manager.get();
ar& GPU::g_regs;
ar& LCD::g_regs;

View File

@ -65,7 +65,7 @@ private:
LowPathType type;
std::vector<u8> binary;
std::string string;
std::u16string u16str{};
std::u16string u16str;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
@ -77,18 +77,16 @@ private:
case LowPathType::Char:
ar& string;
break;
#ifdef _WIN32
case LowPathType::Wchar:
static_assert(sizeof(wchar_t) == sizeof(char16_t));
{
std::wstring wstring(reinterpret_cast<wchar_t*>(u16str.data()));
ar& wstring;
if (!Archive::is_saving::value) {
u16str = std::u16string(reinterpret_cast<char16_t*>(wstring.data()));
}
case LowPathType::Wchar: {
std::vector<char16_t> data;
if (Archive::is_saving::value) {
std::copy(u16str.begin(), u16str.end(), std::back_inserter(data));
}
break;
#endif
ar& data;
if (Archive::is_loading::value) {
u16str = std::u16string(data.data(), data.size());
}
} break;
default:
break;
}

View File

@ -167,6 +167,14 @@ public:
}
return SaveDataArchive::CreateFile(path, size);
}
private:
ExtSaveDataArchive() = default;
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<SaveDataArchive>(*this);
}
friend class boost::serialization::access;
};
struct ExtSaveDataArchivePath {
@ -304,3 +312,4 @@ void ArchiveFactory_ExtSaveData::WriteIcon(const Path& path, const u8* icon_data
} // namespace FileSys
SERIALIZE_EXPORT_IMPL(FileSys::ExtSaveDataDelayGenerator)
SERIALIZE_EXPORT_IMPL(FileSys::ExtSaveDataArchive)

View File

@ -4,6 +4,7 @@
#pragma once
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "core/file_sys/archive_source_sd_savedata.h"

View File

@ -4,6 +4,7 @@
#pragma once
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "core/file_sys/archive_source_sd_savedata.h"

View File

@ -10,6 +10,7 @@
#include <vector>
#include <boost/serialization/export.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/unordered_map.hpp>
#include <boost/serialization/vector.hpp>
#include "common/common_types.h"
#include "core/file_sys/archive_backend.h"
@ -63,7 +64,7 @@ private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<ArchiveFactory>(*this);
// NOTE: ncch_data is never written to, so we don't serialize it here
ar& ncch_data;
}
friend class boost::serialization::access;
};

View File

@ -7,7 +7,6 @@
#include <algorithm>
#include <cstddef>
#include <memory>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/unique_ptr.hpp>
#include "common/common_types.h"
#include "core/hle/result.h"

View File

@ -23,14 +23,6 @@ struct RomFSHeader {
struct Descriptor {
u32_le offset;
u32_le length;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& offset;
ar& length;
}
friend class boost::serialization::access;
};
u32_le header_length;
Descriptor directory_hash_table;
@ -146,6 +138,7 @@ private:
if (Archive::is_loading::value) {
Load();
}
// NOTE: Everything else is essentially cached, updated when we call Load
}
friend class boost::serialization::access;
};

View File

@ -38,10 +38,9 @@ public:
protected:
std::string mount_point;
private:
SaveDataArchive() = default;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<ArchiveBackend>(*this);
@ -51,8 +50,10 @@ private:
};
class SaveDataDelayGenerator;
class ExtSaveDataArchive;
} // namespace FileSys
BOOST_CLASS_EXPORT_KEY(FileSys::SaveDataArchive)
BOOST_CLASS_EXPORT_KEY(FileSys::SaveDataDelayGenerator)
BOOST_CLASS_EXPORT_KEY(FileSys::ExtSaveDataArchive)

View File

@ -22,8 +22,6 @@
#include "core/hle/kernel/object.h"
#include "core/hle/kernel/server_session.h"
BOOST_SERIALIZATION_ASSUME_ABSTRACT(Kernel::SessionRequestHandler)
namespace Service {
class ServiceFrameworkBase;
}
@ -320,5 +318,4 @@ private:
} // namespace Kernel
BOOST_CLASS_EXPORT_KEY(Kernel::SessionRequestHandler::SessionDataBase)
BOOST_CLASS_EXPORT_KEY(Kernel::HLERequestContext::ThreadCallback)

View File

@ -6,12 +6,12 @@
#include <memory>
#include <boost/serialization/array.hpp>
#include <boost/serialization/bitset.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "common/archives.h"
#include "common/assert.h"
#include "common/common_funcs.h"
#include "common/logging/log.h"
#include "common/serialization/boost_vector.hpp"
#include "core/global.h"
#include "core/hle/kernel/errors.h"
#include "core/hle/kernel/memory.h"
#include "core/hle/kernel/process.h"

View File

@ -13,6 +13,7 @@
#include <boost/container/static_vector.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/string.hpp>
#include "common/bit_field.h"
#include "common/common_types.h"
#include "core/hle/kernel/handle_table.h"

View File

@ -16,8 +16,6 @@ namespace Kernel {
class Event;
}
BOOST_SERIALIZATION_ASSUME_ABSTRACT(Service::AC::Module::Interface)
namespace Service::AC {
class Module final {
public:

View File

@ -26,7 +26,7 @@ public:
private:
template <class Archive>
inline void serialize(Archive& ar, const unsigned int file_version) {}
void serialize(Archive& ar, const unsigned int file_version) {}
friend class boost::serialization::access;
};

View File

@ -13,6 +13,7 @@
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include "common/common_types.h"
#include "common/construct.h"
#include "core/file_sys/cia_container.h"
#include "core/file_sys/file_backend.h"
#include "core/global.h"
@ -154,7 +155,6 @@ std::string GetMediaTitlePath(Service::FS::MediaType media_type);
class Module final {
public:
explicit Module(Core::System& system);
explicit Module(Kernel::KernelSystem& kernel);
Module() = default;
~Module();
@ -568,6 +568,8 @@ public:
};
private:
explicit Module(Kernel::KernelSystem& kernel);
/**
* Scans the for titles in a storage medium for listing.
* @param media_type the storage medium to scan
@ -590,6 +592,16 @@ private:
ar& am_title_list;
ar& system_updater_mutex;
}
template <class Archive>
static void load_construct(Archive& ar, Module* t, const unsigned int file_version) {
::new (t) Module(Core::Global<Kernel::KernelSystem>());
}
template <class Archive>
void save_construct(Archive& ar, const unsigned int file_version) const {}
friend class ::construct_access;
friend class boost::serialization::access;
};
@ -597,9 +609,4 @@ void InstallInterfaces(Core::System& system);
} // namespace Service::AM
namespace boost::serialization {
template <class Archive>
inline void load_construct_data(Archive& ar, Service::AM::Module* t, const unsigned int) {
::new (t) Service::AM::Module(Core::Global<Kernel::KernelSystem>());
}
} // namespace boost::serialization
BOOST_SERIALIZATION_CONSTRUCT(Service::AM::Module);

View File

@ -10,6 +10,7 @@
#include <boost/serialization/array.hpp>
#include <boost/serialization/optional.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include "core/global.h"
#include "core/hle/kernel/event.h"
#include "core/hle/result.h"

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include "common/archives.h"
#include "common/common_paths.h"
#include "common/file_util.h"

View File

@ -6,8 +6,6 @@
#include <memory>
#include <vector>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/vector.hpp>
#include "common/archives.h"
#include "common/common_funcs.h"
#include "common/common_types.h"
@ -651,7 +649,4 @@ void InstallInterfaces(Core::System& system);
} // namespace Service::APT
namespace boost::serialization {
template <class Archive>
void load_construct_data(Archive& ar, Service::APT::Module* t, const unsigned int);
}
SERVICE_CONSTRUCT(Service::APT::Module)

View File

@ -989,7 +989,7 @@ void InstallInterfaces(Core::System& system);
namespace boost::serialization {
template <class Archive>
inline void load_construct_data(Archive& ar, Service::BOSS::Module* t, const unsigned int) {
void load_construct_data(Archive& ar, Service::BOSS::Module* t, const unsigned int) {
::new (t) Service::BOSS::Module(Core::Global<Core::System>());
}
} // namespace boost::serialization

View File

@ -9,6 +9,10 @@
#include <future>
#include <memory>
#include <vector>
#include <boost/serialization/array.hpp>
#include <boost/serialization/deque.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/unique_ptr.hpp>
#include "common/common_types.h"
#include "common/swap.h"
#include "core/global.h"
@ -849,6 +853,7 @@ private:
ar& completion_event;
ar& buffer_error_interrupt_event;
ar& vsync_interrupt_event;
ar& vsync_timings;
// Ignore capture_result. In-progress captures might be affected but this is OK.
ar& dest_process;
ar& dest;
@ -879,7 +884,7 @@ void InstallInterfaces(Core::System& system);
namespace boost::serialization {
template <class Archive>
inline void load_construct_data(Archive& ar, Service::CAM::Module* t, const unsigned int) {
void load_construct_data(Archive& ar, Service::CAM::Module* t, const unsigned int) {
::new (t) Service::CAM::Module(Core::Global<Core::System>());
}
} // namespace boost::serialization

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <boost/serialization/unique_ptr.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <cryptopp/base64.h>
#include <cryptopp/hmac.h>
#include <cryptopp/sha.h>

View File

@ -258,7 +258,7 @@ public:
ar& data_path_type;
ar& open_mode.raw;
ar& path;
// ar& file;
ar& file;
}
friend class boost::serialization::access;
};

View File

@ -4,6 +4,8 @@
#include <algorithm>
#include <tuple>
#include <boost/serialization/array.hpp>
#include <boost/serialization/unique_ptr.hpp>
#include <cryptopp/osrng.h>
#include <cryptopp/sha.h>
#include "common/archives.h"

View File

@ -277,8 +277,4 @@ void InstallInterfaces(Core::System& system);
} // namespace Service::CSND
BOOST_CLASS_EXPORT_KEY(Service::CSND::CSND_SND)
namespace boost::serialization {
template <class Archive>
void load_construct_data(Archive& ar, Service::CSND::CSND_SND* t, const unsigned int);
}
SERVICE_CONSTRUCT(Service::CSND::CSND_SND)

View File

@ -5,6 +5,9 @@
#pragma once
#include <memory>
#include <boost/serialization/array.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "audio_core/dsp_interface.h"
#include "core/hle/kernel/event.h"
#include "core/hle/result.h"
@ -282,8 +285,4 @@ void InstallInterfaces(Core::System& system);
} // namespace Service::DSP
BOOST_CLASS_EXPORT_KEY(Service::DSP::DSP_DSP)
namespace boost::serialization {
template <class Archive>
void load_construct_data(Archive& ar, Service::DSP::DSP_DSP* t, const unsigned int);
}
SERVICE_CONSTRUCT(Service::DSP::DSP_DSP)

View File

@ -8,7 +8,8 @@
#include <string>
#include <unordered_map>
#include <vector>
#include <boost/container/flat_map.hpp>
#include <boost/serialization/unique_ptr.hpp>
#include <boost/serialization/unordered_map.hpp>
#include "common/common_types.h"
#include "core/file_sys/archive_backend.h"
#include "core/hle/result.h"
@ -253,7 +254,7 @@ private:
* Map of registered archives, identified by id code. Once an archive is registered here, it is
* never removed until UnregisterArchiveTypes is called.
*/
boost::container::flat_map<ArchiveIdCode, std::unique_ptr<ArchiveFactory>> id_code_map;
std::unordered_map<ArchiveIdCode, std::unique_ptr<ArchiveFactory>> id_code_map;
/**
* Map of active archive handles to archive objects
@ -267,6 +268,7 @@ private:
ar& handle_map;
ar& next_handle;
}
friend class boost::serialization::access;
};
} // namespace Service::FS

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/unique_ptr.hpp>
#include "common/archives.h"
#include "common/logging/log.h"
#include "core/file_sys/directory_backend.h"

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <boost/serialization/unique_ptr.hpp>
#include "common/archives.h"
#include "common/logging/log.h"
#include "core/core.h"

View File

@ -5,6 +5,7 @@
#pragma once
#include <memory>
#include <boost/serialization/base_object.hpp>
#include "core/file_sys/archive_backend.h"
#include "core/global.h"
#include "core/hle/service/service.h"

View File

@ -4,6 +4,7 @@
#pragma once
#include <boost/serialization/base_object.hpp>
#include "common/common_types.h"
#include "core/hle/service/service.h"

View File

@ -7,6 +7,8 @@
#include <cstddef>
#include <memory>
#include <string>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "common/bit_field.h"
#include "common/common_types.h"
#include "core/hle/kernel/event.h"

View File

@ -4,6 +4,9 @@
#include <algorithm>
#include <cmath>
#include <boost/serialization/array.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/unique_ptr.hpp>
#include "common/archives.h"
#include "common/logging/log.h"
#include "core/3ds.h"
@ -208,7 +211,7 @@ void Module::UpdateAccelerometerCallback(u64 userdata, s64 cycles_late) {
Common::Vec3<float> accel;
if (!motion_device) {
is_device_reload_pending.exchange(true);
is_device_reload_pending.store(true);
return;
}
std::tie(accel, std::ignore) = motion_device->GetStatus();
@ -259,7 +262,7 @@ void Module::UpdateGyroscopeCallback(u64 userdata, s64 cycles_late) {
Common::Vec3<float> gyro;
if (!motion_device) {
is_device_reload_pending.exchange(true);
is_device_reload_pending.store(true);
return;
}
std::tie(std::ignore, gyro) = motion_device->GetStatus();

View File

@ -7,7 +7,6 @@
#include <array>
#include <atomic>
#include <boost/serialization/array.hpp>
#include <boost/serialization/export.hpp>
#include "common/bit_field.h"
#include "common/swap.h"
#include "core/frontend/input.h"

View File

@ -2,6 +2,8 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "common/archives.h"
#include "core/core.h"
#include "core/core_timing.h"

View File

@ -4,6 +4,7 @@
#include <memory>
#include <boost/crc.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/serialization/unique_ptr.hpp>
#include "common/string_util.h"

View File

@ -5,6 +5,7 @@
#pragma once
#include <array>
#include <boost/serialization/array.hpp>
#include "core/hle/service/service.h"
namespace Core {

View File

@ -22,6 +22,8 @@ void Module::serialize(Archive& ar, const unsigned int) {
ar& tag_out_of_range_event;
ar& nfc_tag_state;
ar& nfc_status;
ar& amiibo_data;
ar& amiibo_in_range;
}
SERIALIZE_IMPL(Module)

View File

@ -6,6 +6,7 @@
#include <atomic>
#include <memory>
#include <boost/serialization/binary_object.hpp>
#include "common/common_types.h"
#include "core/hle/service/service.h"
@ -35,6 +36,13 @@ struct AmiiboData {
u16_be model_number;
u8 series;
INSERT_PADDING_BYTES(0x1C1);
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::make_binary_object(this, sizeof(AmiiboData));
}
friend class boost::serialization::access;
};
static_assert(sizeof(AmiiboData) == 0x21C, "AmiiboData is an invalid size");

View File

@ -1175,7 +1175,7 @@ void NWM_UDS::GetChannel(Kernel::HLERequestContext& ctx) {
class NWM_UDS::ThreadCallback : public Kernel::HLERequestContext::WakeupCallback {
public:
ThreadCallback(u16 command_id_) : command_id(command_id_) {}
explicit ThreadCallback(u16 command_id_) : command_id(command_id_) {}
void WakeUp(std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx,
Kernel::ThreadWakeupReason reason) {

View File

@ -10,7 +10,6 @@
#include <memory>
#include <string>
#include <boost/container/flat_map.hpp>
#include <boost/serialization/assume_abstract.hpp>
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include "common/common_types.h"

View File

@ -88,7 +88,8 @@ void SRV::EnableNotification(Kernel::HLERequestContext& ctx) {
class SRV::ThreadCallback : public Kernel::HLERequestContext::WakeupCallback {
public:
ThreadCallback(Core::System& system_, std::string name_) : system(system_), name(name_) {}
explicit ThreadCallback(Core::System& system_, std::string name_)
: system(system_), name(name_) {}
void WakeUp(std::shared_ptr<Kernel::Thread> thread, Kernel::HLERequestContext& ctx,
Kernel::ThreadWakeupReason reason) {

View File

@ -13,4 +13,4 @@ add_library(network STATIC
create_target_directory_groups(network)
target_link_libraries(network PRIVATE common enet Boost::boost)
target_link_libraries(network PRIVATE common enet Boost::serialization)

View File

@ -8,7 +8,7 @@
#include <memory>
#include <string>
#include <vector>
#include <boost/serialization/access.hpp>
#include <boost/serialization/vector.hpp>
#include "common/common_types.h"
#include "network/room.h"