objc2_core_media/generated/
CMSimpleQueue.rs

1//! This file has been automatically generated by `objc2`'s `header-translator`.
2//! DO NOT EDIT
3use core::cell::UnsafeCell;
4use core::ffi::*;
5use core::marker::{PhantomData, PhantomPinned};
6use core::ptr::NonNull;
7#[cfg(feature = "objc2")]
8use objc2::__framework_prelude::*;
9use objc2_core_foundation::*;
10
11use crate::*;
12
13/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmsimplequeueerror_allocationfailed?language=objc)
14pub const kCMSimpleQueueError_AllocationFailed: OSStatus = -12770;
15/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmsimplequeueerror_requiredparametermissing?language=objc)
16pub const kCMSimpleQueueError_RequiredParameterMissing: OSStatus = -12771;
17/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmsimplequeueerror_parameteroutofrange?language=objc)
18pub const kCMSimpleQueueError_ParameterOutOfRange: OSStatus = -12772;
19/// [Apple's documentation](https://developer.apple.com/documentation/coremedia/kcmsimplequeueerror_queueisfull?language=objc)
20pub const kCMSimpleQueueError_QueueIsFull: OSStatus = -12773;
21
22/// A reference to a CMSimpleQueue, a CF object that implements a simple lockless queue of (void *) elements.
23///
24/// See also [Apple's documentation](https://developer.apple.com/documentation/coremedia/cmsimplequeue?language=objc)
25#[doc(alias = "CMSimpleQueueRef")]
26#[repr(C)]
27pub struct CMSimpleQueue {
28    inner: [u8; 0],
29    _p: UnsafeCell<PhantomData<(*const UnsafeCell<()>, PhantomPinned)>>,
30}
31
32cf_type!(
33    unsafe impl CMSimpleQueue {}
34);
35#[cfg(feature = "objc2")]
36cf_objc2_type!(
37    unsafe impl RefEncode<"opaqueCMSimpleQueue"> for CMSimpleQueue {}
38);
39
40unsafe impl ConcreteType for CMSimpleQueue {
41    /// Returns the CFTypeID of CMSimpleQueue objects.
42    ///
43    /// You can check if a CFTypeRef object is actually a CMSimpleQueue by comparing CFGetTypeID(object)
44    /// with CMSimpleQueueGetTypeID().
45    ///
46    /// Returns: CFTypeID of CMSimpleQueue objects.
47    #[doc(alias = "CMSimpleQueueGetTypeID")]
48    #[inline]
49    fn type_id() -> CFTypeID {
50        extern "C-unwind" {
51            fn CMSimpleQueueGetTypeID() -> CFTypeID;
52        }
53        unsafe { CMSimpleQueueGetTypeID() }
54    }
55}
56
57impl CMSimpleQueue {
58    /// Creates a CMSimpleQueue.
59    ///
60    /// On return, the caller owns the returned CMSimpleQueue, and must release it when done with it.
61    ///
62    /// Returns: Returns noErr if the call succeeds.  Returns kCMSimpleQueueError_ParameterOutOfRange if
63    /// capacity is negative.
64    ///
65    /// # Safety
66    ///
67    /// `queue_out` must be a valid pointer.
68    #[doc(alias = "CMSimpleQueueCreate")]
69    #[inline]
70    pub unsafe fn create(
71        allocator: Option<&CFAllocator>,
72        capacity: i32,
73        queue_out: NonNull<*mut CMSimpleQueue>,
74    ) -> OSStatus {
75        extern "C-unwind" {
76            fn CMSimpleQueueCreate(
77                allocator: Option<&CFAllocator>,
78                capacity: i32,
79                queue_out: NonNull<*mut CMSimpleQueue>,
80            ) -> OSStatus;
81        }
82        unsafe { CMSimpleQueueCreate(allocator, capacity, queue_out) }
83    }
84
85    /// Enqueues an element on the queue.
86    ///
87    /// If the queue is full, this operation will fail.
88    ///
89    /// Returns: Returns noErr if the call succeeds, kCMSimpleQueueError_QueueIsFull if the queue is full.
90    ///
91    /// # Safety
92    ///
93    /// `element` must be a valid pointer.
94    #[doc(alias = "CMSimpleQueueEnqueue")]
95    #[inline]
96    pub unsafe fn enqueue(&self, element: NonNull<c_void>) -> OSStatus {
97        extern "C-unwind" {
98            fn CMSimpleQueueEnqueue(queue: &CMSimpleQueue, element: NonNull<c_void>) -> OSStatus;
99        }
100        unsafe { CMSimpleQueueEnqueue(self, element) }
101    }
102
103    /// Dequeues an element from the queue.
104    ///
105    /// If the queue is empty, NULL will be returned.
106    ///
107    /// Returns: The dequeued element.  NULL if the queue was empty, or if there was some other error.
108    #[doc(alias = "CMSimpleQueueDequeue")]
109    #[inline]
110    pub unsafe fn dequeue(&self) -> *const c_void {
111        extern "C-unwind" {
112            fn CMSimpleQueueDequeue(queue: &CMSimpleQueue) -> *const c_void;
113        }
114        unsafe { CMSimpleQueueDequeue(self) }
115    }
116
117    /// Returns the element at the head of the queue.
118    ///
119    /// If the queue is empty, NULL will be returned.
120    ///
121    /// Returns: The head element.  NULL if the queue was empty, or if there was some other error.
122    #[doc(alias = "CMSimpleQueueGetHead")]
123    #[inline]
124    pub unsafe fn head(&self) -> *const c_void {
125        extern "C-unwind" {
126            fn CMSimpleQueueGetHead(queue: &CMSimpleQueue) -> *const c_void;
127        }
128        unsafe { CMSimpleQueueGetHead(self) }
129    }
130
131    /// Resets the queue.
132    ///
133    /// This function resets the queue to its empty state;  all values
134    /// in the queue prior to reset are lost.   Note that CMSimpleQueueReset
135    /// is not synchronized in any way, so the reader thread and writer thread
136    /// must be held off by the client during this operation.
137    ///
138    /// Returns: Returns noErr if the call succeeds.
139    #[doc(alias = "CMSimpleQueueReset")]
140    #[inline]
141    pub unsafe fn reset(&self) -> OSStatus {
142        extern "C-unwind" {
143            fn CMSimpleQueueReset(queue: &CMSimpleQueue) -> OSStatus;
144        }
145        unsafe { CMSimpleQueueReset(self) }
146    }
147
148    /// Returns the number of elements that can be held in the queue.
149    ///
150    /// Returns: The number of elements that can be held in the queue.  Returns
151    /// 0 if there is an error.
152    #[doc(alias = "CMSimpleQueueGetCapacity")]
153    #[inline]
154    pub unsafe fn capacity(&self) -> i32 {
155        extern "C-unwind" {
156            fn CMSimpleQueueGetCapacity(queue: &CMSimpleQueue) -> i32;
157        }
158        unsafe { CMSimpleQueueGetCapacity(self) }
159    }
160
161    /// Returns the number of elements currently on the queue.
162    ///
163    /// Returns: The number of elements currently in the queue. Returns 0 if there is an error.
164    #[doc(alias = "CMSimpleQueueGetCount")]
165    #[inline]
166    pub unsafe fn count(&self) -> i32 {
167        extern "C-unwind" {
168            fn CMSimpleQueueGetCount(queue: &CMSimpleQueue) -> i32;
169        }
170        unsafe { CMSimpleQueueGetCount(self) }
171    }
172}
173
174extern "C-unwind" {
175    #[deprecated = "renamed to `CMSimpleQueue::create`"]
176    pub fn CMSimpleQueueCreate(
177        allocator: Option<&CFAllocator>,
178        capacity: i32,
179        queue_out: NonNull<*mut CMSimpleQueue>,
180    ) -> OSStatus;
181}
182
183extern "C-unwind" {
184    #[deprecated = "renamed to `CMSimpleQueue::enqueue`"]
185    pub fn CMSimpleQueueEnqueue(queue: &CMSimpleQueue, element: NonNull<c_void>) -> OSStatus;
186}
187
188extern "C-unwind" {
189    #[deprecated = "renamed to `CMSimpleQueue::dequeue`"]
190    pub fn CMSimpleQueueDequeue(queue: &CMSimpleQueue) -> *const c_void;
191}
192
193extern "C-unwind" {
194    #[deprecated = "renamed to `CMSimpleQueue::head`"]
195    pub fn CMSimpleQueueGetHead(queue: &CMSimpleQueue) -> *const c_void;
196}
197
198extern "C-unwind" {
199    #[deprecated = "renamed to `CMSimpleQueue::reset`"]
200    pub fn CMSimpleQueueReset(queue: &CMSimpleQueue) -> OSStatus;
201}
202
203extern "C-unwind" {
204    #[deprecated = "renamed to `CMSimpleQueue::capacity`"]
205    pub fn CMSimpleQueueGetCapacity(queue: &CMSimpleQueue) -> i32;
206}
207
208extern "C-unwind" {
209    #[deprecated = "renamed to `CMSimpleQueue::count`"]
210    pub fn CMSimpleQueueGetCount(queue: &CMSimpleQueue) -> i32;
211}