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

Annotation of /wxCpuThrottle/src/acpiparser.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 25 - (hide annotations) (download)
Fri Aug 10 18:12:36 2007 UTC (16 years, 9 months ago) by torben
File size: 3298 byte(s)
A lot of gui modifications, but now the application works as I want it to.

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 24
27     AcpiParser::AcpiParser()
28     {
29     mNumstates = 0;
30     mCurrentState = 0;
31     }
32    
33    
34     AcpiParser::~AcpiParser()
35     {
36     }
37    
38     void AcpiParser::ReadAcpiFile()
39     {
40     char buffer[1024];
41     std::ifstream in;
42    
43 torben 25 in.open("/proc/acpi/processor/CPU1/throttling");
44     if (!in)
45     throw std::runtime_error("Could not open file");
46    
47 torben 24 int linecounter = 0;
48 torben 25 mStateDescriptions.clear();
49    
50 torben 24 while (! in.eof() )
51     {
52     in.getline(buffer,1024);
53     std::string line(buffer);
54     linecounter++;
55    
56     unsigned int pos = line.rfind(' ');
57     if (pos == std::string::npos)
58     continue;
59 torben 25 pos++;
60 torben 24
61     std::string value = line.substr(pos, line.size() - pos);
62 torben 25 //std::cout << "Value: (" << linecounter << ") = " << value << std::endl;
63 torben 24
64     switch (linecounter)
65     {
66     case 1:
67     mNumstates = atoi(value.c_str());
68     break;
69     case 2:
70     {
71     std::string tmp = value.substr(1, value.size() -1);
72     mCurrentState = atoi(tmp.c_str() );
73 torben 25 //std::cout << "tmp: >" << tmp << "< = " << std::endl;
74 torben 24 break;
75     }
76     default:
77     mStateDescriptions.push_back( value );
78     }
79     }
80    
81     in.close();
82 torben 25 //std::cout << "Current state:" << mCurrentState <<std::endl;
83     //std::cout << "Numstates:" << mNumstates << std::endl;
84 torben 24 }
85    
86    
87     int AcpiParser::GetCurrentState()
88     {
89     return mCurrentState;
90     }
91    
92    
93    
94     int AcpiParser::GetStateCount()
95     {
96     return mNumstates;
97     }
98    
99    
100     std::string AcpiParser::GetStateDescription(unsigned int stateNumber)
101     {
102     if (stateNumber >= mStateDescriptions.size() )
103     return "";
104    
105     return mStateDescriptions[stateNumber];
106     }
107    
108    
109    
110 torben 25 void AcpiParser::SetState(int newState)
111 torben 24 {
112     if (newState > mNumstates)
113 torben 25 throw std::invalid_argument("newState too small");
114 torben 24
115     std::ofstream out;
116     out.open("/proc/acpi/processor/CPU1/throttling");
117    
118 torben 25 if (!out)
119     throw std::runtime_error("Could not open file");
120 torben 24
121 torben 25
122     std::stringstream buf;
123     buf << newState << "\n";
124     out << buf.str();
125     out.close();
126 torben 24 }

Properties

Name Value
svn:eol-style native

  ViewVC Help
Powered by ViewVC 1.1.20