Skip to main content

endpoint_sec/event/
event_profile_add.rs

1//! [`EventProfileAdd`]
2
3use std::ffi::OsStr;
4
5use endpoint_sec_sys::{es_event_profile_add_t, es_profile_source_t, es_profile_t};
6
7use crate::Process;
8
9/// Notification for Profiles installed on the system.
10#[doc(alias = "es_event_profile_add_t")]
11pub struct EventProfileAdd<'a> {
12    /// The raw reference.
13    pub(crate) raw: &'a es_event_profile_add_t,
14    /// The version of the message.
15    pub(crate) version: u32,
16}
17
18impl<'a> EventProfileAdd<'a> {
19    /// Process that instigated the Profile install or update.
20    #[inline(always)]
21    pub fn instigator(&self) -> Process<'a> {
22        // Safety: 'a tied to self, object obtained through ES
23        Process::new(unsafe { self.raw.instigator.as_ref() }, self.version)
24    }
25
26    /// `true` if the event is an update to an already installed profile.
27    #[inline(always)]
28    pub fn is_update(&self) -> bool {
29        self.raw.is_update
30    }
31
32    /// Profile install item.
33    #[inline(always)]
34    pub fn profile(&self) -> Profile<'a> {
35        Profile {
36            // Safety: 'a tied to self, object obtained through ES
37            raw: unsafe { self.raw.profile.as_ref() },
38        }
39    }
40}
41
42// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
43unsafe impl Send for EventProfileAdd<'_> {}
44// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
45unsafe impl Sync for EventProfileAdd<'_> {}
46
47impl_debug_eq_hash_with_functions!(EventProfileAdd<'a> with version; instigator, is_update, profile);
48
49/// Structure describing a Profile event
50#[doc(alias = "es_profile_t")]
51pub struct Profile<'a> {
52    /// The raw reference.
53    pub(crate) raw: &'a es_profile_t,
54}
55
56impl<'a> Profile<'a> {
57    /// Profile identifier.
58    #[inline(always)]
59    pub fn identifier(&self) -> &'a OsStr {
60        // Safety: lifetime matches that of message
61        unsafe { self.raw.identifier.as_os_str() }
62    }
63
64    /// Profile UUID.
65    #[inline(always)]
66    pub fn uuid(&self) -> &'a OsStr {
67        // Safety: lifetime matches that of message
68        unsafe { self.raw.uuid.as_os_str() }
69    }
70
71    /// Source of Profile installation (MDM/Manual Install)
72    #[inline(always)]
73    pub fn install_source(&self) -> es_profile_source_t {
74        self.raw.install_source
75    }
76
77    /// Profile organization name.
78    #[inline(always)]
79    pub fn organization(&self) -> &'a OsStr {
80        // Safety: lifetime matches that of message
81        unsafe { self.raw.organization.as_os_str() }
82    }
83
84    /// Profile display name.
85    #[inline(always)]
86    pub fn display_name(&self) -> &'a OsStr {
87        // Safety: lifetime matches that of message
88        unsafe { self.raw.display_name.as_os_str() }
89    }
90
91    /// Profile scope.
92    #[inline(always)]
93    pub fn scope(&self) -> &'a OsStr {
94        // Safety: lifetime matches that of message
95        unsafe { self.raw.scope.as_os_str() }
96    }
97}
98
99// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
100unsafe impl Send for Profile<'_> {}
101
102impl_debug_eq_hash_with_functions!(Profile<'a>; identifier, uuid, install_source, organization, display_name, scope);