~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to ksysguard/ksysguardd/Linux/i8k.c

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    KSysGuard, the KDE System Guard
 
3
 
 
4
    Copyright (c) 1999 - 2001 Chris Schlaeger <cs@kde.org>
 
5
 
 
6
    This program is free software; you can redistribute it and/or
 
7
    modify it under the terms of version 2 of the GNU General Public
 
8
    License as published by the Free Software Foundation.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program; if not, write to the Free Software
 
17
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 
 
19
*/
 
20
 
 
21
#include <fcntl.h>
 
22
#include <stdio.h>
 
23
#include <sys/stat.h>
 
24
#include <sys/types.h>
 
25
#include <unistd.h>
 
26
 
 
27
#include "Command.h"
 
28
#include "ksysguardd.h"
 
29
 
 
30
#include "i8k.h"
 
31
 
 
32
#ifdef HAVE_I8K_SUPPORT
 
33
 
 
34
static int I8kOK = 0;
 
35
static int cpuTemp, fan0Speed, fan1Speed;
 
36
 
 
37
#define I8KBUFSIZE 128
 
38
static char I8kBuf[ I8KBUFSIZE ];
 
39
 
 
40
/*
 
41
================================ public part =================================
 
42
*/
 
43
 
 
44
void initI8k( struct SensorModul* sm )
 
45
{
 
46
  if ( updateI8k() < 0 ) {
 
47
    I8kOK = -1;
 
48
    return;
 
49
  } else
 
50
    I8kOK = 1;
 
51
 
 
52
  registerMonitor( "dell/cputemp", "integer", printI8kCPUTemperature,
 
53
                   printI8kCPUTemperatureInfo, sm );
 
54
  registerMonitor( "dell/fan0", "integer", printI8kFan0Speed,
 
55
                   printI8kFan0SpeedInfo, sm );
 
56
  registerMonitor( "dell/fan1", "integer", printI8kFan1Speed,
 
57
                   printI8kFan1SpeedInfo, sm );
 
58
}
 
59
 
 
60
void exitI8k( void )
 
61
{
 
62
  I8kOK = -1;
 
63
}
 
64
 
 
65
int updateI8k( void )
 
66
{
 
67
  size_t n;
 
68
  int fd;
 
69
 
 
70
  if ( I8kOK < 0 )
 
71
    return -1;
 
72
 
 
73
  if ( ( fd = open( "/proc/i8k", O_RDONLY ) ) < 0 ) {
 
74
    print_error( "Cannot open file \'/proc/i8k\'!\n"
 
75
                 "The kernel needs to be compiled with support\n"
 
76
                 "for /proc file system enabled!\n" );
 
77
    return -1;
 
78
  }
 
79
 
 
80
  if ( ( n = read( fd, I8kBuf, I8KBUFSIZE - 1 ) ) == I8KBUFSIZE - 1 ) {
 
81
    log_error( "Internal buffer too small to read \'/proc/i8k\'" );
 
82
 
 
83
    close( fd );
 
84
    return -1;
 
85
  }
 
86
 
 
87
  close( fd );
 
88
  I8kBuf[ n ] = '\0';
 
89
 
 
90
  sscanf( I8kBuf, "%*f %*s %*s %d %*d %*d %d %d %*d %*d",
 
91
          &cpuTemp, &fan0Speed, &fan1Speed );
 
92
 
 
93
  return 0;
 
94
}
 
95
 
 
96
void printI8kCPUTemperature( const char* cmd )
 
97
{
 
98
  (void)cmd;
 
99
  output( "%d\n", cpuTemp );
 
100
}
 
101
 
 
102
void printI8kCPUTemperatureInfo( const char* cmd )
 
103
{
 
104
  (void)cmd;
 
105
  output( "CPU Temperature\t0\t0\tC\n" );
 
106
}
 
107
 
 
108
void printI8kFan0Speed( const char* cmd )
 
109
{
 
110
  (void)cmd;
 
111
  output( "%d\n", fan0Speed );
 
112
}
 
113
 
 
114
void printI8kFan0SpeedInfo( const char* cmd )
 
115
{
 
116
  (void)cmd;
 
117
  output( "Left fan\t0\t0\trpm\n" );
 
118
}
 
119
 
 
120
void printI8kFan1Speed( const char* cmd )
 
121
{
 
122
  (void)cmd;
 
123
  output( "%d\n", fan1Speed );
 
124
}
 
125
 
 
126
void printI8kFan1SpeedInfo( const char* cmd )
 
127
{
 
128
  (void)cmd;
 
129
  output( "Right fan\t0\t0\trpm\n" );
 
130
}
 
131
 
 
132
#else /* HAVE_I8K_SUPPORT */
 
133
 
 
134
/* dummy version for systems that have no i8k support */
 
135
 
 
136
void initI8k( struct SensorModul* sm )
 
137
{
 
138
  (void)sm;
 
139
}
 
140
 
 
141
void exitI8k( void )
 
142
{
 
143
}
 
144
 
 
145
int updateI8k( void )
 
146
{
 
147
  return 0;
 
148
}
 
149
 
 
150
#endif