diff options
Diffstat (limited to 'daemon/Hwmon.cpp')
-rw-r--r-- | daemon/Hwmon.cpp | 40 |
1 files changed, 26 insertions, 14 deletions
diff --git a/daemon/Hwmon.cpp b/daemon/Hwmon.cpp index 1d7c0da..778f307 100644 --- a/daemon/Hwmon.cpp +++ b/daemon/Hwmon.cpp | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * Copyright (C) ARM Limited 2013. All rights reserved. | 2 | * Copyright (C) ARM Limited 2013-2014. All rights reserved. |
3 | * | 3 | * |
4 | * This program is free software; you can redistribute it and/or modify | 4 | * This program is free software; you can redistribute it and/or modify |
5 | * it under the terms of the GNU General Public License version 2 as | 5 | * it under the terms of the GNU General Public License version 2 as |
@@ -17,7 +17,7 @@ | |||
17 | 17 | ||
18 | class HwmonCounter { | 18 | class HwmonCounter { |
19 | public: | 19 | public: |
20 | HwmonCounter(HwmonCounter *next, int key, const sensors_chip_name *chip, const sensors_feature *feature); | 20 | HwmonCounter(HwmonCounter *next, const sensors_chip_name *chip, const sensors_feature *feature); |
21 | ~HwmonCounter(); | 21 | ~HwmonCounter(); |
22 | 22 | ||
23 | HwmonCounter *getNext() const { return next; } | 23 | HwmonCounter *getNext() const { return next; } |
@@ -69,7 +69,7 @@ private: | |||
69 | HwmonCounter &operator=(const HwmonCounter &); | 69 | HwmonCounter &operator=(const HwmonCounter &); |
70 | }; | 70 | }; |
71 | 71 | ||
72 | HwmonCounter::HwmonCounter(HwmonCounter *next, int key, const sensors_chip_name *chip, const sensors_feature *feature) : next(next), key(key), polled(false), readable(false), enabled(false), duplicate(false), chip(chip), feature(feature) { | 72 | HwmonCounter::HwmonCounter(HwmonCounter *next, const sensors_chip_name *chip, const sensors_feature *feature) : next(next), key(getEventKey()), polled(false), readable(false), enabled(false), duplicate(false), chip(chip), feature(feature) { |
73 | 73 | ||
74 | int len = sensors_snprintf_chip_name(NULL, 0, chip) + 1; | 74 | int len = sensors_snprintf_chip_name(NULL, 0, chip) + 1; |
75 | char *chip_name = new char[len]; | 75 | char *chip_name = new char[len]; |
@@ -205,6 +205,23 @@ bool HwmonCounter::canRead() { | |||
205 | } | 205 | } |
206 | 206 | ||
207 | Hwmon::Hwmon() : counters(NULL) { | 207 | Hwmon::Hwmon() : counters(NULL) { |
208 | } | ||
209 | |||
210 | Hwmon::~Hwmon() { | ||
211 | while (counters != NULL) { | ||
212 | HwmonCounter * counter = counters; | ||
213 | counters = counter->getNext(); | ||
214 | delete counter; | ||
215 | } | ||
216 | sensors_cleanup(); | ||
217 | } | ||
218 | |||
219 | void Hwmon::setup() { | ||
220 | // hwmon does not currently work with perf | ||
221 | if (gSessionData->perf.isSetup()) { | ||
222 | return; | ||
223 | } | ||
224 | |||
208 | int err = sensors_init(NULL); | 225 | int err = sensors_init(NULL); |
209 | if (err) { | 226 | if (err) { |
210 | logg->logMessage("Failed to initialize libsensors! (%d)", err); | 227 | logg->logMessage("Failed to initialize libsensors! (%d)", err); |
@@ -218,20 +235,11 @@ Hwmon::Hwmon() : counters(NULL) { | |||
218 | int feature_nr = 0; | 235 | int feature_nr = 0; |
219 | const sensors_feature *feature; | 236 | const sensors_feature *feature; |
220 | while ((feature = sensors_get_features(chip, &feature_nr))) { | 237 | while ((feature = sensors_get_features(chip, &feature_nr))) { |
221 | counters = new HwmonCounter(counters, getEventKey(), chip, feature); | 238 | counters = new HwmonCounter(counters, chip, feature); |
222 | } | 239 | } |
223 | } | 240 | } |
224 | } | 241 | } |
225 | 242 | ||
226 | Hwmon::~Hwmon() { | ||
227 | while (counters != NULL) { | ||
228 | HwmonCounter * counter = counters; | ||
229 | counters = counter->getNext(); | ||
230 | delete counter; | ||
231 | } | ||
232 | sensors_cleanup(); | ||
233 | } | ||
234 | |||
235 | HwmonCounter *Hwmon::findCounter(const Counter &counter) const { | 243 | HwmonCounter *Hwmon::findCounter(const Counter &counter) const { |
236 | for (HwmonCounter * hwmonCounter = counters; hwmonCounter != NULL; hwmonCounter = hwmonCounter->getNext()) { | 244 | for (HwmonCounter * hwmonCounter = counters; hwmonCounter != NULL; hwmonCounter = hwmonCounter->getNext()) { |
237 | if (hwmonCounter->canRead() && strcmp(hwmonCounter->getName(), counter.getType()) == 0) { | 245 | if (hwmonCounter->canRead() && strcmp(hwmonCounter->getName(), counter.getType()) == 0) { |
@@ -271,14 +279,18 @@ void Hwmon::setupCounter(Counter &counter) { | |||
271 | counter.setKey(hwmonCounter->getKey()); | 279 | counter.setKey(hwmonCounter->getKey()); |
272 | } | 280 | } |
273 | 281 | ||
274 | void Hwmon::writeCounters(mxml_node_t *root) const { | 282 | int Hwmon::writeCounters(mxml_node_t *root) const { |
283 | int count = 0; | ||
275 | for (HwmonCounter * counter = counters; counter != NULL; counter = counter->getNext()) { | 284 | for (HwmonCounter * counter = counters; counter != NULL; counter = counter->getNext()) { |
276 | if (!counter->canRead()) { | 285 | if (!counter->canRead()) { |
277 | continue; | 286 | continue; |
278 | } | 287 | } |
279 | mxml_node_t *node = mxmlNewElement(root, "counter"); | 288 | mxml_node_t *node = mxmlNewElement(root, "counter"); |
280 | mxmlElementSetAttr(node, "name", counter->getName()); | 289 | mxmlElementSetAttr(node, "name", counter->getName()); |
290 | ++count; | ||
281 | } | 291 | } |
292 | |||
293 | return count; | ||
282 | } | 294 | } |
283 | 295 | ||
284 | void Hwmon::writeEvents(mxml_node_t *root) const { | 296 | void Hwmon::writeEvents(mxml_node_t *root) const { |