1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
/***************************************************************************
LMSensors.cpp - description
-------------------
begin : Mon Aug 6 2001
copyright : (C) 2001 by
email :
***************************************************************************/
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/stat.h>
#include <ntqstrlist.h>
#include <ntqobjectlist.h>
#include "lmsensors.h"
//****************************************************************************
// Public methods
//****************************************************************************
LMSensors::LMSensors(TQObject *parent, const char * name)
: TQObject(parent,name)
{
if(initSensors()) createLMSensors();
createI8KSensors();
createHDSensors();
}
LMSensors::~LMSensors()
{
if(count()) sensors_cleanup();
}
bool LMSensors::initSensors()
{
#if SENSORS_API_VERSION < 0x400 /* libsensor 3 code */
FILE *fp=fopen("/etc/sensors.conf","r");
if(!fp) {
tqWarning("KSensors error: /etc/sensors.conf not found !");
return false;
}
#else
FILE *fp=NULL;
#endif
int err= sensors_init(fp);
if(err) {
tqWarning("KSensors error: sensors_init fail, error code %d",err);
return false;
}
#if SENSORS_API_VERSION < 0x400 /* libsensor 3 code */
fclose(fp);
#endif
return true;
}
void LMSensors::createLMSensors()
{
const sensors_chip_name *chip_name;
int err= 0;
#if SENSORS_API_VERSION < 0x400 /* libsensor 3 code */
while( (chip_name= sensors_get_detected_chips(&err)) )
{
if( existSensor(chip_name,"temp") ||
existSensor(chip_name,"fan") )
{
(void)new LMSensorsChip(chip_name,this);
}
}
#else
while( (chip_name= sensors_get_detected_chips(NULL, &err)) )
(void)new LMSensorsChip(chip_name,this);
#endif
}
void LMSensors::createHDSensors()
{
HDSensorsList *disks= new HDSensorsList(this,"Disks");
if(disks->count()==0) delete disks;
}
void LMSensors::createI8KSensors()
{
if(I8KSensorsList::I8KAvailable())
(void) new I8KSensorsList(this,"I8KSensors");
}
#if SENSORS_API_VERSION < 0x400 /* libsensor 3 code */
int LMSensors::existSensor(const sensors_chip_name *chip_name,const char *sensor_name)
{
int nr1,nr2;
const sensors_feature_data *sensor_data;
nr1=nr2= 0;
while( (sensor_data= sensors_get_all_features(*chip_name, &nr1, &nr2)) )
{
if( strstr(sensor_data->name,sensor_name) )
return sensor_data->number;
}
return 0;
}
#endif
void LMSensors::setMonitorized(bool enable)
{
TQObjectList *list= getSensorsChips();
if(list)
for(LMSensorsChip *sensor=(LMSensorsChip*)list->first(); sensor!=0; sensor= (LMSensorsChip *)list->next())
sensor->setMonitorized(enable);
}
Sensor *LMSensors::getSensor(const char *name)
{
int index= count();
Sensor *sensor= 0;
while(--index>=0 && !sensor) {
sensor= getSensorsChip(index)->getSensor(name);
}
return sensor;
}
void LMSensors::childEvent( TQChildEvent *e )
{
if(e->inserted()) {
connect((SensorsList *)e->child(),SIGNAL(valueChanged(Sensor *)) ,this,SIGNAL(valueChanged(Sensor *)));
connect((SensorsList *)e->child(),SIGNAL(configChanged(const char *)),this,SIGNAL(configChanged(const char *)));
}
}
/*********************************************************************************/
|