Kevin Lin | c6615ae | 2020-11-11 19:36:59 +0800 | [diff] [blame] | 1 | // Copyright 2021 The Chromium OS Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "runtime_probe/system_property_impl.h" |
| 6 | |
| 7 | #include <string> |
| 8 | |
| 9 | #include <vboot/crossystem.h> |
| 10 | |
Kevin Lin | a6779a0 | 2021-03-12 19:28:43 +0800 | [diff] [blame] | 11 | namespace runtime_probe { |
| 12 | |
Kevin Lin | c6615ae | 2020-11-11 19:36:59 +0800 | [diff] [blame] | 13 | bool SystemPropertyImpl::GetInt(const std::string& key, int* value_out) { |
| 14 | int value = ::VbGetSystemPropertyInt(key.c_str()); |
| 15 | if (value == -1) |
| 16 | return false; |
| 17 | *value_out = value; |
| 18 | return true; |
| 19 | } |
| 20 | |
| 21 | bool SystemPropertyImpl::SetInt(const std::string& key, int value) { |
| 22 | return 0 == ::VbSetSystemPropertyInt(key.c_str(), value); |
| 23 | } |
| 24 | |
| 25 | bool SystemPropertyImpl::GetString(const std::string& key, |
| 26 | std::string* value_out) { |
| 27 | char buf[VB_MAX_STRING_PROPERTY]; |
| 28 | if (::VbGetSystemPropertyString(key.c_str(), buf, sizeof(buf)) == nullptr) |
| 29 | return false; |
| 30 | *value_out = std::string(buf); |
| 31 | return true; |
| 32 | } |
| 33 | |
| 34 | bool SystemPropertyImpl::SetString(const std::string& key, |
| 35 | const std::string& value) { |
| 36 | return 0 == ::VbSetSystemPropertyString(key.c_str(), value.c_str()); |
| 37 | } |
Kevin Lin | a6779a0 | 2021-03-12 19:28:43 +0800 | [diff] [blame] | 38 | |
| 39 | } // namespace runtime_probe |