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...
case DirectoryCommand::Read: {
u32 count = cmd_buff[1];
u32 address = cmd_buff[3];
std::vector<FileSys::Entry> entries(count); std::vector<FileSys::Entry> entries(count);
LOG_TRACE(Service_FS, "Read %s: count=%d", GetName().c_str(), count); LOG_TRACE(Service_FS, "Read %s: count=%u", GetName().c_str(), count);
// Number of entries actually read // Number of entries actually read
u32 read = backend->Read(static_cast<u32>(entries.size()), entries.data()); u32 read = backend->Read(static_cast<u32>(entries.size()), entries.data());
cmd_buff[2] = read; buffer.Write(entries.data(), 0, read * sizeof(FileSys::Entry));
Memory::WriteBlock(address, entries.data(), read * sizeof(FileSys::Entry));
break;
}
case DirectoryCommand::Close: { IPC::RequestBuilder rb = rp.MakeBuilder(2, 2);
rb.Push(RESULT_SUCCESS);
rb.Push(read);
rb.PushMappedBuffer(buffer);
}
void Directory::Close(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx, 0x0802, 0, 0);
LOG_TRACE(Service_FS, "Close %s", GetName().c_str()); LOG_TRACE(Service_FS, "Close %s", GetName().c_str());
backend->Close(); backend->Close();
break;
}
// 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;
}
}; };
/** /**