File: rust_pings.jinja2

package info (click to toggle)
firefox-esr 128.13.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,230,012 kB
  • sloc: cpp: 7,103,971; javascript: 6,088,450; ansic: 3,653,980; python: 1,212,330; xml: 594,604; asm: 420,652; java: 182,969; sh: 71,124; makefile: 20,747; perl: 13,449; objc: 12,399; yacc: 4,583; cs: 3,846; pascal: 2,973; lex: 1,720; ruby: 1,194; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 54; csh: 10
file content (111 lines) | stat: -rw-r--r-- 3,597 bytes parent folder | download | duplicates (6)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
// -*- 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.include_info_sections|rust }},
        {{ obj.enabled|rust }},
        {{ obj.schedules_pings|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 %}
        }
    }
}

/// Schedule pings alongside a parent ping.
///
/// Should be called in `submit` of the parent ping
/// to also submit pings that should ride along.
///
/// # Arguments
///
/// `submitted_ping`: The parent ping that is submitted
/// `reason`: The original reason for the submitted ping.
///           Will be used for the ride-along ping too.
#[doc(hidden)]
pub fn schedule_pings(submitted_ping: &str, reason: Option<&str>) {
    {% if ping_schedule_reverse_map|length %}
    match submitted_ping {
        {% for ping, schedule in ping_schedule_reverse_map.items() %}
        "{{ping}}" => {
            log::info!("Submitting pings {{ schedule|join(', ') }} along with {{ping}}");
            {% for ping_name in schedule %}
            let _ = {{ ping_name|snake_case }}.submit(reason);
            {% endfor %}
        },
        {% endfor %}
        _ => {},
    }
    {% else %}
    // Ignore arguments.
    _ = submitted_ping;
    _ = reason;
    {% endif %}
}

#[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);
        }
    }
}