apple_log/
os_log_entry_signpost.rs1use core::ffi::c_void;
2use std::ptr::NonNull;
3
4use crate::bridge_support::take_optional_c_string;
5use crate::ffi;
6use crate::os_log_store::{OSLogEntryCommon, OSLogEntryFromProcess, OSLogEntryWithPayload};
7
8#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
10pub enum OSLogEntrySignpostType {
11 Undefined,
12 IntervalBegin,
13 IntervalEnd,
14 Event,
15}
16
17impl OSLogEntrySignpostType {
18 pub(crate) const fn from_raw(raw: i32) -> Self {
19 match raw {
20 1 => Self::IntervalBegin,
21 2 => Self::IntervalEnd,
22 3 => Self::Event,
23 _ => Self::Undefined,
24 }
25 }
26}
27
28pub struct OSLogEntrySignpost {
30 ptr: NonNull<c_void>,
31}
32
33impl OSLogEntrySignpost {
34 pub(crate) const fn from_raw(ptr: NonNull<c_void>) -> Self {
35 Self { ptr }
36 }
37
38 #[must_use]
39 pub fn signpost_identifier(&self) -> u64 {
40 unsafe { ffi::apple_log_os_log_entry_signpost_identifier(self.ptr.as_ptr()) }
41 }
42
43 #[must_use]
44 pub fn signpost_name(&self) -> String {
45 unsafe {
46 take_optional_c_string(ffi::apple_log_os_log_entry_copy_signpost_name(
47 self.ptr.as_ptr(),
48 ))
49 }
50 .unwrap_or_default()
51 }
52
53 #[must_use]
54 pub fn signpost_type(&self) -> OSLogEntrySignpostType {
55 OSLogEntrySignpostType::from_raw(unsafe {
56 ffi::apple_log_os_log_entry_signpost_type(self.ptr.as_ptr())
57 })
58 }
59}
60
61impl OSLogEntryCommon for OSLogEntrySignpost {
62 fn raw_entry_ptr(&self) -> *mut c_void {
63 self.ptr.as_ptr()
64 }
65}
66
67impl OSLogEntryFromProcess for OSLogEntrySignpost {}
68impl OSLogEntryWithPayload for OSLogEntrySignpost {}
69
70impl Drop for OSLogEntrySignpost {
71 fn drop(&mut self) {
72 unsafe { ffi::apple_log_os_log_entry_release(self.ptr.as_ptr()) };
73 }
74}