Skip to content

Commit

Permalink
sonar cloud
Browse files Browse the repository at this point in the history
  • Loading branch information
FrogTheFrog committed Dec 11, 2024
1 parent 3f37821 commit cd91683
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 39 deletions.
2 changes: 1 addition & 1 deletion src/confighttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ namespace confighttp {
print_req(request);

Check warning on line 742 in src/confighttp.cpp

View check run for this annotation

Codecov / codecov/patch

src/confighttp.cpp#L742

Added line #L742 was not covered by tests

pt::ptree outputTree;

Check warning on line 744 in src/confighttp.cpp

View check run for this annotation

Codecov / codecov/patch

src/confighttp.cpp#L744

Added line #L744 was not covered by tests
auto g = util::fail_guard([&]() {
auto g = util::fail_guard([&outputTree, &response]() {
std::ostringstream data;

Check warning on line 746 in src/confighttp.cpp

View check run for this annotation

Codecov / codecov/patch

src/confighttp.cpp#L746

Added line #L746 was not covered by tests
pt::write_json(data, outputTree);
response->write(data.str());
Expand Down
78 changes: 43 additions & 35 deletions src/display_device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ namespace display_device {
if (audio_context) {
audio_context->released = true;

// It is possible that the audio sink is not immediately available after the display is turned on.
// Therefore, we will hold on to the audio context a little longer, until it is either available
// or we time out.
const auto *audio_ctx_ptr = audio_context->audio_ctx_ref.get();
if (audio_ctx_ptr && !audio::is_audio_ctx_sink_available(*audio_ctx_ptr)) {
if (audio_context->retry_counter > 0) {
if (audio_ctx_ptr) {
// It is possible that the audio sink is not immediately available after the display is turned on.
// Therefore, we will hold on to the audio context a little longer, until it is either available
// or we time out.
if (!audio::is_audio_ctx_sink_available(*audio_ctx_ptr) && audio_context->retry_counter > 0) {
--audio_context->retry_counter;
return;
}
Expand Down Expand Up @@ -145,10 +145,10 @@ namespace display_device {
* std::optional<Resolution> resolution;
* if (parse_resolution_string("1920x1080", resolution)) {
* if (resolution) {
* // Value was specified
* BOOST_LOG(info) << "Value was specified";
* }
* else {
* // Value was empty
* BOOST_LOG(info) << "Value was empty";
* }
* }
* @examples_end
Expand All @@ -158,8 +158,7 @@ namespace display_device {
const std::string trimmed_input { boost::algorithm::trim_copy(input) };
const std::regex resolution_regex { R"(^(\d+)x(\d+)$)" };

std::smatch match;
if (std::regex_match(trimmed_input, match, resolution_regex)) {
if (std::smatch match; std::regex_match(trimmed_input, match, resolution_regex)) {
try {
output = Resolution {
stou(match[1].str()),
Expand All @@ -181,7 +180,7 @@ namespace display_device {
return true;
}

BOOST_LOG(error) << "Failed to parse resolution string " << trimmed_input << ". It must match a \"1920x1080\" pattern!";
BOOST_LOG(error) << "Failed to parse resolution string " << trimmed_input << R"(. It must match a "1920x1080" pattern!)";
}

return false;
Expand All @@ -197,10 +196,10 @@ namespace display_device {
* std::optional<FloatingPoint> refresh_rate;
* if (parse_refresh_rate_string("59.95", refresh_rate)) {
* if (refresh_rate) {
* // Value was specified
* BOOST_LOG(info) << "Value was specified";
* }
* else {
* // Value was empty
* BOOST_LOG(info) << "Value was empty";
* }
* }
* @examples_end
Expand All @@ -211,13 +210,12 @@ namespace display_device {
const std::string trimmed_input { boost::algorithm::trim_copy(input) };
const std::regex refresh_rate_regex { R"(^(\d+)(?:\.(\d+))?$)" };

std::smatch match;
if (std::regex_match(trimmed_input, match, refresh_rate_regex)) {
if (std::smatch match; std::regex_match(trimmed_input, match, refresh_rate_regex)) {
try {
// Here we are trimming zeros from the string to possibly reduce out of bounds case
std::string trimmed_match_1 { boost::algorithm::trim_left_copy_if(match[1].str(), is_zero) };
if (trimmed_match_1.empty()) {
trimmed_match_1 = "0"s; // Just in case ALL of the string is full of zeros, we want to leave one
trimmed_match_1 = "0"s; // Just in case ALL the string is full of zeros, we want to leave one
}

std::string trimmed_match_2;
Expand Down Expand Up @@ -265,7 +263,7 @@ namespace display_device {
return true;
}

BOOST_LOG(error) << "Failed to parse refresh rate string " << trimmed_input << ". Must have a pattern of \"123\" or \"123.456\"!";
BOOST_LOG(error) << "Failed to parse refresh rate string " << trimmed_input << R"(. Must have a pattern of "123" or "123.456"!)";
}

return false;
Expand All @@ -284,19 +282,19 @@ namespace display_device {
*/
std::optional<SingleDisplayConfiguration::DevicePreparation>
parse_device_prep_option(const config::video_t &video_config) {
using config_option_e = config::video_t::dd_t::config_option_e;
using device_prep_e = SingleDisplayConfiguration::DevicePreparation;
using enum config::video_t::dd_t::config_option_e;
using enum SingleDisplayConfiguration::DevicePreparation;

switch (video_config.dd.configuration_option) {
case config_option_e::verify_only:
return device_prep_e::VerifyOnly;
case config_option_e::ensure_active:
return device_prep_e::EnsureActive;
case config_option_e::ensure_primary:
return device_prep_e::EnsurePrimary;
case config_option_e::ensure_only_display:
return device_prep_e::EnsureOnlyDisplay;
case config_option_e::disabled:
case verify_only:
return VerifyOnly;
case ensure_active:
return EnsureActive;
case ensure_primary:
return EnsurePrimary;
case ensure_only_display:
return EnsureOnlyDisplay;
case disabled:
break;
}

Expand All @@ -311,7 +309,7 @@ namespace display_device {
* @returns True on successful parsing, false otherwise.
*
* @examples
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session; // Assuming ptr is properly initialized
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session;
* const config::video_t &video_config { config::video };
*
* SingleDisplayConfiguration config;
Expand All @@ -325,7 +323,7 @@ namespace display_device {
switch (video_config.dd.resolution_option) {
case resolution_option_e::automatic: {
if (!session.enable_sops) {
BOOST_LOG(warning) << "Sunshine is configured to change resolution automatically, but the \"Optimize game settings\" is not set in the client! Resolution will not be changed.";
BOOST_LOG(warning) << R"(Sunshine is configured to change resolution automatically, but the "Optimize game settings" is not set in the client! Resolution will not be changed.)";
}
else if (session.width >= 0 && session.height >= 0) {
config.m_resolution = Resolution {
Expand All @@ -341,7 +339,7 @@ namespace display_device {
}
case resolution_option_e::manual: {
if (!session.enable_sops) {
BOOST_LOG(warning) << "Sunshine is configured to change resolution manually, but the \"Optimize game settings\" is not set in the client! Resolution will not be changed.";
BOOST_LOG(warning) << R"(Sunshine is configured to change resolution manually, but the "Optimize game settings" is not set in the client! Resolution will not be changed.)";
}
else {
if (!parse_resolution_string(video_config.dd.manual_resolution, config.m_resolution)) {
Expand Down Expand Up @@ -371,7 +369,7 @@ namespace display_device {
* @returns True on successful parsing, false otherwise.
*
* @examples
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session; // Assuming ptr is properly initialized
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session;
* const config::video_t &video_config { config::video };
*
* SingleDisplayConfiguration config;
Expand Down Expand Up @@ -420,7 +418,7 @@ namespace display_device {
* Empty optional if no action is required.
*
* @examples
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session; // Assuming ptr is properly initialized
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session;
* const config::video_t &video_config { config::video };
* const auto hdr_option = parse_hdr_option(video_config, *launch_session);
* @examples_end
Expand All @@ -446,7 +444,7 @@ namespace display_device {
* @return An interface or nullptr if the OS does not support the interface.
*/
std::unique_ptr<SettingsManagerInterface>
make_settings_manager(const std::filesystem::path &persistence_filepath, const config::video_t &video_config) {
make_settings_manager([[maybe_unused]] const std::filesystem::path &persistence_filepath, [[maybe_unused]] const config::video_t &video_config) {

Check warning on line 447 in src/display_device.cpp

View check run for this annotation

Codecov / codecov/patch

src/display_device.cpp#L447

Added line #L447 was not covered by tests
#ifdef _WIN32
return std::make_unique<SettingsManager>(
std::make_shared<WinDisplayDevice>(std::make_shared<WinApiLayer>()),
Expand Down Expand Up @@ -523,7 +521,17 @@ namespace display_device {
public:
~deinit_t() override {
std::lock_guard lock { DD_DATA.mutex };
revert_configuration_unlocked(revert_option_e::try_once);
try {
// This may throw if used incorrectly. At the moment this will not happen, however
// in case some unforeseen changes are made that could raise an exception,
// we definitely don't want this to happen in destructor. Especially in the
// deinit_t where the outcome does not really matter.
revert_configuration_unlocked(revert_option_e::try_once);
}
catch (std::exception &err) {
BOOST_LOG(fatal) << err.what();
}

DD_DATA.sm_instance = nullptr;

Check warning on line 535 in src/display_device.cpp

View check run for this annotation

Codecov / codecov/patch

src/display_device.cpp#L535

Added line #L535 was not covered by tests
}
};
Expand Down Expand Up @@ -591,7 +599,7 @@ namespace display_device {
}

return DD_DATA.sm_instance->execute([](auto &settings_iface, auto &stop_token) {
// Whatever the outcome is we want to stop interfering with the used,
// Whatever the outcome is we want to stop interfering with the user,
// so any schedulers need to be stopped.
stop_token.requestStop();
return settings_iface.resetPersistence();

Check warning on line 605 in src/display_device.cpp

View check run for this annotation

Codecov / codecov/patch

src/display_device.cpp#L604-L605

Added lines #L604 - L605 were not covered by tests
Expand Down
6 changes: 3 additions & 3 deletions src/display_device.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ namespace display_device {
* @param session Session information.
*
* @examples
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session; // Assuming ptr is properly initialized
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session;
* const config::video_t &video_config { config::video };
*
* configure_display(video_config, *launch_session);
Expand Down Expand Up @@ -138,10 +138,10 @@ namespace display_device {
* @param session Session information.
* @return Parsed single display configuration or
* a tag indicating that the parsing has failed or
* a tag indicating that the user does not want perform any configuration.
* a tag indicating that the user does not want to perform any configuration.
*
* @examples
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session; // Assuming ptr is properly initialized
* const std::shared_ptr<rtsp_stream::launch_session_t> launch_session;
* const config::video_t &video_config { config::video };
*
* const auto config { parse_configuration(video_config, *launch_session) };
Expand Down

0 comments on commit cd91683

Please sign in to comment.