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

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

  ViewVC Help
Powered by ViewVC 1.1.20