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
5 #![cfg(feature = "with_gecko")]
6
7 use nsstring::nsACString;
8 use uuid::Uuid;
9
10 #[no_mangle]
fog_uuid_test_has_value(id: u32, ping_name: &nsACString) -> bool11 pub extern "C" fn fog_uuid_test_has_value(id: u32, ping_name: &nsACString) -> bool {
12 with_metric!(UUID_MAP, id, metric, test_has!(metric, ping_name))
13 }
14
15 #[no_mangle]
fog_uuid_test_get_value(id: u32, ping_name: &nsACString, value: &mut nsACString)16 pub extern "C" fn fog_uuid_test_get_value(id: u32, ping_name: &nsACString, value: &mut nsACString) {
17 let uuid = with_metric!(UUID_MAP, id, metric, test_get!(metric, ping_name)).to_string();
18 value.assign(&uuid);
19 }
20
21 #[no_mangle]
fog_uuid_set(id: u32, value: &nsACString)22 pub extern "C" fn fog_uuid_set(id: u32, value: &nsACString) {
23 if let Ok(uuid) = Uuid::parse_str(&value.to_utf8()) {
24 with_metric!(UUID_MAP, id, metric, metric.set(uuid));
25 }
26 }
27
28 #[no_mangle]
fog_uuid_generate_and_set(id: u32)29 pub extern "C" fn fog_uuid_generate_and_set(id: u32) {
30 with_metric!(UUID_MAP, id, metric, metric.generate_and_set());
31 }
32
33 #[no_mangle]
fog_uuid_test_get_error( id: u32, ping_name: &nsACString, error_str: &mut nsACString, ) -> bool34 pub extern "C" fn fog_uuid_test_get_error(
35 id: u32,
36 ping_name: &nsACString,
37 error_str: &mut nsACString,
38 ) -> bool {
39 let err = with_metric!(UUID_MAP, id, metric, test_get_errors!(metric, ping_name));
40 err.map(|err_str| error_str.assign(&err_str)).is_some()
41 }
42