Skip to main content

endpoint_sec/event/
event_btm_launch_item_remove.rs

1//! [`EventBtmLaunchItemRemove`]
2
3use endpoint_sec_sys::es_event_btm_launch_item_remove_t;
4
5use crate::{AuditToken, BtmLaunchItem, Process};
6
7/// A launch item being removed from background task management.
8#[doc(alias = "es_event_btm_launch_item_add_t")]
9pub struct EventBtmLaunchItemRemove<'a> {
10    /// Raw event
11    pub(crate) raw: &'a es_event_btm_launch_item_remove_t,
12    /// Message version
13    pub(crate) version: u32,
14}
15
16impl<'a> EventBtmLaunchItemRemove<'a> {
17    /// Optional. Process that instigated the BTM operation (XPC caller that asked for the item to
18    /// be removed).
19    #[inline(always)]
20    pub fn instigator(&self) -> Option<Process<'a>> {
21        // Safety: 'a tied to self, object obtained through ES
22        let process = unsafe { self.raw.instigator()? };
23        Some(Process::new(process, self.version))
24    }
25
26    /// Audit token of the process that instigated this event.
27    pub fn instigator_token(&self) -> Option<AuditToken> {
28        #[cfg(feature = "macos_15_0_0")]
29        if self.version >= 8 {
30            // Safety: 'a tied to self, object obtained through ES
31            let token = unsafe { self.raw.instigator_token() };
32            return token.map(|v| AuditToken(*v));
33        }
34
35        // On older version, grab it from the instigator object.
36        self.instigator().map(|v| v.audit_token())
37    }
38
39    /// Optional. App process that removed the item.
40    #[inline(always)]
41    pub fn app(&self) -> Option<Process<'a>> {
42        // Safety: 'a tied to self, object obtained through ES
43        let process = unsafe { self.raw.app()? };
44        Some(Process::new(process, self.version))
45    }
46
47    /// Audit token of the app process that removed the item.
48    pub fn app_token(&self) -> Option<AuditToken> {
49        #[cfg(feature = "macos_15_0_0")]
50        if self.version >= 8 {
51            // Safety: 'a tied to self, object obtained through ES
52            let token = unsafe { self.raw.app_token() };
53            return token.map(|v| AuditToken(*v));
54        }
55
56        // On older version, grab it from the instigator object.
57        self.app().map(|v| v.audit_token())
58    }
59
60    /// BTM launch item.
61    #[inline(always)]
62    pub fn item(&self) -> BtmLaunchItem<'a> {
63        // Safety: 'a tied to self, object obtained through ES
64        BtmLaunchItem::new(unsafe { self.raw.item() })
65    }
66}
67
68// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
69unsafe impl Send for EventBtmLaunchItemRemove<'_> {}
70// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
71unsafe impl Sync for EventBtmLaunchItemRemove<'_> {}
72
73impl_debug_eq_hash_with_functions!(EventBtmLaunchItemRemove<'a>; instigator, instigator_token, app, app_token, item);