mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-08-12 02:58:48 +00:00
haze: improve WriteVariableLengthData readability
This commit is contained in:
parent
9c922e4774
commit
0b5b63b9d8
1 changed files with 17 additions and 6 deletions
|
@ -107,23 +107,34 @@ namespace haze {
|
||||||
|
|
||||||
template <typename F>
|
template <typename F>
|
||||||
Result WriteVariableLengthData(PtpUsbBulkContainer &request, F &&func) {
|
Result WriteVariableLengthData(PtpUsbBulkContainer &request, F &&func) {
|
||||||
|
HAZE_ASSERT(m_offset == 0 && m_transmitted_size == 0);
|
||||||
|
|
||||||
|
/* Declare how many bytes the data will require to write. */
|
||||||
|
size_t data_size = 0;
|
||||||
{
|
{
|
||||||
|
/* Temporarily disable writing to calculate the size.*/
|
||||||
m_disabled = true;
|
m_disabled = true;
|
||||||
ON_SCOPE_EXIT { m_disabled = false; };
|
|
||||||
|
ON_SCOPE_EXIT {
|
||||||
|
/* Report how many bytes were required. */
|
||||||
|
data_size = m_transmitted_size;
|
||||||
|
|
||||||
|
/* On exit, enable writing and reset sizes. */
|
||||||
|
m_transmitted_size = 0;
|
||||||
|
m_disabled = false;
|
||||||
|
m_offset = 0;
|
||||||
|
};
|
||||||
|
|
||||||
R_TRY(func());
|
R_TRY(func());
|
||||||
R_TRY(this->Commit());
|
R_TRY(this->Commit());
|
||||||
}
|
}
|
||||||
|
|
||||||
const size_t data_size = m_transmitted_size;
|
/* Actually copy and write the data. */
|
||||||
|
|
||||||
m_transmitted_size = 0;
|
|
||||||
m_offset = 0;
|
|
||||||
|
|
||||||
R_TRY(this->AddDataHeader(request, data_size));
|
R_TRY(this->AddDataHeader(request, data_size));
|
||||||
R_TRY(func());
|
R_TRY(func());
|
||||||
R_TRY(this->Commit());
|
R_TRY(this->Commit());
|
||||||
|
|
||||||
|
/* We succeeded. */
|
||||||
R_SUCCEED();
|
R_SUCCEED();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue