1 // Copyright (c) 2023 Huawei Device Co., Ltd. 2 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // you may not use this file except in compliance with the License. 4 // You may obtain a copy of the License at 5 // 6 // http://www.apache.org/licenses/LICENSE-2.0 7 // 8 // Unless required by applicable law or agreed to in writing, software 9 // distributed under the License is distributed on an "AS IS" BASIS, 10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // See the License for the specific language governing permissions and 12 // limitations under the License. 13 14 use libc::{c_int, c_uchar, c_uint, c_void}; 15 16 // Unstable interface, rust encapsulation temporarily not provided 17 18 type FfrtSysEventHandleT = *mut c_void; 19 type DestroyFunc = extern "C" fn(*mut c_void); 20 type FfrtFdCallBack = extern "C" fn(*const c_void, c_uint, c_uchar); 21 22 #[link(name = "ffrt")] 23 // sys_event.h 24 extern "C" { 25 #![allow(unused)] ffrt_sys_event_create(ty: c_int, fd: usize, filter: usize) -> FfrtSysEventHandleT26 fn ffrt_sys_event_create(ty: c_int, fd: usize, filter: usize) -> FfrtSysEventHandleT; ffrt_sys_event_wait(event: FfrtSysEventHandleT, sec: i64) -> c_int27 fn ffrt_sys_event_wait(event: FfrtSysEventHandleT, sec: i64) -> c_int; ffrt_sys_event_destroy(event: FfrtSysEventHandleT, func: DestroyFunc, arg: *mut c_void)28 fn ffrt_sys_event_destroy(event: FfrtSysEventHandleT, func: DestroyFunc, arg: *mut c_void); 29 30 /// Registers the fd to ffrt's epoll. Callback will be called when io events 31 /// arrived. ffrt_poller_register( fd: c_int, events: c_uint, data: *const c_void, callback: FfrtFdCallBack, ) -> c_int32 pub fn ffrt_poller_register( 33 fd: c_int, 34 events: c_uint, 35 data: *const c_void, 36 callback: FfrtFdCallBack, 37 ) -> c_int; 38 39 /// Deregisters the fd from ffrt's epoll. ffrt_poller_deregister(fd: c_int) -> c_int40 pub fn ffrt_poller_deregister(fd: c_int) -> c_int; 41 } 42