core_foundation_sys/
messageport.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_void;
11
12use crate::base::{Boolean, CFAllocatorRef, CFIndex, CFTypeID, SInt32};
13use crate::data::CFDataRef;
14use crate::date::CFTimeInterval;
15use crate::runloop::CFRunLoopSourceRef;
16use crate::string::CFStringRef;
17
18#[repr(C)]
19#[derive(Copy, Clone, Debug)]
20pub struct CFMessagePortContext {
21    pub version: CFIndex,
22    pub info: *mut c_void,
23    pub retain: Option<unsafe extern "C" fn(info: *const c_void) -> *const c_void>,
24    pub release: Option<unsafe extern "C" fn(info: *const c_void)>,
25    pub copyDescription: Option<unsafe extern "C" fn(info: *const c_void) -> CFStringRef>,
26}
27
28pub type CFMessagePortCallBack = Option<
29    unsafe extern "C" fn(
30        local: CFMessagePortRef,
31        msgid: i32,
32        data: CFDataRef,
33        info: *mut c_void,
34    ) -> CFDataRef,
35>;
36
37pub type CFMessagePortInvalidationCallBack =
38    Option<unsafe extern "C" fn(ms: CFMessagePortRef, info: *mut c_void)>;
39
40/* CFMessagePortSendRequest Error Codes */
41pub const kCFMessagePortSuccess: SInt32 = 0;
42pub const kCFMessagePortSendTimeout: SInt32 = -1;
43pub const kCFMessagePortReceiveTimeout: SInt32 = -2;
44pub const kCFMessagePortIsInvalid: SInt32 = -3;
45pub const kCFMessagePortTransportError: SInt32 = -4;
46pub const kCFMessagePortBecameInvalidError: SInt32 = -5;
47
48#[repr(C)]
49pub struct __CFMessagePort(c_void);
50pub type CFMessagePortRef = *mut __CFMessagePort;
51
52extern "C" {
53    /*
54     * CFMessagePort.h
55     */
56
57    /* Creating a CFMessagePort Object */
58    pub fn CFMessagePortCreateLocal(
59        allocator: CFAllocatorRef,
60        name: CFStringRef,
61        callout: CFMessagePortCallBack,
62        context: *const CFMessagePortContext,
63        shouldFreeInfo: *mut Boolean,
64    ) -> CFMessagePortRef;
65    pub fn CFMessagePortCreateRemote(
66        allocator: CFAllocatorRef,
67        name: CFStringRef,
68    ) -> CFMessagePortRef;
69
70    /* Configuring a CFMessagePort Object */
71    pub fn CFMessagePortCreateRunLoopSource(
72        allocator: CFAllocatorRef,
73        local: CFMessagePortRef,
74        order: CFIndex,
75    ) -> CFRunLoopSourceRef;
76    pub fn CFMessagePortSetInvalidationCallBack(
77        ms: CFMessagePortRef,
78        callout: CFMessagePortInvalidationCallBack,
79    );
80    pub fn CFMessagePortSetName(ms: CFMessagePortRef, newName: CFStringRef) -> Boolean;
81
82    /* Using a Message Port */
83    pub fn CFMessagePortInvalidate(ms: CFMessagePortRef);
84    pub fn CFMessagePortSendRequest(
85        remote: CFMessagePortRef,
86        msgid: i32,
87        data: CFDataRef,
88        sendTimeout: CFTimeInterval,
89        rcvTimeout: CFTimeInterval,
90        replyMode: CFStringRef,
91        returnData: *mut CFDataRef,
92    ) -> i32;
93    //pub fn CFMessagePortSetDispatchQueue(ms: CFMessagePortRef, queue: dispatch_queue_t);
94
95    /* Examining a Message Port */
96    pub fn CFMessagePortGetContext(ms: CFMessagePortRef, context: *mut CFMessagePortContext);
97    pub fn CFMessagePortGetInvalidationCallBack(
98        ms: CFMessagePortRef,
99    ) -> CFMessagePortInvalidationCallBack;
100    pub fn CFMessagePortGetName(ms: CFMessagePortRef) -> CFStringRef;
101    pub fn CFMessagePortIsRemote(ms: CFMessagePortRef) -> Boolean;
102    pub fn CFMessagePortIsValid(ms: CFMessagePortRef) -> Boolean;
103
104    /* Getting the CFMessagePort Type ID */
105    pub fn CFMessagePortGetTypeID() -> CFTypeID;
106}