diff --git a/app/CMakeLists.txt b/app/CMakeLists.txt index 27f99cd4..a485cffe 100644 --- a/app/CMakeLists.txt +++ b/app/CMakeLists.txt @@ -92,6 +92,7 @@ add_library(skyline SHARED ${source_DIR}/skyline/services/hid/IAppletResource.cpp ${source_DIR}/skyline/services/timesrv/IStaticService.cpp ${source_DIR}/skyline/services/timesrv/ISystemClock.cpp + ${source_DIR}/skyline/services/timesrv/ISteadyClock.cpp ${source_DIR}/skyline/services/timesrv/ITimeZoneService.cpp ${source_DIR}/skyline/services/fssrv/IFileSystemProxy.cpp ${source_DIR}/skyline/services/fssrv/IFileSystem.cpp diff --git a/app/src/main/cpp/skyline/services/base_service.h b/app/src/main/cpp/skyline/services/base_service.h index c9037abe..69fa6a4e 100644 --- a/app/src/main/cpp/skyline/services/base_service.h +++ b/app/src/main/cpp/skyline/services/base_service.h @@ -55,6 +55,7 @@ namespace skyline::service { timesrv_IStaticService, timesrv_ISystemClock, timesrv_ITimeZoneService, + timesrv_ISteadyClock, fssrv_IFileSystemProxy, fssrv_IFileSystem, fssrv_IStorage, diff --git a/app/src/main/cpp/skyline/services/timesrv/IStaticService.cpp b/app/src/main/cpp/skyline/services/timesrv/IStaticService.cpp index 263f9d17..f7c5a37f 100644 --- a/app/src/main/cpp/skyline/services/timesrv/IStaticService.cpp +++ b/app/src/main/cpp/skyline/services/timesrv/IStaticService.cpp @@ -1,14 +1,16 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) -#include "IStaticService.h" +#include "ISteadyClock.h" #include "ISystemClock.h" #include "ITimeZoneService.h" +#include "IStaticService.h" namespace skyline::service::timesrv { IStaticService::IStaticService(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::timesrv_IStaticService, "timesrv:IStaticService", { {0x0, SFUNC(IStaticService::GetStandardUserSystemClock)}, {0x1, SFUNC(IStaticService::GetStandardNetworkSystemClock)}, + {0x2, SFUNC(IStaticService::GetStandardSteadyClock)}, {0x3, SFUNC(IStaticService::GetTimeZoneService)}, {0x4, SFUNC(IStaticService::GetStandardLocalSystemClock)} }) {} @@ -21,6 +23,10 @@ namespace skyline::service::timesrv { manager.RegisterService(std::make_shared(SystemClockType::Network, state, manager), session, response); } + void IStaticService::GetStandardSteadyClock(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + manager.RegisterService(std::make_shared(state, manager), session, response); + } + void IStaticService::GetTimeZoneService(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { manager.RegisterService(std::make_shared(state, manager), session, response); } diff --git a/app/src/main/cpp/skyline/services/timesrv/IStaticService.h b/app/src/main/cpp/skyline/services/timesrv/IStaticService.h index 99083524..31ba9577 100644 --- a/app/src/main/cpp/skyline/services/timesrv/IStaticService.h +++ b/app/src/main/cpp/skyline/services/timesrv/IStaticService.h @@ -24,6 +24,11 @@ namespace skyline::service::timesrv { */ void GetStandardNetworkSystemClock(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + /** + * @brief This returns a handle to a ISteadyClock for a steady timepoint + */ + void GetStandardSteadyClock(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + /** * @brief This returns a handle to a ITimeZoneService for reading time zone information */ diff --git a/app/src/main/cpp/skyline/services/timesrv/ISteadyClock.cpp b/app/src/main/cpp/skyline/services/timesrv/ISteadyClock.cpp new file mode 100644 index 00000000..a729d753 --- /dev/null +++ b/app/src/main/cpp/skyline/services/timesrv/ISteadyClock.cpp @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#include "ISteadyClock.h" + +namespace skyline::service::timesrv { + ISteadyClock::ISteadyClock(const DeviceState &state, ServiceManager &manager) : BaseService(state, manager, Service::timesrv_ISteadyClock, "timesrv:ISteadyClock", { + {0x0, SFUNC(ISteadyClock::GetCurrentTimePoint)} + }) {} + + void ISteadyClock::GetCurrentTimePoint(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + response.Push(SteadyClockTimePoint{static_cast(std::time(nullptr))}); + } +} diff --git a/app/src/main/cpp/skyline/services/timesrv/ISteadyClock.h b/app/src/main/cpp/skyline/services/timesrv/ISteadyClock.h new file mode 100644 index 00000000..32755dd2 --- /dev/null +++ b/app/src/main/cpp/skyline/services/timesrv/ISteadyClock.h @@ -0,0 +1,30 @@ +// SPDX-License-Identifier: MPL-2.0 +// Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) + +#pragma once + +#include +#include + +namespace skyline::service::timesrv { + /** + * @brief This holds a steady clock timepoint (https://switchbrew.org/wiki/PSC_services#SteadyClockTimePoint) + */ + struct SteadyClockTimePoint { + u64 timepoint; //!< The point in time of this timepoint + u8 id[0x10]; //!< The ID of the source clock + }; + + /** + * @brief ISteadyClock is used to retrieve a steady time that increments uniformly for the lifetime on an application (https://switchbrew.org/wiki/PSC_services#ISteadyClock) + */ + class ISteadyClock : public BaseService { + public: + ISteadyClock(const DeviceState &state, ServiceManager &manager); + + /** + * @brief This returns the current value of the steady clock + */ + void GetCurrentTimePoint(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + }; +} diff --git a/app/src/main/cpp/skyline/services/timesrv/ISystemClock.cpp b/app/src/main/cpp/skyline/services/timesrv/ISystemClock.cpp index df8fca8d..5cb30fdb 100644 --- a/app/src/main/cpp/skyline/services/timesrv/ISystemClock.cpp +++ b/app/src/main/cpp/skyline/services/timesrv/ISystemClock.cpp @@ -1,14 +1,21 @@ // SPDX-License-Identifier: MPL-2.0 // Copyright © 2020 Skyline Team and Contributors (https://github.com/skyline-emu/) +#include "ISteadyClock.h" #include "ISystemClock.h" namespace skyline::service::timesrv { ISystemClock::ISystemClock(const SystemClockType clockType, const DeviceState &state, ServiceManager &manager) : type(clockType), BaseService(state, manager, Service::timesrv_ISystemClock, "timesrv:ISystemClock", { - {0x0, SFUNC(ISystemClock::GetCurrentTime)} + {0x0, SFUNC(ISystemClock::GetCurrentTime)}, + {0x2, SFUNC(ISystemClock::GetSystemClockContext)} }) {} void ISystemClock::GetCurrentTime(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { response.Push(static_cast(std::time(nullptr))); } + + void ISystemClock::GetSystemClockContext(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response) { + response.Push(static_cast(std::time(nullptr))); + response.Push(SteadyClockTimePoint{static_cast(std::time(nullptr))}); + } } diff --git a/app/src/main/cpp/skyline/services/timesrv/ISystemClock.h b/app/src/main/cpp/skyline/services/timesrv/ISystemClock.h index 52be0d01..0a161a49 100644 --- a/app/src/main/cpp/skyline/services/timesrv/ISystemClock.h +++ b/app/src/main/cpp/skyline/services/timesrv/ISystemClock.h @@ -29,5 +29,10 @@ namespace skyline::service::timesrv { * @brief This returns the amount of seconds since epoch */ void GetCurrentTime(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); + + /** + * @brief This returns the system clock context + */ + void GetSystemClockContext(type::KSession &session, ipc::IpcRequest &request, ipc::IpcResponse &response); }; }