core_foundation_sys/
filedescriptor.rs

1// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution.
3//
4// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7// option. This file may not be copied, modified, or distributed
8// except according to those terms.
9
10use std::os::raw::{c_int, c_void};
11
12use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFOptionFlags, CFTypeID};
13use crate::runloop::CFRunLoopSourceRef;
14use crate::string::CFStringRef;
15
16pub type CFFileDescriptorNativeDescriptor = c_int;
17
18#[repr(C)]
19pub struct __CFFileDescriptor(c_void);
20
21pub type CFFileDescriptorRef = *mut __CFFileDescriptor;
22
23/* Callback Reason Types */
24pub const kCFFileDescriptorReadCallBack: CFOptionFlags = 1 << 0;
25pub const kCFFileDescriptorWriteCallBack: CFOptionFlags = 1 << 1;
26
27pub type CFFileDescriptorCallBack =
28    extern "C" fn(f: CFFileDescriptorRef, callBackTypes: CFOptionFlags, info: *mut c_void);
29
30#[repr(C)]
31#[derive(Debug, Clone, Copy)]
32pub struct CFFileDescriptorContext {
33    pub version: CFIndex,
34    pub info: *mut c_void,
35    pub retain: Option<extern "C" fn(info: *const c_void) -> *const c_void>,
36    pub release: Option<extern "C" fn(info: *const c_void)>,
37    pub copyDescription: Option<extern "C" fn(info: *const c_void) -> CFStringRef>,
38}
39
40extern "C" {
41    /*
42     * CFFileDescriptor.h
43     */
44
45    /* Creating a CFFileDescriptor */
46    pub fn CFFileDescriptorCreate(
47        allocator: CFAllocatorRef,
48        fd: CFFileDescriptorNativeDescriptor,
49        closeOnInvalidate: Boolean,
50        callout: CFFileDescriptorCallBack,
51        context: *const CFFileDescriptorContext,
52    ) -> CFFileDescriptorRef;
53
54    /* Getting Information About a File Descriptor */
55    pub fn CFFileDescriptorGetNativeDescriptor(
56        f: CFFileDescriptorRef,
57    ) -> CFFileDescriptorNativeDescriptor;
58    pub fn CFFileDescriptorIsValid(f: CFFileDescriptorRef) -> Boolean;
59    pub fn CFFileDescriptorGetContext(
60        f: CFFileDescriptorRef,
61        context: *mut CFFileDescriptorContext,
62    );
63
64    /* Invalidating a File Descriptor */
65    pub fn CFFileDescriptorInvalidate(f: CFFileDescriptorRef);
66
67    /* Managing Callbacks */
68    pub fn CFFileDescriptorEnableCallBacks(f: CFFileDescriptorRef, callBackTypes: CFOptionFlags);
69    pub fn CFFileDescriptorDisableCallBacks(f: CFFileDescriptorRef, callBackTypes: CFOptionFlags);
70
71    /* Creating a Run Loop Source */
72    pub fn CFFileDescriptorCreateRunLoopSource(
73        allocator: CFAllocatorRef,
74        f: CFFileDescriptorRef,
75        order: CFIndex,
76    ) -> CFRunLoopSourceRef;
77
78    /* Getting the CFFileDescriptor Type ID */
79    pub fn CFFileDescriptorGetTypeID() -> CFTypeID;
80}