From 9ed82a280e8f22dbd119b4b7becd3582b50f3ffa Mon Sep 17 00:00:00 2001 From: Kelebek1 Date: Tue, 30 Jan 2024 19:08:47 +0000 Subject: Remove a few hacks for clock setups, which seem to no longer be needed, but fix network clock to local clock on every boot. Also fix some logging strings. --- src/core/hle/service/glue/time/time_zone.cpp | 27 ++++++-------- src/core/hle/service/glue/time/time_zone.h | 6 ++-- src/core/hle/service/psc/time/common.h | 24 ++++++------- src/core/hle/service/psc/time/service_manager.cpp | 14 ++------ src/core/hle/service/psc/time/time_zone.cpp | 41 ++++++++++++---------- src/core/hle/service/psc/time/time_zone.h | 12 +++---- .../hle/service/psc/time/time_zone_service.cpp | 20 +++++------ src/core/hle/service/psc/time/time_zone_service.h | 4 +-- .../hle/service/set/system_settings_server.cpp | 2 +- 9 files changed, 66 insertions(+), 84 deletions(-) diff --git a/src/core/hle/service/glue/time/time_zone.cpp b/src/core/hle/service/glue/time/time_zone.cpp index 5dc1187cb..98d928697 100644 --- a/src/core/hle/service/glue/time/time_zone.cpp +++ b/src/core/hle/service/glue/time/time_zone.cpp @@ -197,32 +197,27 @@ Result TimeZoneService::ToCalendarTimeWithMyRule( Result TimeZoneService::ToPosixTime(Out out_count, OutArray out_times, - Out out_times_count, - Service::PSC::Time::CalendarTime& calendar_time, InRule rule) { + const Service::PSC::Time::CalendarTime& calendar_time, + InRule rule) { SCOPE_EXIT({ LOG_DEBUG(Service_Time, - "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} " - "out_times_count={}", - calendar_time, *out_count, out_times[0], out_times[1], *out_times_count); + "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={}", + calendar_time, *out_count, out_times[0], out_times[1]); }); - R_RETURN( - m_wrapped_service->ToPosixTime(out_count, out_times, out_times_count, calendar_time, rule)); + R_RETURN(m_wrapped_service->ToPosixTime(out_count, out_times, calendar_time, rule)); } -Result TimeZoneService::ToPosixTimeWithMyRule(Out out_count, - OutArray out_times, - Out out_times_count, - Service::PSC::Time::CalendarTime& calendar_time) { +Result TimeZoneService::ToPosixTimeWithMyRule( + Out out_count, OutArray out_times, + const Service::PSC::Time::CalendarTime& calendar_time) { SCOPE_EXIT({ LOG_DEBUG(Service_Time, - "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} " - "out_times_count={}", - calendar_time, *out_count, out_times[0], out_times[1], *out_times_count); + "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={}", + calendar_time, *out_count, out_times[0], out_times[1]); }); - R_RETURN(m_wrapped_service->ToPosixTimeWithMyRule(out_count, out_times, out_times_count, - calendar_time)); + R_RETURN(m_wrapped_service->ToPosixTimeWithMyRule(out_count, out_times, calendar_time)); } } // namespace Service::Glue::Time diff --git a/src/core/hle/service/glue/time/time_zone.h b/src/core/hle/service/glue/time/time_zone.h index bf12adbdc..9c1530966 100644 --- a/src/core/hle/service/glue/time/time_zone.h +++ b/src/core/hle/service/glue/time/time_zone.h @@ -68,12 +68,10 @@ public: Out out_calendar_time, Out out_additional_info, s64 time); Result ToPosixTime(Out out_count, OutArray out_times, - Out out_times_count, Service::PSC::Time::CalendarTime& calendar_time, - InRule rule); + const Service::PSC::Time::CalendarTime& calendar_time, InRule rule); Result ToPosixTimeWithMyRule(Out out_count, OutArray out_times, - Out out_times_count, - Service::PSC::Time::CalendarTime& calendar_time); + const Service::PSC::Time::CalendarTime& calendar_time); private: Core::System& m_system; diff --git a/src/core/hle/service/psc/time/common.h b/src/core/hle/service/psc/time/common.h index 596828b8b..3e13144a0 100644 --- a/src/core/hle/service/psc/time/common.h +++ b/src/core/hle/service/psc/time/common.h @@ -189,7 +189,7 @@ struct fmt::formatter : fmt::formatter template auto format(const Service::PSC::Time::SteadyClockTimePoint& time_point, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "time_point={}", time_point.time_point); + return fmt::format_to(ctx.out(), "[time_point={}]", time_point.time_point); } }; @@ -197,7 +197,7 @@ template <> struct fmt::formatter : fmt::formatter { template auto format(const Service::PSC::Time::SystemClockContext& context, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "offset={} steady_time_point={}", context.offset, + return fmt::format_to(ctx.out(), "[offset={} steady_time_point={}]", context.offset, context.steady_time_point.time_point); } }; @@ -206,8 +206,9 @@ template <> struct fmt::formatter : fmt::formatter { template auto format(const Service::PSC::Time::CalendarTime& calendar, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "{}/{}/{} {}:{}:{}", calendar.day, calendar.month, - calendar.year, calendar.hour, calendar.minute, calendar.second); + return fmt::format_to(ctx.out(), "[{:02}/{:02}/{:04} {:02}:{:02}:{:02}]", calendar.day, + calendar.month, calendar.year, calendar.hour, calendar.minute, + calendar.second); } }; @@ -217,7 +218,7 @@ struct fmt::formatter template auto format(const Service::PSC::Time::CalendarAdditionalInfo& additional, FormatContext& ctx) const { - return fmt::format_to(ctx.out(), "weekday={} yearday={} name={} is_dst={} ut_offset={}", + return fmt::format_to(ctx.out(), "[weekday={} yearday={} name={} is_dst={} ut_offset={}]", additional.day_of_week, additional.day_of_year, additional.name.data(), additional.is_dst, additional.ut_offset); } @@ -227,8 +228,7 @@ template <> struct fmt::formatter : fmt::formatter { template auto format(const Service::PSC::Time::LocationName& name, FormatContext& ctx) const { - std::string_view n{name.data(), name.size()}; - return formatter::format(n, ctx); + return formatter::format(name.data(), ctx); } }; @@ -236,8 +236,7 @@ template <> struct fmt::formatter : fmt::formatter { template auto format(const Service::PSC::Time::RuleVersion& version, FormatContext& ctx) const { - std::string_view v{version.data(), version.size()}; - return formatter::format(v, ctx); + return formatter::format(version.data(), ctx); } }; @@ -247,10 +246,11 @@ struct fmt::formatter : fmt::formatter auto format(const Service::PSC::Time::ContinuousAdjustmentTimePoint& time_point, FormatContext& ctx) const { return fmt::format_to(ctx.out(), - "rtc_offset={} diff_scale={} shift_amount={} lower={} upper={}", + "[rtc_offset={} diff_scale={} shift_amount={} lower={} upper={}]", time_point.rtc_offset, time_point.diff_scale, time_point.shift_amount, time_point.lower, time_point.upper); } diff --git a/src/core/hle/service/psc/time/service_manager.cpp b/src/core/hle/service/psc/time/service_manager.cpp index ec906b723..4e1643fcb 100644 --- a/src/core/hle/service/psc/time/service_manager.cpp +++ b/src/core/hle/service/psc/time/service_manager.cpp @@ -120,11 +120,8 @@ Result ServiceManager::SetupStandardNetworkSystemClockCore(SystemClockContext& c context, context.steady_time_point.clock_source_id.RawString(), accuracy); // TODO this is a hack! The network clock should be updated independently, from the ntc service - // and maybe elsewhere. We do not do that, so fix the clock to the local clock on first boot - // to avoid it being stuck at 0. - if (context == Service::PSC::Time::SystemClockContext{}) { - m_local_system_clock.GetContext(context); - } + // and maybe elsewhere. We do not do that, so fix the clock to the local clock. + m_local_system_clock.GetContext(context); m_network_system_clock.SetContextWriter(m_network_system_context_writer); m_network_system_clock.Initialize(context, accuracy); @@ -138,13 +135,6 @@ Result ServiceManager::SetupStandardUserSystemClockCore(bool automatic_correctio LOG_DEBUG(Service_Time, "called. automatic_correction={} time_point={} clock_source_id={}", automatic_correction, time_point, time_point.clock_source_id.RawString()); - // TODO this is a hack! The user clock should be updated independently, from the ntc service - // and maybe elsewhere. We do not do that, so fix the clock to the local clock on first boot - // to avoid it being stuck at 0. - if (time_point == Service::PSC::Time::SteadyClockTimePoint{}) { - m_local_system_clock.GetCurrentTimePoint(time_point); - } - m_user_system_clock.SetAutomaticCorrection(automatic_correction); m_user_system_clock.SetTimePointAndSignal(time_point); m_user_system_clock.SetInitialized(); diff --git a/src/core/hle/service/psc/time/time_zone.cpp b/src/core/hle/service/psc/time/time_zone.cpp index 82ddba42f..cc855c763 100644 --- a/src/core/hle/service/psc/time/time_zone.cpp +++ b/src/core/hle/service/psc/time/time_zone.cpp @@ -140,11 +140,11 @@ Result TimeZone::ParseBinaryInto(Tz::Rule& out_rule, std::span binary) R_RETURN(ParseBinaryImpl(out_rule, binary)); } -Result TimeZone::ToPosixTime(u32& out_count, std::span out_times, u32 out_times_count, - CalendarTime& calendar, const Tz::Rule& rule) { +Result TimeZone::ToPosixTime(u32& out_count, std::span out_times, size_t out_times_max_count, + const CalendarTime& calendar, const Tz::Rule& rule) { std::scoped_lock l{m_mutex}; - auto res = ToPosixTimeImpl(out_count, out_times, out_times_count, calendar, rule, -1); + auto res = ToPosixTimeImpl(out_count, out_times, out_times_max_count, calendar, rule, -1); if (res != ResultSuccess) { if (res == ResultTimeZoneNotFound) { @@ -158,10 +158,10 @@ Result TimeZone::ToPosixTime(u32& out_count, std::span out_times, u32 out_t } Result TimeZone::ToPosixTimeWithMyRule(u32& out_count, std::span out_times, - u32 out_times_count, CalendarTime& calendar) { + size_t out_times_max_count, const CalendarTime& calendar) { std::scoped_lock l{m_mutex}; - auto res = ToPosixTimeImpl(out_count, out_times, out_times_count, calendar, m_my_rule, -1); + auto res = ToPosixTimeImpl(out_count, out_times, out_times_max_count, calendar, m_my_rule, -1); if (res != ResultSuccess) { if (res == ResultTimeZoneNotFound) { @@ -212,20 +212,23 @@ Result TimeZone::ToCalendarTimeImpl(CalendarTime& out_calendar_time, R_SUCCEED(); } -Result TimeZone::ToPosixTimeImpl(u32& out_count, std::span out_times, u32 out_times_count, - CalendarTime& calendar, const Tz::Rule& rule, s32 is_dst) { +Result TimeZone::ToPosixTimeImpl(u32& out_count, std::span out_times, + size_t out_times_max_count, const CalendarTime& calendar, + const Tz::Rule& rule, s32 is_dst) { R_TRY(ValidateRule(rule)); - calendar.month -= 1; - calendar.year -= 1900; + CalendarTime local_calendar{calendar}; + + local_calendar.month -= 1; + local_calendar.year -= 1900; Tz::CalendarTimeInternal internal{ - .tm_sec = calendar.second, - .tm_min = calendar.minute, - .tm_hour = calendar.hour, - .tm_mday = calendar.day, - .tm_mon = calendar.month, - .tm_year = calendar.year, + .tm_sec = local_calendar.second, + .tm_min = local_calendar.minute, + .tm_hour = local_calendar.hour, + .tm_mday = local_calendar.day, + .tm_mon = local_calendar.month, + .tm_year = local_calendar.year, .tm_wday = 0, .tm_yday = 0, .tm_isdst = is_dst, @@ -243,9 +246,9 @@ Result TimeZone::ToPosixTimeImpl(u32& out_count, std::span out_times, u32 o R_RETURN(ResultTimeZoneNotFound); } - if (internal.tm_sec != calendar.second || internal.tm_min != calendar.minute || - internal.tm_hour != calendar.hour || internal.tm_mday != calendar.day || - internal.tm_mon != calendar.month || internal.tm_year != calendar.year) { + if (internal.tm_sec != local_calendar.second || internal.tm_min != local_calendar.minute || + internal.tm_hour != local_calendar.hour || internal.tm_mday != local_calendar.day || + internal.tm_mon != local_calendar.month || internal.tm_year != local_calendar.year) { R_RETURN(ResultTimeZoneNotFound); } @@ -254,7 +257,7 @@ Result TimeZone::ToPosixTimeImpl(u32& out_count, std::span out_times, u32 o } out_times[0] = time; - if (out_times_count < 2) { + if (out_times_max_count < 2) { out_count = 1; R_SUCCEED(); } diff --git a/src/core/hle/service/psc/time/time_zone.h b/src/core/hle/service/psc/time/time_zone.h index 6bd8f2fda..6248e45f9 100644 --- a/src/core/hle/service/psc/time/time_zone.h +++ b/src/core/hle/service/psc/time/time_zone.h @@ -38,18 +38,18 @@ public: CalendarAdditionalInfo& calendar_additional, s64 time); Result ParseBinary(LocationName& name, std::span binary); Result ParseBinaryInto(Tz::Rule& out_rule, std::span binary); - Result ToPosixTime(u32& out_count, std::span out_times, u32 out_times_count, - CalendarTime& calendar, const Tz::Rule& rule); - Result ToPosixTimeWithMyRule(u32& out_count, std::span out_times, u32 out_times_count, - CalendarTime& calendar); + Result ToPosixTime(u32& out_count, std::span out_times, size_t out_times_max_count, + const CalendarTime& calendar, const Tz::Rule& rule); + Result ToPosixTimeWithMyRule(u32& out_count, std::span out_times, + size_t out_times_max_count, const CalendarTime& calendar); private: Result ParseBinaryImpl(Tz::Rule& out_rule, std::span binary); Result ToCalendarTimeImpl(CalendarTime& out_calendar_time, CalendarAdditionalInfo& out_additional_info, s64 time, const Tz::Rule& rule); - Result ToPosixTimeImpl(u32& out_count, std::span out_times, u32 out_times_count, - CalendarTime& calendar, const Tz::Rule& rule, s32 is_dst); + Result ToPosixTimeImpl(u32& out_count, std::span out_times, size_t out_times_max_count, + const CalendarTime& calendar, const Tz::Rule& rule, s32 is_dst); bool m_initialized{}; std::recursive_mutex m_mutex; diff --git a/src/core/hle/service/psc/time/time_zone_service.cpp b/src/core/hle/service/psc/time/time_zone_service.cpp index 9376a0324..eb81f5b03 100644 --- a/src/core/hle/service/psc/time/time_zone_service.cpp +++ b/src/core/hle/service/psc/time/time_zone_service.cpp @@ -138,32 +138,28 @@ Result TimeZoneService::ToCalendarTimeWithMyRule(Out out_calendar_ Result TimeZoneService::ToPosixTime(Out out_count, OutArray out_times, - Out out_times_count, CalendarTime& calendar_time, - InRule rule) { + const CalendarTime& calendar_time, InRule rule) { SCOPE_EXIT({ LOG_DEBUG(Service_Time, - "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} " - "out_times_count={}", - calendar_time, *out_count, out_times[0], out_times[1], *out_times_count); + "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} ", + calendar_time, *out_count, out_times[0], out_times[1]); }); R_RETURN( - m_time_zone.ToPosixTime(*out_count, out_times, *out_times_count, calendar_time, *rule)); + m_time_zone.ToPosixTime(*out_count, out_times, out_times.size(), calendar_time, *rule)); } Result TimeZoneService::ToPosixTimeWithMyRule(Out out_count, OutArray out_times, - Out out_times_count, - CalendarTime& calendar_time) { + const CalendarTime& calendar_time) { SCOPE_EXIT({ LOG_DEBUG(Service_Time, - "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} " - "out_times_count={}", - calendar_time, *out_count, out_times[0], out_times[1], *out_times_count); + "called. calendar_time={} out_count={} out_times[0]={} out_times[1]={} ", + calendar_time, *out_count, out_times[0], out_times[1]); }); R_RETURN( - m_time_zone.ToPosixTimeWithMyRule(*out_count, out_times, *out_times_count, calendar_time)); + m_time_zone.ToPosixTimeWithMyRule(*out_count, out_times, out_times.size(), calendar_time)); } } // namespace Service::PSC::Time diff --git a/src/core/hle/service/psc/time/time_zone_service.h b/src/core/hle/service/psc/time/time_zone_service.h index 084e3f907..6eb9ddc4b 100644 --- a/src/core/hle/service/psc/time/time_zone_service.h +++ b/src/core/hle/service/psc/time/time_zone_service.h @@ -50,10 +50,10 @@ public: Result ToCalendarTimeWithMyRule(Out out_calendar_time, Out out_additional_info, s64 time); Result ToPosixTime(Out out_count, OutArray out_times, - Out out_times_count, CalendarTime& calendar_time, InRule rule); + const CalendarTime& calendar_time, InRule rule); Result ToPosixTimeWithMyRule(Out out_count, OutArray out_times, - Out out_times_count, CalendarTime& calendar_time); + const CalendarTime& calendar_time); private: Core::System& m_system; diff --git a/src/core/hle/service/set/system_settings_server.cpp b/src/core/hle/service/set/system_settings_server.cpp index 100cb2db4..d3d0fb112 100644 --- a/src/core/hle/service/set/system_settings_server.cpp +++ b/src/core/hle/service/set/system_settings_server.cpp @@ -25,7 +25,7 @@ namespace Service::Set { namespace { -constexpr u32 SETTINGS_VERSION{2u}; +constexpr u32 SETTINGS_VERSION{3u}; constexpr auto SETTINGS_MAGIC = Common::MakeMagic('y', 'u', 'z', 'u', '_', 's', 'e', 't'); struct SettingsHeader { u64 magic; -- cgit v1.2.3