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(self.ptr.as_ptr()))
47 }
48 .unwrap_or_default()
49 }
50
51 #[must_use]
52 pub fn signpost_type(&self) -> OSLogEntrySignpostType {
53 OSLogEntrySignpostType::from_raw(unsafe {
54 ffi::apple_log_os_log_entry_signpost_type(self.ptr.as_ptr())
55 })
56 }
57}
58
59impl OSLogEntryCommon for OSLogEntrySignpost {
60 fn raw_entry_ptr(&self) -> *mut c_void {
61 self.ptr.as_ptr()
62 }
63}
64
65impl OSLogEntryFromProcess for OSLogEntrySignpost {}
66impl OSLogEntryWithPayload for OSLogEntrySignpost {}
67
68impl Drop for OSLogEntrySignpost {
69 fn drop(&mut self) {
70 unsafe { ffi::apple_log_os_log_entry_release(self.ptr.as_ptr()) };
71 }
72}