diff options
author | Daniel Leung <daniel.leung@intel.com> | 2016-01-20 01:52:20 +0000 |
---|---|---|
committer | Lisa Nguyen <lisa.nguyen@linaro.org> | 2016-08-08 11:14:40 -0700 |
commit | c73e386654a823e228abcd4647416839e60fed67 (patch) | |
tree | b0989732a731a35294a571ccdcedb0ac0df65af8 | |
parent | e277219caf0dd46e9220964a0b37c984e975818d (diff) | |
download | powertop-2.0-c73e386654a823e228abcd4647416839e60fed67.tar.gz |
Android: disable C++ exceptions
Android native C++ libraries do not support C++
exceptions.
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
-rw-r--r-- | src/devices/ahci.cpp | 9 | ||||
-rw-r--r-- | src/devices/alsa.cpp | 9 | ||||
-rw-r--r-- | src/lib.cpp | 16 |
3 files changed, 32 insertions, 2 deletions
diff --git a/src/devices/ahci.cpp b/src/devices/ahci.cpp index b8adf72..e5b6750 100644 --- a/src/devices/ahci.cpp +++ b/src/devices/ahci.cpp @@ -162,7 +162,9 @@ void ahci::start_measurement(void) ifstream file; snprintf(filename, sizeof(filename), "%s/ahci_alpm_active", sysfs_path); +#ifndef DISABLE_TRYCATCH try { +#endif file.open(filename, ios::in); if (file) { file >> start_active; @@ -187,11 +189,12 @@ void ahci::start_measurement(void) file >> start_devslp; } file.close(); +#ifndef DISABLE_TRYCATCH } catch (std::ios_base::failure &c) { fprintf(stderr, "%s\n", c.what()); } - +#endif } void ahci::end_measurement(void) @@ -202,7 +205,9 @@ void ahci::end_measurement(void) double p; double total; +#ifndef DISABLE_TRYCATCH try { +#endif snprintf(filename, sizeof(filename), "%s/ahci_alpm_active", sysfs_path); file.open(filename, ios::in); if (file) { @@ -227,10 +232,12 @@ void ahci::end_measurement(void) file >> end_devslp; } file.close(); +#ifndef DISABLE_TRYCATCH } catch (std::ios_base::failure &c) { fprintf(stderr, "%s\n", c.what()); } +#endif if (end_active < start_active) end_active = start_active; if (end_partial < start_partial) diff --git a/src/devices/alsa.cpp b/src/devices/alsa.cpp index f7ba2b6..3488e86 100644 --- a/src/devices/alsa.cpp +++ b/src/devices/alsa.cpp @@ -87,7 +87,9 @@ void alsa::start_measurement(void) ifstream file; snprintf(filename, sizeof(filename), "%s/power_off_acct", sysfs_path); +#ifndef DISABLE_TRYCATCH try { +#endif file.open(filename, ios::in); if (file) { file >> start_inactive; @@ -100,10 +102,12 @@ void alsa::start_measurement(void) file >> start_active; } file.close(); +#ifndef DISABLE_TRYCATCH } catch (std::ios_base::failure &c) { fprintf(stderr, "%s\n", c.what()); } +#endif } void alsa::end_measurement(void) @@ -113,7 +117,9 @@ void alsa::end_measurement(void) double p; snprintf(filename, sizeof(filename), "%s/power_off_acct", sysfs_path); +#ifndef DISABLE_TRYCATCH try { +#endif file.open(filename, ios::in); if (file) { file >> end_inactive; @@ -126,11 +132,12 @@ void alsa::end_measurement(void) file >> end_active; } file.close(); +#ifndef DISABLE_TRYCATCH } catch (std::ios_base::failure &c) { fprintf(stderr, "%s\n", c.what()); } - +#endif p = (end_active - start_active) / (0.001 + end_active + end_inactive - start_active - start_inactive) * 100.0; report_utilization(name, p); } diff --git a/src/lib.cpp b/src/lib.cpp index 5e48f37..9521415 100644 --- a/src/lib.cpp +++ b/src/lib.cpp @@ -176,13 +176,17 @@ void write_sysfs(const string &filename, const string &value) file.open(filename.c_str(), ios::out); if (!file) return; +#ifndef DISABLE_TRYCATCH try { +#endif file << value; file.close(); +#ifndef DISABLE_TRYCATCH } catch (std::exception &exc) { return; } +#endif } int read_sysfs(const string &filename, bool *ok) @@ -196,16 +200,20 @@ int read_sysfs(const string &filename, bool *ok) *ok = false; return 0; } +#ifndef DISABLE_TRYCATCH try { +#endif file >> i; if (ok) *ok = true; +#ifndef DISABLE_TRYCATCH } catch (std::exception &exc) { if (ok) *ok = false; i = 0; } +#endif file.close(); return i; } @@ -219,17 +227,21 @@ string read_sysfs_string(const string &filename) file.open(filename.c_str(), ios::in); if (!file) return ""; +#ifndef DISABLE_TRYCATCH try { +#endif file.getline(content, 4096); file.close(); c = strchr(content, '\n'); if (c) *c = 0; +#ifndef DISABLE_TRYCATCH } catch (std::exception &exc) { file.close(); return ""; } +#endif return content; } @@ -246,17 +258,21 @@ string read_sysfs_string(const char *format, const char *param) file.open(filename, ios::in); if (!file) return ""; +#ifndef DISABLE_TRYCATCH try { +#endif file.getline(content, 4096); file.close(); c = strchr(content, '\n'); if (c) *c = 0; +#ifndef DISABLE_TRYCATCH } catch (std::exception &exc) { file.close(); return ""; } +#endif return content; } |