fs/archive: convert Directory to ServiceFramework

This commit is contained in:
wwylele 2018-02-14 21:29:56 +02:00
parent 4935dcaf56
commit 19d7324075
2 changed files with 32 additions and 36 deletions

View File

@ -303,42 +303,41 @@ Kernel::SharedPtr<Kernel::ClientSession> File::Connect() {
Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, Directory::Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend,
const FileSys::Path& path) const FileSys::Path& path)
: path(path), backend(std::move(backend)) {} : ServiceFramework("", 1), path(path), backend(std::move(backend)) {
static const FunctionInfo functions[] = {
// clang-format off
{0x08010042, &Directory::Read, "Read"},
{0x08020000, &Directory::Close, "Close"},
// clang-format on
};
RegisterHandlers(functions);
}
Directory::~Directory() {} Directory::~Directory() {}
void Directory::HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) { void Directory::Read(Kernel::HLERequestContext& ctx) {
u32* cmd_buff = Kernel::GetCommandBuffer(); IPC::RequestParser rp(ctx, 0x0801, 1, 2);
DirectoryCommand cmd = static_cast<DirectoryCommand>(cmd_buff[0]); u32 count = rp.Pop<u32>();
switch (cmd) { auto& buffer = rp.PopMappedBuffer();
// Read from directory... std::vector<FileSys::Entry> entries(count);
case DirectoryCommand::Read: { LOG_TRACE(Service_FS, "Read %s: count=%u", GetName().c_str(), count);
u32 count = cmd_buff[1]; // Number of entries actually read
u32 address = cmd_buff[3]; u32 read = backend->Read(static_cast<u32>(entries.size()), entries.data());
std::vector<FileSys::Entry> entries(count); buffer.Write(entries.data(), 0, read * sizeof(FileSys::Entry));
LOG_TRACE(Service_FS, "Read %s: count=%d", GetName().c_str(), count);
// Number of entries actually read IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
u32 read = backend->Read(static_cast<u32>(entries.size()), entries.data()); rb.Push(RESULT_SUCCESS);
cmd_buff[2] = read; rb.Push(read);
Memory::WriteBlock(address, entries.data(), read * sizeof(FileSys::Entry)); rb.PushMappedBuffer(buffer);
break; }
}
case DirectoryCommand::Close: { void Directory::Close(Kernel::HLERequestContext& ctx) {
LOG_TRACE(Service_FS, "Close %s", GetName().c_str()); IPC::RequestParser rp(ctx, 0x0802, 0, 0);
backend->Close(); LOG_TRACE(Service_FS, "Close %s", GetName().c_str());
break; backend->Close();
}
// Unknown command... IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
default: rb.Push(RESULT_SUCCESS);
LOG_ERROR(Service_FS, "Unknown command=0x%08X!", static_cast<u32>(cmd));
ResultCode error = UnimplementedFunction(ErrorModule::FS);
cmd_buff[1] = error.raw; // TODO(Link Mauve): use the correct error code for that.
return;
}
cmd_buff[1] = RESULT_SUCCESS.raw; // No error
} }
//////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////

View File

@ -87,7 +87,7 @@ private:
void OpenSubFile(Kernel::HLERequestContext& ctx); void OpenSubFile(Kernel::HLERequestContext& ctx);
}; };
class Directory final : public Kernel::SessionRequestHandler { class Directory final : public ServiceFramework<Directory> {
public: public:
Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path); Directory(std::unique_ptr<FileSys::DirectoryBackend>&& backend, const FileSys::Path& path);
~Directory(); ~Directory();
@ -100,11 +100,8 @@ public:
std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface std::unique_ptr<FileSys::DirectoryBackend> backend; ///< File backend interface
protected: protected:
void HandleSyncRequest(Kernel::SharedPtr<Kernel::ServerSession> server_session) override; void Read(Kernel::HLERequestContext& ctx);
void Close(Kernel::HLERequestContext& ctx);
std::unique_ptr<SessionDataBase> MakeSessionData() const override {
return nullptr;
}
}; };
/** /**