From 6c99a828af722d2e809a8ff4059a6bb9a2d61b9a Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 15 Apr 2023 20:24:44 -0400 Subject: [PATCH] haze: misc comments --- .../haze/include/haze/console_main_loop.hpp | 2 +- .../haze/include/haze/ptp_data_parser.hpp | 14 +++++++++----- troposphere/haze/source/main.cpp | 17 +++++++++++++++-- troposphere/haze/source/usb_session.cpp | 2 +- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/troposphere/haze/include/haze/console_main_loop.hpp b/troposphere/haze/include/haze/console_main_loop.hpp index b213ebede..97ae31082 100644 --- a/troposphere/haze/include/haze/console_main_loop.hpp +++ b/troposphere/haze/include/haze/console_main_loop.hpp @@ -138,7 +138,7 @@ namespace haze { printf("\n" CONSOLE_ESC(38;5;196m) "Applet Mode" CONSOLE_ESC(0m) "\n"); } - consoleUpdate(NULL); + consoleUpdate(nullptr); } protected: void ProcessEvent() override { diff --git a/troposphere/haze/include/haze/ptp_data_parser.hpp b/troposphere/haze/include/haze/ptp_data_parser.hpp index 86b62460a..2ae23b84b 100644 --- a/troposphere/haze/include/haze/ptp_data_parser.hpp +++ b/troposphere/haze/include/haze/ptp_data_parser.hpp @@ -27,27 +27,31 @@ namespace haze { u32 m_received_size; u32 m_offset; u8 *m_data; - bool m_eos; + bool m_eot; private: Result Flush() { - R_UNLESS(!m_eos, haze::ResultEndOfTransmission()); + R_UNLESS(!m_eot, haze::ResultEndOfTransmission()); m_received_size = 0; m_offset = 0; - ON_SCOPE_EXIT { m_eos = m_received_size < haze::UsbBulkPacketBufferSize; }; + ON_SCOPE_EXIT { + /* End of transmission occurs when receiving a bulk transfer less than the buffer size. */ + /* PTP uses zero-length termination, so zero is a possible size to receive. */ + m_eot = m_received_size < haze::UsbBulkPacketBufferSize; + }; R_RETURN(m_server->ReadPacket(m_data, haze::UsbBulkPacketBufferSize, std::addressof(m_received_size))); } public: - constexpr explicit PtpDataParser(void *data, AsyncUsbServer *server) : m_server(server), m_received_size(), m_offset(), m_data(static_cast(data)), m_eos() { /* ... */ } + constexpr explicit PtpDataParser(void *data, AsyncUsbServer *server) : m_server(server), m_received_size(), m_offset(), m_data(static_cast(data)), m_eot() { /* ... */ } Result Finalize() { /* Read until the transmission completes. */ while (true) { Result rc = this->Flush(); - R_SUCCEED_IF(m_eos || haze::ResultEndOfTransmission::Includes(rc)); + R_SUCCEED_IF(m_eot || haze::ResultEndOfTransmission::Includes(rc)); R_TRY(rc); } } diff --git a/troposphere/haze/source/main.cpp b/troposphere/haze/source/main.cpp index c2dfc5b91..7d3ff810d 100644 --- a/troposphere/haze/source/main.cpp +++ b/troposphere/haze/source/main.cpp @@ -17,26 +17,39 @@ #include int main(int argc, char **argv) { + /* Declare the object heap, to hold the database for an active session. */ haze::PtpObjectHeap ptp_object_heap; + /* Declare the event reactor, and components which use it. */ haze::EventReactor event_reactor; haze::PtpResponder ptp_responder; haze::ConsoleMainLoop console_main_loop; - consoleInit(NULL); + /* Initialize the console.*/ + consoleInit(nullptr); + + /* Ensure we don't go to sleep while transferring files. */ appletSetAutoSleepDisabled(true); + /* Configure the PTP responder and console main loop. */ ptp_responder.Initialize(std::addressof(event_reactor), std::addressof(ptp_object_heap)); console_main_loop.Initialize(std::addressof(event_reactor), std::addressof(ptp_object_heap)); + /* Process events until the user requests exit. */ while (!event_reactor.GetStopRequested()) { ptp_responder.HandleRequest(); } + /* Finalize the console main loop and PTP responder. */ console_main_loop.Finalize(); ptp_responder.Finalize(); + /* Restore auto sleep setting. */ appletSetAutoSleepDisabled(false); - consoleExit(NULL); + + /* Finalize the console. */ + consoleExit(nullptr); + + /* Return to the loader. */ return 0; } diff --git a/troposphere/haze/source/usb_session.cpp b/troposphere/haze/source/usb_session.cpp index fa7769c5d..57538abae 100644 --- a/troposphere/haze/source/usb_session.cpp +++ b/troposphere/haze/source/usb_session.cpp @@ -153,7 +153,7 @@ namespace haze { if (hosversionAtLeast(5, 0, 0)) { static const u16 supported_langs[1] = { 0x0409 }; - R_TRY(usbDsAddUsbLanguageStringDescriptor(NULL, supported_langs, util::size(supported_langs))); + R_TRY(usbDsAddUsbLanguageStringDescriptor(nullptr, supported_langs, util::size(supported_langs))); u8 iManufacturer, iProduct, iSerialNumber; R_TRY(usbDsAddUsbStringDescriptor(std::addressof(iManufacturer), "Nintendo"));