endpoint_sec/event/
event_create.rs1use std::ffi::OsStr;
4
5use endpoint_sec_sys::{es_destination_type_t, es_event_create_t, mode_t};
6
7#[cfg(feature = "macos_10_15_1")]
8use crate::Acl;
9use crate::File;
10
11#[doc(alias = "es_event_create_t")]
13pub struct EventCreate<'a> {
14 pub(crate) raw: &'a es_event_create_t,
16 pub(crate) version: u32,
18}
19
20#[derive(Debug, PartialEq, Eq, Hash)]
22#[doc(alias = "es_destination_type_t")]
23#[non_exhaustive]
24pub enum EventCreateDestinationFile<'a> {
25 #[non_exhaustive]
27 ExistingFile {
28 file: File<'a>,
30 },
31 #[non_exhaustive]
33 NewPath {
34 directory: File<'a>,
36 filename: &'a OsStr,
38 mode: mode_t,
40 },
41}
42
43impl<'a> EventCreate<'a> {
44 #[inline(always)]
46 pub fn destination(&self) -> Option<EventCreateDestinationFile<'a>> {
47 match self.raw.destination_type {
48 es_destination_type_t::ES_DESTINATION_TYPE_EXISTING_FILE => {
49 Some(EventCreateDestinationFile::ExistingFile {
50 file: File::new(unsafe { self.raw.destination.existing_file.as_ref() }),
52 })
53 },
54 es_destination_type_t::ES_DESTINATION_TYPE_NEW_PATH => {
55 let new_path = unsafe { &self.raw.destination.new_path };
57 Some(EventCreateDestinationFile::NewPath {
58 directory: File::new(unsafe { new_path.dir() }),
60 filename: unsafe { new_path.filename.as_os_str() },
62 mode: new_path.mode,
63 })
64 },
65 _ => None,
66 }
67 }
68
69 #[inline(always)]
73 #[cfg(feature = "macos_10_15_1")]
74 pub fn acl(&self) -> Option<Acl<'a>> {
75 if self.version < 2 {
76 return None;
77 }
78
79 Acl::from_raw(unsafe { self.raw.anon_1.anon_0.acl })
81 }
82}
83
84unsafe impl Send for EventCreate<'_> {}
86unsafe impl Sync for EventCreate<'_> {}
88
89impl_debug_eq_hash_with_functions!(EventCreate<'a> with version; destination, #[cfg(feature = "macos_10_15_1")] acl);