/[projects]/wxCpuThrottle/src/acpiparser.cpp
ViewVC logotype

Annotation of /wxCpuThrottle/src/acpiparser.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 326 - (hide annotations) (download)
Wed Sep 16 18:47:18 2009 UTC (14 years, 8 months ago) by torben
File size: 3340 byte(s)
Use CPU0 instead of CPU1

1 torben 24 /***************************************************************************
2     * Copyright (C) 2007 by Torben Nielsen *
3     * torben@t-hoerup.dk *
4     * *
5     * This program is free software; you can redistribute it and/or modify *
6     * it under the terms of the GNU General Public License as published by *
7     * the Free Software Foundation; either version 2 of the License, or *
8     * (at your option) any later version. *
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 *
17     * Free Software Foundation, Inc., *
18     * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19     ***************************************************************************/
20     #include "acpiparser.h"
21    
22     #include <iostream>
23     #include <fstream>
24     #include <sstream>
25 torben 25 #include <stdexcept>
26 torben 221 #include <stdlib.h>
27 torben 24
28     AcpiParser::AcpiParser()
29     {
30     mNumstates = 0;
31     mCurrentState = 0;
32     }
33    
34    
35     AcpiParser::~AcpiParser()
36     {
37     }
38    
39     void AcpiParser::ReadAcpiFile()
40     {
41     char buffer[1024];
42     std::ifstream in;
43    
44 torben 326 in.open("/proc/acpi/processor/CPU0/throttling");
45 torben 25 if (!in)
46     throw std::runtime_error("Could not open file");
47    
48 torben 24 int linecounter = 0;
49 torben 25 mStateDescriptions.clear();
50    
51 torben 24 while (! in.eof() )
52     {
53     in.getline(buffer,1024);
54     std::string line(buffer);
55     linecounter++;
56    
57     unsigned int pos = line.rfind(' ');
58     if (pos == std::string::npos)
59     continue;
60 torben 25 pos++;
61 torben 24
62     std::string value = line.substr(pos, line.size() - pos);
63 torben 25 //std::cout << "Value: (" << linecounter << ") = " << value << std::endl;
64 torben 24
65     switch (linecounter)
66     {
67     case 1:
68     mNumstates = atoi(value.c_str());
69     break;
70     case 2:
71     {
72     std::string tmp = value.substr(1, value.size() -1);
73     mCurrentState = atoi(tmp.c_str() );
74 torben 25 //std::cout << "tmp: >" << tmp << "< = " << std::endl;
75 torben 24 break;
76     }
77 torben 221 case 3:
78     break;
79 torben 24 default:
80     mStateDescriptions.push_back( value );
81     }
82     }
83    
84     in.close();
85 torben 25 //std::cout << "Current state:" << mCurrentState <<std::endl;
86     //std::cout << "Numstates:" << mNumstates << std::endl;
87 torben 24 }
88    
89    
90     int AcpiParser::GetCurrentState()
91     {
92     return mCurrentState;
93     }
94    
95    
96    
97     int AcpiParser::GetStateCount()
98     {
99     return mNumstates;
100     }
101    
102    
103     std::string AcpiParser::GetStateDescription(unsigned int stateNumber)
104     {
105     if (stateNumber >= mStateDescriptions.size() )
106     return "";
107    
108     return mStateDescriptions[stateNumber];
109     }
110    
111    
112    
113 torben 25 void AcpiParser::SetState(int newState)
114 torben 24 {
115     if (newState > mNumstates)
116 torben 25 throw std::invalid_argument("newState too small");
117 torben 24
118     std::ofstream out;
119 torben 326 out.open("/proc/acpi/processor/CPU0/throttling");
120 torben 24
121 torben 25 if (!out)
122     throw std::runtime_error("Could not open file");
123 torben 24
124 torben 25
125     std::stringstream buf;
126     buf << newState << "\n";
127     out << buf.str();
128     out.close();
129 torben 24 }

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20