glean_ffi/
boolean.rs

1// This Source Code Form is subject to the terms of the Mozilla Public
2// License, v. 2.0. If a copy of the MPL was not distributed with this
3// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
5use ffi_support::FfiStr;
6
7use crate::{define_metric, handlemap_ext::HandleMapExtension, with_glean_value, Lifetime};
8
9define_metric!(BooleanMetric => BOOLEAN_METRICS {
10    new           -> glean_new_boolean_metric(),
11    destroy       -> glean_destroy_boolean_metric,
12});
13
14#[no_mangle]
15pub extern "C" fn glean_boolean_set(metric_id: u64, value: u8) {
16    with_glean_value(|glean| {
17        BOOLEAN_METRICS.call_infallible(metric_id, |metric| {
18            metric.set(glean, value != 0);
19        })
20    })
21}
22
23#[no_mangle]
24pub extern "C" fn glean_boolean_test_has_value(metric_id: u64, storage_name: FfiStr) -> u8 {
25    with_glean_value(|glean| {
26        BOOLEAN_METRICS.call_infallible(metric_id, |metric| {
27            metric
28                .test_get_value(glean, storage_name.as_str())
29                .is_some()
30        })
31    })
32}
33
34#[no_mangle]
35pub extern "C" fn glean_boolean_test_get_value(metric_id: u64, storage_name: FfiStr) -> u8 {
36    with_glean_value(|glean| {
37        BOOLEAN_METRICS.call_infallible(metric_id, |metric| {
38            metric.test_get_value(glean, storage_name.as_str()).unwrap()
39        })
40    })
41}