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

Diff of /wxCpuThrottle/src/acpiparser.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 24 by torben, Thu Aug 9 20:57:19 2007 UTC revision 25 by torben, Fri Aug 10 18:12:36 2007 UTC
# Line 22  Line 22 
22  #include <iostream>  #include <iostream>
23  #include <fstream>  #include <fstream>
24  #include <sstream>  #include <sstream>
25    #include <stdexcept>
26    
27  AcpiParser::AcpiParser()  AcpiParser::AcpiParser()
28  {  {
# Line 38  void AcpiParser::ReadAcpiFile() Line 39  void AcpiParser::ReadAcpiFile()
39  {  {
40          char buffer[1024];          char buffer[1024];
41          std::ifstream in;          std::ifstream in;
42                  in.open("/proc/acpi/processor/CPU1/throttling");          
43            in.open("/proc/acpi/processor/CPU1/throttling");
44            if  (!in)
45                    throw std::runtime_error("Could not open file");
46                    
47          int linecounter = 0;          int linecounter = 0;
48            mStateDescriptions.clear();
49            
50          while (! in.eof() )          while (! in.eof() )
51          {          {
52                  in.getline(buffer,1024);                  in.getline(buffer,1024);
# Line 51  void AcpiParser::ReadAcpiFile() Line 56  void AcpiParser::ReadAcpiFile()
56                  unsigned int pos = line.rfind(' ');                  unsigned int pos = line.rfind(' ');
57                  if (pos == std::string::npos)                  if (pos == std::string::npos)
58                          continue;                          continue;
59                    pos++;
60                                    
61                  std::string value = line.substr(pos, line.size() - pos);                  std::string value = line.substr(pos, line.size() - pos);
62                    //std::cout << "Value: (" << linecounter << ") = " << value << std::endl;
63                                    
64                  switch (linecounter)                  switch (linecounter)
65                  {                  {
# Line 63  void AcpiParser::ReadAcpiFile() Line 70  void AcpiParser::ReadAcpiFile()
70                          {                          {
71                                  std::string tmp = value.substr(1, value.size() -1);                                  std::string tmp = value.substr(1, value.size() -1);
72                                  mCurrentState = atoi(tmp.c_str() );                                  mCurrentState = atoi(tmp.c_str() );
73                                    //std::cout << "tmp: >" << tmp << "< = " << std::endl;
74                                  break;                                  break;
75                          }                          }
76                          default:                          default:
# Line 71  void AcpiParser::ReadAcpiFile() Line 79  void AcpiParser::ReadAcpiFile()
79          }          }
80                    
81          in.close();          in.close();
82            //std::cout << "Current state:" << mCurrentState <<std::endl;
83            //std::cout << "Numstates:" << mNumstates << std::endl;
84  }  }
85    
86    
# Line 97  std::string AcpiParser::GetStateDescript Line 107  std::string AcpiParser::GetStateDescript
107    
108    
109    
110  bool AcpiParser::SetState(int newState)  void AcpiParser::SetState(int newState)
111  {  {
112          if (newState > mNumstates)          if (newState > mNumstates)
113                  return false;                  throw std::invalid_argument("newState too small");
114                    
     bool success = false;  
115          std::ofstream out;          std::ofstream out;
116          out.open("/proc/acpi/processor/CPU1/throttling");          out.open("/proc/acpi/processor/CPU1/throttling");
117                    
118          if ( out )          if (!out)
119          {                  throw std::runtime_error("Could not open file");
                 std::stringstream buf;  
                 buf << newState << "\n";  
                 out << buf.str();  
                 out.close();  
                 success = true;  
         }  
120                    
121          return success;  
122            std::stringstream buf;
123            buf << newState << "\n";
124            out << buf.str();
125            out.close();
126  }  }

Legend:
Removed from v.24  
changed lines
  Added in v.25

  ViewVC Help
Powered by ViewVC 1.1.20