diff options
author | Joel Galenson <jgalenson@google.com> | 2021-07-22 10:22:28 -0700 |
---|---|---|
committer | Joel Galenson <jgalenson@google.com> | 2021-07-28 12:14:38 -0700 |
commit | d09092fd6d2632e6e2787af06ad6fdb69099966c (patch) | |
tree | 49f39188b9d81d77bcdac57899a583c46e090511 /profcollectd/libprofcollectd/bindings/libflags/lib.rs | |
parent | 1d2f2761cd1770bc040596e706335b74572e76de (diff) | |
download | extras-d09092fd6d2632e6e2787af06ad6fdb69099966c.tar.gz |
Migrate profcollectd's libflags bindings from bindgen to cxx.
This should both simplify the code and fix some errors in the existing
implementation.
Bug: 182498247
Test: Build
Change-Id: I2a5bcbcac407ba0bb41d4884b99fe8a55113ae38
(cherry picked from commit c8fb4177717b50c3c5789011e4ab795771a62102)
Diffstat (limited to 'profcollectd/libprofcollectd/bindings/libflags/lib.rs')
-rw-r--r-- | profcollectd/libprofcollectd/bindings/libflags/lib.rs | 37 |
1 files changed, 16 insertions, 21 deletions
diff --git a/profcollectd/libprofcollectd/bindings/libflags/lib.rs b/profcollectd/libprofcollectd/bindings/libflags/lib.rs index c8875cb1..c6435bbd 100644 --- a/profcollectd/libprofcollectd/bindings/libflags/lib.rs +++ b/profcollectd/libprofcollectd/bindings/libflags/lib.rs @@ -17,27 +17,22 @@ //! This module implements safe wrappers for GetServerConfigurableFlag method //! from libflags. -use std::ffi::{CStr, CString}; +pub use ffi::GetServerConfigurableFlag; -/// Use the category name and flag name registered in SettingsToPropertiesMapper.java -/// to query the experiment flag value. This method will return default_value if -/// querying fails. -/// Note that for flags from Settings.Global, experiment_category_name should -/// always be global_settings. -pub fn get_server_configurable_flag<'a>( - experiment_category_name: &str, - experiment_flag_name: &str, - default_value: &'a str, -) -> &'a str { - let experiment_category_name = CString::new(experiment_category_name).unwrap(); - let experiment_flag_name = CString::new(experiment_flag_name).unwrap(); - let default_value = CString::new(default_value).unwrap(); - unsafe { - let cstr = profcollect_libflags_bindgen::GetServerConfigurableFlag( - experiment_category_name.as_ptr(), - experiment_flag_name.as_ptr(), - default_value.as_ptr(), - ); - CStr::from_ptr(cstr).to_str().unwrap() +#[cxx::bridge] +mod ffi { + unsafe extern "C++" { + include!("get_flags.hpp"); + + /// Use the category name and flag name registered in SettingsToPropertiesMapper.java + /// to query the experiment flag value. This method will return default_value if + /// querying fails. + /// Note that for flags from Settings.Global, experiment_category_name should + /// always be global_settings. + fn GetServerConfigurableFlag( + experiment_category_name: &str, + experiment_flag_name: &str, + default_value: &str, + ) -> String; } } |