// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include #include #include "Service/CpuSentinel.hpp" namespace sys { using SentinelPointer = std::weak_ptr; class GovernorSentinel { public: explicit GovernorSentinel(std::shared_ptr newSentinel); [[nodiscard]] auto GetSentinel() const noexcept -> SentinelPointer; [[nodiscard]] auto GetRequestedFrequency() const noexcept -> bsp::CpuFrequencyHz; void SetRequestedFrequency(bsp::CpuFrequencyHz newFrequency); private: SentinelPointer sentinelPtr; bsp::CpuFrequencyHz requestedFrequency; }; using GovernorSentinelPointer = std::unique_ptr; using GovernorSentinelsVector = std::vector; /// CpuGovernor manages all sentinels in the system and has CPU frequency requests from them (e.g. eInkSentinel). /// It is also responsible for informing all sentinels that the CPU frequency has changed. class CpuGovernor { public: void RegisterNewSentinel(std::shared_ptr newSentinel); [[nodiscard]] auto GetNumberOfRegisteredSentinels() const noexcept -> uint32_t; void PrintAllSentinels() const noexcept; void SetCpuFrequencyRequest(std::string sentinelName, bsp::CpuFrequencyHz request); void ResetCpuFrequencyRequest(std::string sentinelName); [[nodiscard]] auto GetMinimumFrequencyRequested() const noexcept -> bsp::CpuFrequencyHz; void InformSentinelsAboutCpuFrequencyChange(bsp::CpuFrequencyHz newFrequency) const noexcept; private: static void PrintName(const GovernorSentinelPointer &element); GovernorSentinelsVector sentinels; }; } // namespace sys