summaryrefslogtreecommitdiff
path: root/profcollectd/libprofcollectd/bindings/libbase/lib.rs
diff options
context:
space:
mode:
authorAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-11-12 15:45:40 +0000
committerAndroid Build Coastguard Worker <android-build-coastguard-worker@google.com>2021-11-12 15:45:40 +0000
commitb10151f531375fc1f25199c16334c4446c24a23b (patch)
treedd72a84514306c5cc0c9025a1fb9e9e3976ced32 /profcollectd/libprofcollectd/bindings/libbase/lib.rs
parentf3076ee9f11bdfd75fec983c15b0c3fbe5ba6afe (diff)
parent3b739c8720db08d5b34e8a547a5b2f6305fe37b6 (diff)
downloadextras-b10151f531375fc1f25199c16334c4446c24a23b.tar.gz
Snap for 7910331 from 3b739c8720db08d5b34e8a547a5b2f6305fe37b6 to mainline-neuralnetworks-releaseandroid-mainline-12.0.0_r92android-mainline-12.0.0_r78android-mainline-12.0.0_r50android12-mainline-neuralnetworks-release
Change-Id: I37da9ab80b1cf86d4ebb8f3c2ca8e44e8efc2db8
Diffstat (limited to 'profcollectd/libprofcollectd/bindings/libbase/lib.rs')
-rw-r--r--profcollectd/libprofcollectd/bindings/libbase/lib.rs31
1 files changed, 13 insertions, 18 deletions
diff --git a/profcollectd/libprofcollectd/bindings/libbase/lib.rs b/profcollectd/libprofcollectd/bindings/libbase/lib.rs
index 6ac34d58..bdd99a02 100644
--- a/profcollectd/libprofcollectd/bindings/libbase/lib.rs
+++ b/profcollectd/libprofcollectd/bindings/libbase/lib.rs
@@ -14,26 +14,21 @@
// limitations under the License.
//
-//! This module implements safe wrappers for GetProperty method from libbase.
+//! This module implements safe wrappers for GetProperty and SetProperty from libbase.
-use std::ffi::{CStr, CString};
+pub use ffi::{GetProperty, SetProperty};
-/// Returns the current value of the system property `key`,
-/// or `default_value` if the property is empty or doesn't exist.
-pub fn get_property<'a>(key: &str, default_value: &'a str) -> &'a str {
- let key = CString::new(key).unwrap();
- let default_value = CString::new(default_value).unwrap();
- unsafe {
- let cstr = profcollect_libbase_bindgen::GetProperty(key.as_ptr(), default_value.as_ptr());
- CStr::from_ptr(cstr).to_str().unwrap()
- }
-}
+/// Safe wrappers for the GetProperty and SetProperty methods from libbase.
+#[cxx::bridge]
+mod ffi {
+ unsafe extern "C++" {
+ include!("properties.hpp");
+
+ /// Returns the current value of the system property `key`,
+ /// or `default_value` if the property is empty or doesn't exist.
+ fn GetProperty(key: &str, default_value: &str) -> String;
-/// Sets the system property `key` to `value`.
-pub fn set_property(key: &str, value: &str) {
- let key = CString::new(key).unwrap();
- let value = CString::new(value).unwrap();
- unsafe {
- profcollect_libbase_bindgen::SetProperty(key.as_ptr(), value.as_ptr());
+ /// Sets the system property `key` to `value`.
+ fn SetProperty(key: &str, value: &str);
}
}