--- wxCpuThrottle/src/acpiparser.cpp 2007/08/09 20:57:19 24 +++ wxCpuThrottle/src/acpiparser.cpp 2007/08/10 18:12:36 25 @@ -22,6 +22,7 @@ #include #include #include +#include AcpiParser::AcpiParser() { @@ -38,10 +39,14 @@ { char buffer[1024]; std::ifstream in; - in.open("/proc/acpi/processor/CPU1/throttling"); + + in.open("/proc/acpi/processor/CPU1/throttling"); + if (!in) + throw std::runtime_error("Could not open file"); int linecounter = 0; - + mStateDescriptions.clear(); + while (! in.eof() ) { in.getline(buffer,1024); @@ -51,8 +56,10 @@ unsigned int pos = line.rfind(' '); if (pos == std::string::npos) continue; + pos++; std::string value = line.substr(pos, line.size() - pos); + //std::cout << "Value: (" << linecounter << ") = " << value << std::endl; switch (linecounter) { @@ -63,6 +70,7 @@ { std::string tmp = value.substr(1, value.size() -1); mCurrentState = atoi(tmp.c_str() ); + //std::cout << "tmp: >" << tmp << "< = " << std::endl; break; } default: @@ -71,6 +79,8 @@ } in.close(); + //std::cout << "Current state:" << mCurrentState < mNumstates) - return false; + throw std::invalid_argument("newState too small"); - bool success = false; std::ofstream out; out.open("/proc/acpi/processor/CPU1/throttling"); - if ( out ) - { - std::stringstream buf; - buf << newState << "\n"; - out << buf.str(); - out.close(); - success = true; - } + if (!out) + throw std::runtime_error("Could not open file"); - return success; + + std::stringstream buf; + buf << newState << "\n"; + out << buf.str(); + out.close(); }