summaryrefslogtreecommitdiffstats
path: root/toolkit/components/glean/build_scripts/glean_parser_ext/templates/rust_pings.jinja2
blob: c041f663a698b815e58d01e1ed5a2ddb861ced37 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// -*- mode: Rust -*-

// AUTOGENERATED BY glean_parser.  DO NOT EDIT.
{# The rendered source is autogenerated, but this
Jinja2 template is not. Please file bugs! #}

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

use crate::private::Ping;
use once_cell::sync::Lazy;

{% for obj in all_objs['pings'].values() %}
#[allow(non_upper_case_globals)]
/// {{ obj.description|wordwrap() | replace('\n', '\n/// ') }}
pub static {{ obj.name|snake_case }}: Lazy<Ping> = Lazy::new(|| {
    Ping::new(
        "{{ obj.name }}",
        {{ obj.include_client_id|rust }},
        {{ obj.send_if_empty|rust }},
        {{ obj.precise_timestamps|rust }},
        {{ obj.reason_codes|rust }},
    )
});

{% endfor %}

/// Instantiate custom pings once to trigger registration.
///
/// # Arguments
///
/// application_id: If present, limit to only registering custom pings
///                 assigned to the identified application.
#[doc(hidden)]
pub fn register_pings(application_id: Option<&str>) {
    match application_id {
        {% for id, ping_names in ping_names_by_app_id.items() %}
        Some("{{id}}") => {
            log::info!("Registering pings {{ ping_names|join(', ') }} for {{id}}");
            {% for ping_name in ping_names %}
            let _ = &*{{ ping_name|snake_case }};
            {% endfor %}
        },
        {% endfor %}
        _ => {
            {% for obj in all_objs['pings'].values() %}
            let _ = &*{{ obj.name|snake_case }};
            {% endfor %}
        }
    }
}

#[cfg(feature = "with_gecko")]
pub(crate) fn submit_ping_by_id(id: u32, reason: Option<&str>) {
    if id & (1 << crate::factory::DYNAMIC_PING_BIT) > 0 {
        let map = crate::factory::__jog_metric_maps::PING_MAP
            .read()
            .expect("Read lock for dynamic ping map was poisoned!");
        if let Some(ping) = map.get(&id) {
            ping.submit(reason);
        } else {
            // TODO: instrument this error.
            log::error!("Cannot submit unknown dynamic ping {} by id.", id);
        }
        return;
    }
    match id {
{% for obj in all_objs['pings'].values() %}
        {{ obj.name|ping_id }} => {{ obj.name | snake_case }}.submit(reason),
{% endfor %}
        _ => {
            // TODO: instrument this error.
            log::error!("Cannot submit unknown ping {} by id.", id);
        }
    }
}