time.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <array>
  6. #include "common/common_funcs.h"
  7. #include "core/hle/service/service.h"
  8. namespace Service::Time {
  9. struct LocationName {
  10. std::array<u8, 0x24> name;
  11. };
  12. static_assert(sizeof(LocationName) == 0x24, "LocationName is incorrect size");
  13. struct CalendarTime {
  14. u16_le year;
  15. u8 month; // Starts at 1
  16. u8 day; // Starts at 1
  17. u8 hour;
  18. u8 minute;
  19. u8 second;
  20. };
  21. static_assert(sizeof(CalendarTime) == 0x8, "CalendarTime structure has incorrect size");
  22. struct CalendarAdditionalInfo {
  23. u32_le day_of_week;
  24. u32_le day_of_year;
  25. std::array<u8, 8> name;
  26. u8 is_dst;
  27. s32_le utc_offset;
  28. };
  29. static_assert(sizeof(CalendarAdditionalInfo) == 0x18,
  30. "CalendarAdditionalInfo structure has incorrect size");
  31. // TODO(mailwl) RE this structure
  32. struct TimeZoneRule {
  33. INSERT_PADDING_BYTES(0x4000);
  34. };
  35. struct SteadyClockTimePoint {
  36. using SourceID = std::array<u8, 16>;
  37. u64_le value;
  38. SourceID source_id;
  39. };
  40. static_assert(sizeof(SteadyClockTimePoint) == 0x18, "SteadyClockTimePoint is incorrect size");
  41. struct SystemClockContext {
  42. u64_le offset;
  43. SteadyClockTimePoint time_point;
  44. };
  45. static_assert(sizeof(SystemClockContext) == 0x20,
  46. "SystemClockContext structure has incorrect size");
  47. struct ClockSnapshot {
  48. SystemClockContext user_clock_context;
  49. SystemClockContext network_clock_context;
  50. s64_le system_posix_time;
  51. s64_le network_posix_time;
  52. CalendarTime system_calendar_time;
  53. CalendarTime network_calendar_time;
  54. CalendarAdditionalInfo system_calendar_info;
  55. CalendarAdditionalInfo network_calendar_info;
  56. SteadyClockTimePoint steady_clock_timepoint;
  57. LocationName location_name;
  58. u8 clock_auto_adjustment_enabled;
  59. u8 type;
  60. u8 version;
  61. INSERT_PADDING_BYTES(1);
  62. };
  63. static_assert(sizeof(ClockSnapshot) == 0xd0, "ClockSnapshot is an invalid size");
  64. class Module final {
  65. public:
  66. class Interface : public ServiceFramework<Interface> {
  67. public:
  68. explicit Interface(std::shared_ptr<Module> time, const char* name);
  69. ~Interface() override;
  70. void GetStandardUserSystemClock(Kernel::HLERequestContext& ctx);
  71. void GetStandardNetworkSystemClock(Kernel::HLERequestContext& ctx);
  72. void GetStandardSteadyClock(Kernel::HLERequestContext& ctx);
  73. void GetTimeZoneService(Kernel::HLERequestContext& ctx);
  74. void GetStandardLocalSystemClock(Kernel::HLERequestContext& ctx);
  75. void GetClockSnapshot(Kernel::HLERequestContext& ctx);
  76. void CalculateStandardUserSystemClockDifferenceByUser(Kernel::HLERequestContext& ctx);
  77. protected:
  78. std::shared_ptr<Module> time;
  79. };
  80. };
  81. /// Registers all Time services with the specified service manager.
  82. void InstallInterfaces(SM::ServiceManager& service_manager);
  83. } // namespace Service::Time