diff --git a/src/confighttp.cpp b/src/confighttp.cpp index c5cee1bbc..5c74ed545 100644 --- a/src/confighttp.cpp +++ b/src/confighttp.cpp @@ -532,14 +532,14 @@ namespace confighttp { #endif /** - * @brief Log the request details. + * @brief Log request details through read-only header entries. * @param request The HTTP request object. */ void print_req(const req_https_t &request) { logging::debug("METHOD :: {}", request->method); logging::debug("DESTINATION :: {}", request->path); - for (auto &[name, val] : request->header) { + for (const auto &[name, val] : request->header) { logging::debug("{} -- {}", name, (name == "Authorization" ? "CREDENTIALS REDACTED" : val)); } diff --git a/src/entry_handler.cpp b/src/entry_handler.cpp index 9079f8463..d9ce59ccc 100644 --- a/src/entry_handler.cpp +++ b/src/entry_handler.cpp @@ -310,6 +310,9 @@ namespace service_ctrl { return true; } + /** + * @brief Observe the TCP table until the configured Web UI port is listening. + */ bool wait_for_ui_ready(const config::settings_t &settings) { std::cout << "Waiting for Web UI to be ready..."; @@ -339,7 +342,7 @@ namespace service_ctrl { uint16_t port_nbo = htons(net::map_port(settings, confighttp::PORT_HTTPS)); for (DWORD i = 0; i < tcp_table->dwNumEntries; i++) { - auto &entry = tcp_table->table[i]; + const auto &entry = tcp_table->table[i]; // Look for our port in the listening state if (entry.dwLocalPort == port_nbo && entry.dwState == MIB_TCP_STATE_LISTEN) { diff --git a/src/input.cpp b/src/input.cpp index 15b55859c..bfb307505 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -984,7 +984,7 @@ namespace input { return; } - auto &touch_port = input->touch_port; + const auto &touch_port = input->touch_port; platf::abs_mouse(host.platf_input, platform_touch_port(touch_port), tpcoords->first, tpcoords->second); } @@ -1447,11 +1447,12 @@ namespace input { /** * @brief Called to pass a controller arrival message to the platform backend. + * @details Read host controller policy before allocating the client's gamepad. * @param input Shared handle retaining the mutable client input state. * @param packet Read-only controller arrival packet. */ void passthrough(const std::shared_ptr &input, const SS_CONTROLLER_ARRIVAL_PACKET *packet) { - if (auto &host = input->host; !host.settings.input.controller || host.gamepad_driver == config::GAMEPAD_DRIVER_NONE) { + if (const auto &host = input->host; !host.settings.input.controller || host.gamepad_driver == config::GAMEPAD_DRIVER_NONE) { return; } @@ -1501,7 +1502,7 @@ namespace input { }; /** - * @brief Normalize the fields shared by touch and pen packets. + * @brief Normalize the fields shared by touch and pen packets after reading host mouse policy. * * @tparam Packet Pointer type for a Moonlight touch or pen packet. * @param input Input context that supplies the current touch-port metadata. @@ -1510,7 +1511,7 @@ namespace input { */ template std::optional prepare_absolute_pointer_data(std::shared_ptr &input, Packet packet) { - if (auto &host = input->host; !host.settings.input.mouse) { + if (const auto &host = input->host; !host.settings.input.mouse) { return std::nullopt; } @@ -1611,7 +1612,7 @@ namespace input { return; } - auto &gamepad = input->gamepads[packet->controllerNumber]; + const auto &gamepad = input->gamepads[packet->controllerNumber]; if (gamepad.id < 0) { logging::warning("ControllerNumber [{}] not allocated", static_cast(packet->controllerNumber)); return; @@ -1645,7 +1646,7 @@ namespace input { return; } - auto &gamepad = input->gamepads[packet->controllerNumber]; + const auto &gamepad = input->gamepads[packet->controllerNumber]; if (gamepad.id < 0) { logging::warning("ControllerNumber [{}] not allocated", static_cast(packet->controllerNumber)); return; @@ -1678,7 +1679,7 @@ namespace input { return; } - auto &gamepad = input->gamepads[packet->controllerNumber]; + const auto &gamepad = input->gamepads[packet->controllerNumber]; if (gamepad.id < 0) { logging::warning("ControllerNumber [{}] not allocated", static_cast(packet->controllerNumber)); return; diff --git a/src/platform/linux/portalgrab.cpp b/src/platform/linux/portalgrab.cpp index d3dd25a2c..21b227a42 100644 --- a/src/platform/linux/portalgrab.cpp +++ b/src/platform/linux/portalgrab.cpp @@ -6,6 +6,7 @@ #include #include #include +#include // lib includes #include @@ -361,13 +362,16 @@ namespace portal { /** * @brief Open DBus and prepare portal screencast request handling. * + * The bus address is read through a const view while its GLib allocation is owned until initialization returns. + * * @return 0 on success; nonzero or negative platform status on failure. */ int init() { restore_token_t::load(); g_autoptr(GError) g_error = nullptr; - g_autofree gchar *address = g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SESSION, nullptr, &g_error); + std::unique_ptr address_owner {g_dbus_address_get_for_bus_sync(G_BUS_TYPE_SESSION, nullptr, &g_error), &g_free}; + const gchar *address = address_owner.get(); if (!address) { return -1; } diff --git a/src/platform/linux/vulkan_encode.cpp b/src/platform/linux/vulkan_encode.cpp index aed7b3240..0c31b6088 100644 --- a/src/platform/linux/vulkan_encode.cpp +++ b/src/platform/linux/vulkan_encode.cpp @@ -622,11 +622,11 @@ namespace vk { /** * @brief Convert a captured frame into a Vulkan hardware frame. * - * @param img Image or frame object to read from or populate. + * @param img Captured image whose DMA-BUF and cursor metadata are read without modification. * @return Conversion status. */ int convert(platf::img_t &img) override { - auto &descriptor = (egl::img_descriptor_t &) img; + const auto &descriptor = (const egl::img_descriptor_t &) img; // Get encoder target frame if (!frame->buf[0]) { @@ -1050,8 +1050,13 @@ namespace vk { } } + /** + * @brief Create encoder image views from read-only FFmpeg Vulkan frame metadata. + * + * @return True when both target plane views were created. + */ bool create_target_views() { - auto *vk_frame = (AVVkFrame *) frame->data[0]; + const auto *vk_frame = (const AVVkFrame *) frame->data[0]; if (!vk_frame) { return false; } diff --git a/src/platform/virtualhid_input.cpp b/src/platform/virtualhid_input.cpp index 11384712c..c18001c14 100644 --- a/src/platform/virtualhid_input.cpp +++ b/src/platform/virtualhid_input.cpp @@ -1,6 +1,7 @@ /** * @file src/platform/virtualhid_input.cpp * @brief Definitions for libvirtualhid-backed input helpers. + * @details Gamepad event handlers keep their shared handles unchanged while updating the referenced context and adapter state. */ // standard includes @@ -818,7 +819,7 @@ namespace platf::virtualhid { return; } - auto &gamepad = context.gamepads[nr]; + const auto &gamepad = context.gamepads[nr]; auto updated_state = make_gamepad_state(context.settings.get(), state, gamepad->adapter->support()); const auto &cached_state = gamepad->adapter->state(); updated_state.acceleration = cached_state.acceleration; @@ -833,7 +834,7 @@ namespace platf::virtualhid { return; } - auto &gamepad = context.gamepads[touch.id.globalIndex]; + const auto &gamepad = context.gamepads[touch.id.globalIndex]; if (!gamepad->adapter->support().supports_touchpad) { return; } @@ -887,7 +888,7 @@ namespace platf::virtualhid { return; } - auto &gamepad = context.gamepads[motion.id.globalIndex]; + const auto &gamepad = context.gamepads[motion.id.globalIndex]; switch (motion.motionType) { case LI_MOTION_TYPE_ACCEL: log_failure("submit libvirtualhid gamepad acceleration"sv, gamepad->adapter->set_acceleration(lvh::Vector3 {motion.x, motion.y, motion.z})); @@ -905,7 +906,7 @@ namespace platf::virtualhid { return; } - auto &gamepad = context.gamepads[battery.id.globalIndex]; + const auto &gamepad = context.gamepads[battery.id.globalIndex]; if (battery.state == LI_BATTERY_STATE_UNKNOWN || battery.state == LI_BATTERY_STATE_NOT_PRESENT) { log_failure("clear libvirtualhid gamepad battery"sv, gamepad->adapter->clear_battery()); return; diff --git a/src/platform/windows/audio.cpp b/src/platform/windows/audio.cpp index 64ff218f0..2c7445c60 100644 --- a/src/platform/windows/audio.cpp +++ b/src/platform/windows/audio.cpp @@ -1085,7 +1085,7 @@ namespace platf::audio { prop_var_t current_device_format; if (SUCCEEDED(current_default_dev->OpenPropertyStore(STGM_READ, &prop)) && SUCCEEDED(prop->GetValue(PKEY_AudioEngine_DeviceFormat, ¤t_device_format.prop))) { - auto *format = (WAVEFORMATEXTENSIBLE *) current_device_format.prop.blob.pBlobData; + const auto *format = (const WAVEFORMATEXTENSIBLE *) current_device_format.prop.blob.pBlobData; ///< Read-only endpoint format owned by the property variant. wanted_bits_per_sample = format->Samples.wValidBitsPerSample; logging::info("Virtual audio device will use {}-bit to match default device", wanted_bits_per_sample); } diff --git a/src/process.cpp b/src/process.cpp index 15dc9b9a4..5d90b7d08 100644 --- a/src/process.cpp +++ b/src/process.cpp @@ -190,6 +190,10 @@ namespace proc { #endif } + /** + * @brief Execute the selected application and its configured preparation commands. + * @note Detached command definitions are observed without rewriting the configured strings. + */ int proc_t::execute(int app_id, std::shared_ptr launch_session) { // Ensure starting from a clean slate terminate(); @@ -294,7 +298,7 @@ namespace proc { } } - for (auto &cmd : _app.detached) { + for (const auto &cmd : _app.detached) { const auto command = prepare_command(cmd); boost::filesystem::path working_dir = _app.working_dir.empty() ? find_working_directory(command) : diff --git a/src/rtsp.cpp b/src/rtsp.cpp index fd2161502..27f50063a 100644 --- a/src/rtsp.cpp +++ b/src/rtsp.cpp @@ -116,7 +116,7 @@ namespace rtsp_stream { using cmd_func_t = std::function; /** - * @brief Write msg details to the log. + * @brief Log request or response fields without modifying the message. * * @param msg Raw RTSP message buffer being parsed or encrypted. */ @@ -1478,7 +1478,7 @@ namespace rtsp_stream { logging::debug("payload :: {}", payload); if (msg->type == TYPE_RESPONSE) { - auto &resp = msg->message.response; + const auto &resp = msg->message.response; auto statuscode = resp.statusCode; std::string_view status {resp.statusString}; @@ -1486,7 +1486,7 @@ namespace rtsp_stream { logging::debug("statuscode :: {}", statuscode); logging::debug("status :: {}", status); } else { - auto &req = msg->message.request; + const auto &req = msg->message.request; std::string_view command {req.command}; std::string_view target {req.target}; diff --git a/src/stream.cpp b/src/stream.cpp index 5f611fe15..c3e72831e 100644 --- a/src/stream.cpp +++ b/src/stream.cpp @@ -1257,7 +1257,8 @@ namespace stream { /** * @brief Run the broadcast control-channel worker thread. - * @note Logging-only callbacks retain the dispatcher signature and omit unused argument names. + * @note Logging-only callbacks retain the dispatcher signature, omit unused argument names, + * and observe packet statistics through a read-only view. * * @param server RTSP server instance handling the request. */ @@ -1276,7 +1277,7 @@ namespace stream { }); server->map(packetTypes[IDX_LOSS_STATS], [](session_t *, const std::string_view &payload) { - int32_t *stats = (int32_t *) payload.data(); + const int32_t *stats = (const int32_t *) payload.data(); auto count = stats[0]; std::chrono::milliseconds t {stats[1]}; diff --git a/tests/unit/test_entry_handler.cpp b/tests/unit/test_entry_handler.cpp index 0c1c6b29c..b93a0f486 100644 --- a/tests/unit/test_entry_handler.cpp +++ b/tests/unit/test_entry_handler.cpp @@ -159,7 +159,7 @@ TEST(EntryHandlerTests, InfrastructureDestructionJoinsWorkBeforeDependencyCleanu auto *owner = infrastructure.get(); const std::weak_ptr mailbox = owner->mailbox(); #ifdef _WIN32 - auto *preferences = &owner->preferences(); + const auto *preferences = &owner->preferences(); ///< Read-only identity checked before the preferences owner is released. #endif std::promise started; std::promise release;