blob: 983860ee428655974d04ea8fc9439beb8fabd159 [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_ZONE_CONTROLLER_H_
#define THERMALD_THERMAL_ZONE_CONTROLLER_H_
#include <memory>
#include <string>
#include <vector>
#include "base/macros.h"
#include "base/memory/weak_ptr.h"
#include "thermald/key_value_publisher.h"
#include "thermald/temperature_monitor_interface.h"
#include "thermald/thermal_state_engine.h"
#include "thermald/thermal_zone.h"
namespace thermald {
// Controls the temperature of a thermal zone. Subscribes to the temperature
// monitors of the zone and processes notifications about temperature
// updates. Uses a thermal state machine object to determine the current
// thermal state of the zone. When a new state is entered it sets the output
// values corresponding to this state.
class ThermalZoneController {
public:
// Does not take ownership of the thermal zone and the temperature monitors.
// The caller must ensure that these objects are valid during the lifetime
// of the thermal zone controller.
ThermalZoneController(
const ThermalZone *zone,
KeyValuePublisher *output_values,
std::vector<TemperatureMonitorInterface *> temperature_monitors);
~ThermalZoneController();
// Starts monitoring of the temperatures of the thermal zone.
// Subscribes to temperature monitors of the zone. Thermal outputs are
// published using the KeyValuePublisher passed in the constructor until
// Stop() is called. Returns true on success or false if the controller is
// already running.
bool Start();
// Stops monitoring of the temperatures of the thermal zone.
// Returns true on success or false if the controller is not running.
bool Stop();
private:
friend class ThermalZoneControllerTest;
// Processes a temperature update. If the thermal state of the zone has
// changed it sets the outputs corresponding to the new state.
void ProcessTemperatureUpdate(const std::string &sensor, int temperature);
const ThermalZone *zone_;
std::vector<TemperatureMonitorInterface *> temperature_monitors_;
#if BASE_VER < 860220
std::vector<std::unique_ptr<TemperatureMonitorInterface::Subscription>>
subscriptions_;
#else
std::vector<base::CallbackListSubscription> subscriptions_;
#endif
bool is_running_;
ThermalStateEngine thermal_state_engine_;
const ThermalState *cur_thermal_state_;
KeyValuePublisher *outputs_;
base::WeakPtrFactory<ThermalZoneController> weak_ptr_factory_;
DISALLOW_COPY_AND_ASSIGN(ThermalZoneController);
};
} // namespace thermald
#endif // THERMALD_THERMAL_ZONE_CONTROLLER_H_