nvml_wrapper/struct_wrappers/event.rs
1use crate::device::Device;
2use crate::enums::event::XidError;
3use crate::ffi::bindings::*;
4use crate::{bitmasks::event::EventTypes, Nvml};
5
6/// Information about an event that has occurred.
7// Checked against local
8#[derive(Debug)]
9pub struct EventData<'nvml> {
10 /**
11 Device where the event occurred.
12
13 See `Device.uuid()` for a way to compare this `Device` to another `Device`
14 and find out if they represent the same physical device.
15 */
16 pub device: Device<'nvml>,
17 /// Information about what specific event occurred.
18 pub event_type: EventTypes,
19 /**
20 Stores the last XID error for the device for the
21 nvmlEventTypeXidCriticalError event.
22
23 `None` in the case of any other event type.
24 */
25 pub event_data: Option<XidError>,
26}
27
28impl<'nvml> EventData<'nvml> {
29 /**
30 Create a new `EventData` wrapper.
31
32 The `event_type` bitmask is created via the `EventTypes::from_bits_truncate`
33 method, meaning that any bits that don't correspond to flags present in this
34 version of the wrapper will be dropped.
35
36 # Safety
37
38 It is your responsibility to ensure that the given `nvmlEventdata_t` pointer
39 is valid.
40 */
41 // Clippy bug, see https://github.com/rust-lang/rust-clippy/issues/5593
42 #[allow(clippy::missing_safety_doc)]
43 pub unsafe fn new(event_data: nvmlEventData_t, nvml: &'nvml Nvml) -> Self {
44 let event_type = EventTypes::from_bits_truncate(event_data.eventType);
45
46 EventData {
47 // SAFETY: it is the callers responsibility to ensure that `event_data`
48 // is a valid pointer (meaning its contents will be valid)
49 device: Device::new(event_data.device, nvml),
50 event_type,
51 event_data: if event_type.contains(EventTypes::CRITICAL_XID_ERROR) {
52 Some(match event_data.eventData {
53 999 => XidError::Unknown,
54 v => XidError::Value(v),
55 })
56 } else {
57 None
58 },
59 }
60 }
61}