mirror of
https://github.com/vmatare/thinkfan.git
synced 2024-09-11 19:47:17 +03:00
always init temp_state after sensors init
This commit is contained in:
parent
951d7d2f84
commit
ba61853510
@ -134,10 +134,6 @@ void StepwiseMapping::add_level(unique_ptr<Level> &&level)
|
||||
|
||||
|
||||
|
||||
Config::Config()
|
||||
: num_temps_(0)
|
||||
{}
|
||||
|
||||
|
||||
const Config *Config::read_config(const vector<string> &filenames)
|
||||
{
|
||||
@ -253,13 +249,17 @@ void Config::ensure_consistency() const
|
||||
|
||||
|
||||
void Config::add_sensor(unique_ptr<SensorDriver> &&sensor)
|
||||
{
|
||||
num_temps_ += sensor->num_temps();
|
||||
sensors_.push_back(std::move(sensor));
|
||||
}
|
||||
{ sensors_.push_back(std::move(sensor)); }
|
||||
|
||||
|
||||
unsigned int Config::num_temps() const
|
||||
{ return num_temps_; }
|
||||
{
|
||||
unsigned int count = 0;
|
||||
for (auto &sensor : sensors())
|
||||
count += sensor->num_temps();
|
||||
return count;
|
||||
}
|
||||
|
||||
|
||||
const vector<unique_ptr<SensorDriver>> &Config::sensors() const
|
||||
{ return sensors_; }
|
||||
@ -278,13 +278,19 @@ void Config::init_fans() const
|
||||
}
|
||||
|
||||
|
||||
void Config::init_sensors(TemperatureState &tstate) const
|
||||
TemperatureState Config::init_sensors() const
|
||||
{
|
||||
for (const unique_ptr<SensorDriver> &sensor : sensors())
|
||||
try_init_driver(*sensor);
|
||||
return TemperatureState(num_temps());
|
||||
}
|
||||
|
||||
|
||||
void Config::init_temperature_refs(TemperatureState &tstate) const
|
||||
{
|
||||
tstate.reset_refd_count();
|
||||
for (const unique_ptr<SensorDriver> &sensor : sensors()) {
|
||||
try_init_driver(*sensor);
|
||||
for (auto &sensor : sensors())
|
||||
sensor->init_temp_state_ref(tstate.ref(sensor->num_temps()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
12
src/config.h
12
src/config.h
@ -119,31 +119,27 @@ private:
|
||||
|
||||
class Config {
|
||||
public:
|
||||
Config();
|
||||
// Not trivially copyable since it holds raw pointers to levels, drivers and fans.
|
||||
Config(const Config &) = delete;
|
||||
Config() = default;
|
||||
~Config() = default;
|
||||
|
||||
static const Config *read_config(const vector<string> &filenames);
|
||||
void add_sensor(unique_ptr<SensorDriver> &&sensor);
|
||||
void add_fan_config(unique_ptr<FanConfig> &&fan_cfg);
|
||||
void ensure_consistency() const;
|
||||
void init_fans() const;
|
||||
void init_sensors(TemperatureState &) const;
|
||||
TemperatureState init_sensors() const;
|
||||
void init_temperature_refs(TemperatureState &tstate) const;
|
||||
|
||||
unsigned int num_temps() const;
|
||||
const vector<unique_ptr<SensorDriver>> &sensors() const;
|
||||
const vector<unique_ptr<FanConfig>> &fan_configs() const;
|
||||
|
||||
// No copy assignment operator either (not required).
|
||||
Config &operator = (const Config &) = delete;
|
||||
|
||||
string src_file;
|
||||
private:
|
||||
static const Config *try_read_config(const string &data);
|
||||
void try_init_driver(Driver &drv) const;
|
||||
vector<unique_ptr<SensorDriver>> sensors_;
|
||||
vector<unique_ptr<FanConfig>> temp_mappings_;
|
||||
unsigned int num_temps_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -20,6 +20,7 @@
|
||||
* ******************************************************************/
|
||||
|
||||
#include "temperature_state.h"
|
||||
#include "error.h"
|
||||
#include <cmath>
|
||||
|
||||
namespace thinkfan {
|
||||
@ -118,6 +119,9 @@ void TemperatureState::reset_refd_count()
|
||||
|
||||
TemperatureState::Ref TemperatureState::ref(unsigned int num_temps)
|
||||
{
|
||||
if (refd_temps_ + num_temps > temps_.size())
|
||||
throw Bug("Attempting to reference uninitialized temperature state");
|
||||
|
||||
auto ref = TemperatureState::Ref(*this, refd_temps_);
|
||||
refd_temps_ += num_temps;
|
||||
return ref;
|
||||
|
@ -367,9 +367,10 @@ int main(int argc, char **argv) {
|
||||
|
||||
Logger::instance().log_lvl() = TF_ERR;
|
||||
|
||||
temp_state = TemperatureState(test_cfg->num_temps());
|
||||
test_cfg->init_sensors(temp_state);
|
||||
temp_state = test_cfg->init_sensors();
|
||||
test_cfg->init_temperature_refs(temp_state);
|
||||
test_cfg->init_fans();
|
||||
|
||||
for (auto &sensor : test_cfg->sensors())
|
||||
sensor->read_temps();
|
||||
|
||||
@ -404,9 +405,9 @@ int main(int argc, char **argv) {
|
||||
|
||||
// Load the config for real after forking & enabling syslog
|
||||
unique_ptr<const Config> config(Config::read_config(config_files));
|
||||
temp_state = TemperatureState(config->num_temps());
|
||||
|
||||
config->init_sensors(temp_state);
|
||||
temp_state = config->init_sensors();
|
||||
config->init_temperature_refs(temp_state);
|
||||
|
||||
do {
|
||||
config->init_fans();
|
||||
|
Loading…
Reference in New Issue
Block a user