Expose test API for counters over Ffi

This commit is contained in:
Jan-Erik Rediger 2019-05-09 16:47:49 +02:00
Родитель 701549c96b
Коммит 08d528c006
3 изменённых файлов: 48 добавлений и 4 удалений

Просмотреть файл

@ -36,14 +36,16 @@ internal interface LibGleanFFI : Library {
fun glean_counter_add(glean_handle: Long, metric_id: Long, amount: Long, error: RustError.ByReference)
fun glean_counter_test_get_value(glean_handle: Long, metric_id: Long, storage_name: String): Long
fun glean_counter_test_has_value(glean_handle: Long, metric_id: Long, storage_name: String): Byte
fun glean_initialize(data_dir: String, application_id: String): Long
fun glean_is_initialized(glean_handle: Long): Byte
fun glean_is_upload_enabled(glean_handle: Long): Byte
fun glean_send_ping(glean_handle: Long, ping_name: String)
fun glean_new_boolean_metric(category: String, name: String, send_in_pings: StringArray, send_in_pings_len: Int, lifetime: Int, err: RustError.ByReference): Long
fun glean_new_counter_metric(category: String, name: String, send_in_pings: StringArray, send_in_pings_len: Int, lifetime: Int, err: RustError.ByReference): Long
@ -52,6 +54,8 @@ internal interface LibGleanFFI : Library {
fun glean_ping_collect(glean_handle: Long, ping_name: String, error: RustError.ByReference): Pointer?
fun glean_send_ping(glean_handle: Long, ping_name: String)
fun glean_set_upload_enabled(glean_handle: Long, flag: Byte)
fun glean_string_set(glean_handle: Long, metric_id: Long, value: String, error: RustError.ByReference)

Просмотреть файл

@ -168,14 +168,20 @@ void glean_counter_add(uint64_t glean_handle,
uint64_t amount,
ExternError *error);
uint64_t glean_counter_test_get_value(uint64_t glean_handle,
uint64_t metric_id,
FfiStr storage_name);
uint8_t glean_counter_test_has_value(uint64_t glean_handle,
uint64_t metric_id,
FfiStr storage_name);
uint64_t glean_initialize(FfiStr data_dir, FfiStr application_id);
uint8_t glean_is_initialized(uint64_t glean_handle);
uint8_t glean_is_upload_enabled(uint64_t glean_handle);
void glean_send_ping(uint64_t glean_handle, FfiStr ping_name);
uint64_t glean_new_boolean_metric(FfiStr category,
FfiStr name,
RawStringArray send_in_pings,
@ -199,6 +205,8 @@ uint64_t glean_new_string_metric(FfiStr category,
char *glean_ping_collect(uint64_t glean_handle, FfiStr ping_name, ExternError *error);
void glean_send_ping(uint64_t glean_handle, FfiStr ping_name);
void glean_set_upload_enabled(uint64_t glean_handle, uint8_t flag);
void glean_string_set(uint64_t glean_handle, uint64_t metric_id, FfiStr value, ExternError *error);

Просмотреть файл

@ -191,6 +191,38 @@ pub extern "C" fn glean_counter_add(
})
}
#[no_mangle]
pub extern "C" fn glean_counter_test_has_value(
glean_handle: u64,
metric_id: u64,
storage_name: FfiStr,
) -> u8 {
let mut err = ExternError::success();
GLEAN.call_with_output(&mut err, glean_handle, |glean| {
let mut err = ExternError::success();
COUNTER_METRICS.call_with_output(&mut err, metric_id, |metric| {
metric
.test_get_value(glean, storage_name.as_str())
.is_none()
})
})
}
#[no_mangle]
pub extern "C" fn glean_counter_test_get_value(
glean_handle: u64,
metric_id: u64,
storage_name: FfiStr,
) -> u64 {
let mut err = ExternError::success();
GLEAN.call_with_output(&mut err, glean_handle, |glean| {
let mut err = ExternError::success();
COUNTER_METRICS.call_with_output(&mut err, metric_id, |metric| {
metric.test_get_value(glean, storage_name.as_str()).unwrap()
})
})
}
#[no_mangle]
pub extern "C" fn glean_boolean_set(
glean_handle: u64,