| // Copyright 2015 The Chromium OS Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef THERMALD_THERMAL_OUTPUT_PROCESSOR_H_ |
| #define THERMALD_THERMAL_OUTPUT_PROCESSOR_H_ |
| |
| #include <map> |
| #include <memory> |
| #include <string> |
| #include <vector> |
| |
| #include "base/macros.h" |
| #include "base/memory/weak_ptr.h" |
| #include "base/timer/timer.h" |
| |
| #include "thermald/ath10k_interface.h" |
| #include "thermald/cpufreq_device.h" |
| #include "thermald/key_value_publisher.h" |
| |
| namespace thermald { |
| |
| // The thermal output processor is notified upon changes in thermal parameters |
| // and performs the corresponding actions like throttling of the wireless |
| // interfaces or the CPU cores. |
| class ThermalOutputProcessor { |
| public: |
| // Subscribes to the publisher of thermal output values. |
| // ThermalOutputProcessor does not take ownership of outputs, so it must |
| // out-live the output processor. |
| explicit ThermalOutputProcessor(KeyValuePublisher *outputs); |
| |
| private: |
| enum Status { |
| kSkipped, |
| kOk, |
| kInvalidKey, |
| kDeferred, |
| }; |
| |
| void OnOutputSet(const std::string &key, int value); |
| Status ProcessOutput(const std::string &key, int value); |
| // In some situations immediate processing of certain output values is not |
| // possible. These values are stored in deferred_values_ and processing is |
| // retried periodically. |
| void ProcessDeferredOutputs(); |
| |
| Status ProcessValueAth10k(const std::vector<std::string> &key_parts, |
| int value); |
| Status ProcessValueCpu(const std::vector<std::string> &key_parts, int value); |
| |
| std::map<std::string, std::unique_ptr<Ath10kInterface>> ath10k_interfaces_; |
| // Map with output values for deferred processing. |
| std::map<std::string, int> deferred_values_; |
| base::RepeatingTimer deferred_values_timer_; |
| std::vector<std::unique_ptr<CpufreqDevice>> cpufreq_devices_; |
| #if BASE_VER < 860220 |
| std::unique_ptr<KeyValuePublisher::Subscription> subscription_; |
| #else |
| base::CallbackListSubscription subscription_; |
| #endif |
| base::WeakPtrFactory<ThermalOutputProcessor> weak_ptr_factory_; |
| |
| DISALLOW_COPY_AND_ASSIGN(ThermalOutputProcessor); |
| }; |
| |
| } // namespace thermald |
| |
| #endif // THERMALD_THERMAL_OUTPUT_PROCESSOR_H_ |