citra-emu
/
citra
Archived
1
0
Fork 0

Serialize file/directory services

This commit is contained in:
Hamish Milne 2020-01-10 23:47:39 +00:00 committed by zhupengfei
parent 9525d81344
commit ca971ff31f
7 changed files with 81 additions and 3 deletions

4
TODO
View File

@ -4,14 +4,14 @@
☐ Custom texture cache
☐ Review constructor/initialization code
☐ Review core timing events
☐ Review base class serialization everywhere
✔ Review base class serialization everywhere @done(20-01-10 23:47)
Make sure that all base/derived relationships are registered
☐ Serialize codeset with an apploader reference instead
☐ Additional stuff to serialize
☐ Self-NCCH archive
☐ File backends
☐ Directory backends
☐ File/directory 'services'
✔ File/directory 'services' @done(20-01-10 23:46)
✔ CPU @done(19-08-13 15:41)
✔ Memory @done(19-08-13 15:41)
✔ Page tables @done(20-01-05 16:33)

View File

@ -8,6 +8,8 @@
#include <string>
#include <utility>
#include <vector>
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>
#include "common/bit_field.h"
#include "common/common_types.h"
#include "common/swap.h"
@ -63,7 +65,33 @@ 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) {
ar& type;
switch (type) {
case LowPathType::Binary:
ar& binary;
break;
case LowPathType::Char:
ar& string;
break;
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()));
}
}
break;
default:
break;
}
}
friend class boost::serialization::access;
};
/// Parameters of the archive, as specified in the Create or Format call.

View File

@ -53,6 +53,11 @@ public:
* @return true if the directory closed correctly
*/
virtual bool Close() const = 0;
private:
template <class Archive>
void serialize(Archive& ar, const unsigned int) {}
friend class boost::serialization::access;
};
} // namespace FileSys

View File

@ -2,13 +2,25 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/archives.h"
#include "common/logging/log.h"
#include "core/file_sys/directory_backend.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/service/fs/directory.h"
SERIALIZE_EXPORT_IMPL(Service::FS::Directory)
namespace Service::FS {
template <class Archive>
void Directory::serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
ar& path;
ar& backend;
}
Directory::Directory() : ServiceFramework("", 1) {}
Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend,
const FileSys::Path& path)
: ServiceFramework("", 1), path(path), backend(std::move(backend)) {

View File

@ -25,6 +25,15 @@ public:
protected:
void Read(Kernel::HLERequestContext& ctx);
void Close(Kernel::HLERequestContext& ctx);
private:
Directory();
template <class Archive>
void serialize(Archive& ar, const unsigned int);
friend class boost::serialization::access;
};
} // namespace Service::FS
BOOST_CLASS_EXPORT_KEY(Service::FS::Directory)

View File

@ -2,6 +2,7 @@
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/archives.h"
#include "common/logging/log.h"
#include "core/core.h"
#include "core/file_sys/errors.h"
@ -13,8 +14,20 @@
#include "core/hle/kernel/server_session.h"
#include "core/hle/service/fs/file.h"
SERIALIZE_EXPORT_IMPL(Service::FS::File)
SERIALIZE_EXPORT_IMPL(Service::FS::FileSessionSlot)
namespace Service::FS {
template <class Archive>
void File::serialize(Archive& ar, const unsigned int) {
ar& boost::serialization::base_object<Kernel::SessionRequestHandler>(*this);
ar& path;
ar& backend;
}
File::File() : ServiceFramework("", 1), kernel(Core::Global<Kernel::KernelSystem>()) {}
File::File(Kernel::KernelSystem& kernel, std::unique_ptr<FileSys::FileBackend>&& backend,
const FileSys::Path& path)
: ServiceFramework("", 1), path(path), backend(std::move(backend)), kernel(kernel) {

View File

@ -6,6 +6,7 @@
#include <memory>
#include "core/file_sys/archive_backend.h"
#include "core/global.h"
#include "core/hle/service/service.h"
namespace Core {
@ -30,6 +31,7 @@ private:
ar& size;
ar& subfile;
}
friend class boost::serialization::access;
};
// TODO: File is not a real service, but it can still utilize ServiceFramework::RegisterHandlers.
@ -71,6 +73,15 @@ private:
void OpenSubFile(Kernel::HLERequestContext& ctx);
Kernel::KernelSystem& kernel;
File();
template <class Archive>
void serialize(Archive& ar, const unsigned int);
friend class boost::serialization::access;
};
} // namespace Service::FS
BOOST_CLASS_EXPORT_KEY(Service::FS::FileSessionSlot)
BOOST_CLASS_EXPORT_KEY(Service::FS::File)