File: rust_pings.jinja2

package info (click to toggle)
firefox-esr 115.14.0esr-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,659,200 kB
  • sloc: cpp: 6,676,648; javascript: 5,690,850; ansic: 3,328,545; python: 1,120,605; asm: 397,163; xml: 180,531; java: 178,838; sh: 68,930; makefile: 20,999; perl: 12,595; objc: 12,561; yacc: 4,583; cs: 3,846; pascal: 2,840; lex: 1,720; ruby: 1,079; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (76 lines) | stat: -rw-r--r-- 2,467 bytes parent folder | download | duplicates (4)
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
// -*- 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.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);
        }
    }
}