bus.rs 657 Bytes
Newer Older
1
2
3
4
// SPDX-FileCopyrightText: Copyright (c) 2024-2025 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
// SPDX-License-Identifier: Apache-2.0

use super::handle::AuditRecord;
5
use std::sync::OnceLock;
6
7
use tokio::sync::broadcast;

8
static BUS: OnceLock<broadcast::Sender<AuditRecord>> = OnceLock::new();
9
10

pub fn init(capacity: usize) {
11
    let (tx, _rx) = broadcast::channel::<AuditRecord>(capacity);
12
13
14
    let _ = BUS.set(tx);
}

15
pub fn subscribe() -> broadcast::Receiver<AuditRecord> {
16
17
18
19
20
    BUS.get().expect("audit bus not initialized").subscribe()
}

pub fn publish(rec: AuditRecord) {
    if let Some(tx) = BUS.get() {
21
        let _ = tx.send(rec);
22
23
    }
}