endpoint_sec/event/event_screesharing_detach.rs
1//! [`EventScreensharingDetach`]
2
3use std::ffi::OsStr;
4use std::net::IpAddr;
5use std::str::FromStr;
6
7use endpoint_sec_sys::{es_address_type_t, es_event_screensharing_detach_t, es_graphical_session_id_t};
8
9/// Screen Sharing has detached from a graphical session..
10#[doc(alias = "es_event_screensharing_detach_t")]
11pub struct EventScreensharingDetach<'a> {
12 /// Raw event
13 pub(crate) raw: &'a es_event_screensharing_detach_t,
14}
15
16impl<'a> EventScreensharingDetach<'a> {
17 /// Type of source address.
18 #[inline(always)]
19 pub fn source_address_type(&self) -> es_address_type_t {
20 self.raw.source_address_type
21 }
22
23 /// Optional. Source address of connection, or empty. Depending on the transport used, the
24 /// source address may or may not be available.
25 #[inline(always)]
26 pub fn source_address(&self) -> &'a OsStr {
27 // Safety: 'a tied to self, object obtained through ES
28 unsafe { self.raw.source_address.as_os_str() }
29 }
30
31 /// Optional. For screen sharing initiated using an Apple ID (e.g., from Messages or FaceTime),
32 /// this is the viewer's (client's) Apple ID. It is not necessarily the Apple ID that invited
33 /// the screen sharing. Empty if unavailable.
34 #[inline(always)]
35 pub fn viewer_appleid(&self) -> &'a OsStr {
36 // Safety: 'a tied to self, object obtained through ES
37 unsafe { self.raw.viewer_appleid.as_os_str() }
38 }
39
40 /// Graphical session id of the screen shared.
41 #[inline(always)]
42 pub fn graphical_session_id(&self) -> es_graphical_session_id_t {
43 self.raw.graphical_session_id
44 }
45
46 /// Source address as an [`IpAddr`] from the standard library, if possible.
47 #[inline(always)]
48 pub fn source_address_std(&self) -> Option<IpAddr> {
49 let sa = self.source_address().to_str()?;
50 IpAddr::from_str(sa).ok()
51 }
52}
53
54// Safety: safe to send across threads: does not contain any interior mutability nor depend on current thread state
55unsafe impl Send for EventScreensharingDetach<'_> {}
56// Safety: safe to share across threads: does not contain any interior mutability nor depend on current thread state
57unsafe impl Sync for EventScreensharingDetach<'_> {}
58
59impl_debug_eq_hash_with_functions!(
60 EventScreensharingDetach<'a>;
61 source_address_type, source_address, viewer_appleid, graphical_session_id,
62);