blob: 5894ded35e66fe02bc9763c9d0ffdd139a5b1627 [file] [log] [blame]
// 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_STATE_ENGINE_H_
#define THERMALD_THERMAL_STATE_ENGINE_H_
#include <map>
#include <string>
#include "base/macros.h"
#include "thermald/thermal_zone.h"
namespace thermald {
// Status of a thermal point.
struct ThermalPointStatus {
// Current temperature at the thermal point.
int temperature;
// Flag indicating if the threshold has been cleared (= bottom threshold
// reached).
bool threshold_cleared;
};
// Determines the thermal state of the zone based on the current thermal state,
// the temperature of the thermal points of the zone and their thresholds.
class ThermalStateEngine {
public:
// Does not take ownership of the thermal zone. The caller must ensure that
// the thermal zone is valid during the lifetime of the thermal state engine
// object
explicit ThermalStateEngine(const ThermalZone *zone);
// Process a temperature update on a thermal point of the zone.
bool ProcessTemperatureUpdate(const std::string &thermal_point,
int temperature);
// The state object is guaranteed to be valid during the lifetime of the
// thermal state engine.
const ThermalState &current_state() { return *current_state_; }
private:
// Update the status of a thermal point after a temperature update.
//
// Mainly checks if the activation or bottom threshold have been reached
// and updates the threshold_cleared flag accordingly.
bool UpdateThermalPointStatus(const std::string &thermal_point,
int temperature);
// Determine the thermal state of the zone.
const ThermalState *DetermineThermalState();
// Get the structure holding the status of a thermal point.
//
// If the structure doesn't exist yet it is created.
ThermalPointStatus *GetThermalPointStatus(const std::string &thermal_point);
// Helper function to initialize a newly entered thermal state.
void InitNewThermalState();
// Get the thresholds of a thermal point for a certain thermal state.
bool GetThermalPointThresholds(const ThermalState &state,
const std::string &thermal_point,
ThermalPointThresholds *thresholds) const;
const ThermalZone *zone_;
// Map with the status of all thermal points of this zone
// (point name => status).
std::map<std::string, ThermalPointStatus> thermal_point_status_map_;
// Current thermal state of the zone.
const ThermalState *current_state_;
DISALLOW_COPY_AND_ASSIGN(ThermalStateEngine);
};
} // namespace thermald
#endif // THERMALD_THERMAL_STATE_ENGINE_H_