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")]
23pub enum EventCreateDestinationFile<'a> {
24 ExistingFile(File<'a>),
26 NewPath {
28 directory: File<'a>,
30 filename: &'a OsStr,
32 mode: mode_t,
34 },
35}
36
37impl<'a> EventCreate<'a> {
38 #[inline(always)]
40 pub fn destination(&self) -> Option<EventCreateDestinationFile<'a>> {
41 match self.raw.destination_type {
42 es_destination_type_t::ES_DESTINATION_TYPE_EXISTING_FILE => {
43 Some(EventCreateDestinationFile::ExistingFile(
44 File::new(unsafe { self.raw.destination.existing_file.as_ref() }),
46 ))
47 },
48 es_destination_type_t::ES_DESTINATION_TYPE_NEW_PATH => {
49 let new_path = unsafe { &self.raw.destination.new_path };
51 Some(EventCreateDestinationFile::NewPath {
52 directory: File::new(unsafe { new_path.dir() }),
54 filename: unsafe { new_path.filename.as_os_str() },
56 mode: new_path.mode,
57 })
58 },
59 _ => None,
60 }
61 }
62
63 #[inline(always)]
67 #[cfg(feature = "macos_10_15_1")]
68 pub fn acl(&self) -> Option<Acl<'a>> {
69 if self.version < 2 {
70 return None;
71 }
72
73 Acl::from_raw(unsafe { self.raw.anon_1.anon_0.acl })
75 }
76}
77
78unsafe impl Send for EventCreate<'_> {}
80unsafe impl Sync for EventCreate<'_> {}
82
83impl_debug_eq_hash_with_functions!(EventCreate<'a> with version; destination, #[cfg(feature = "macos_10_15_1")] acl);