2020-04-14 02:07:37 +02:00
|
|
|
/*
|
2021-10-04 21:59:10 +02:00
|
|
|
* Copyright (c) Atmosphère-NX
|
2020-04-14 02:07:37 +02: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>
|
|
|
|
#include "erpt_srv_allocator.hpp"
|
|
|
|
#include "erpt_srv_stream.hpp"
|
|
|
|
#include "erpt_srv_journal.hpp"
|
|
|
|
|
|
|
|
namespace ams::erpt::srv {
|
|
|
|
|
|
|
|
enum AttachmentOpenType {
|
|
|
|
AttachmentOpenType_Create = 0,
|
|
|
|
AttachmentOpenType_Read = 1,
|
|
|
|
};
|
|
|
|
|
|
|
|
constexpr inline u32 AttachmentStreamBufferSize = 1_KB;
|
|
|
|
|
|
|
|
class Attachment : public Allocator, public Stream {
|
|
|
|
private:
|
2021-10-10 09:14:06 +02:00
|
|
|
JournalRecord<AttachmentInfo> *m_record;
|
2020-04-14 02:07:37 +02:00
|
|
|
private:
|
2020-12-03 20:13:35 +01:00
|
|
|
AttachmentFileName FileName() const;
|
2020-04-14 02:07:37 +02:00
|
|
|
public:
|
|
|
|
static AttachmentFileName FileName(AttachmentId attachment_id);
|
|
|
|
public:
|
|
|
|
explicit Attachment(JournalRecord<AttachmentInfo> *r);
|
|
|
|
~Attachment();
|
|
|
|
|
|
|
|
Result Open(AttachmentOpenType type);
|
|
|
|
Result Read(u32 *out_read_count, u8 *dst, u32 dst_size);
|
|
|
|
Result Delete();
|
|
|
|
void Close();
|
|
|
|
|
2020-12-03 20:13:35 +01:00
|
|
|
Result GetFlags(AttachmentFlagSet *out) const;
|
2020-04-14 02:07:37 +02:00
|
|
|
Result SetFlags(AttachmentFlagSet flags);
|
2020-12-03 20:13:35 +01:00
|
|
|
Result GetSize(s64 *out) const;
|
2020-04-14 02:07:37 +02:00
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
Result Write(T val) {
|
|
|
|
return this->WriteStream(reinterpret_cast<const u8 *>(std::addressof(val)), sizeof(val));
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
Result Write(const T *buf, u32 buffer_size) {
|
|
|
|
return this->WriteStream(reinterpret_cast<const u8 *>(buf), buffer_size);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|