1cac7dca0Sopenharmony_ci// Copyright (c) 2023 Huawei Device Co., Ltd.
2cac7dca0Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License");
3cac7dca0Sopenharmony_ci// you may not use this file except in compliance with the License.
4cac7dca0Sopenharmony_ci// You may obtain a copy of the License at
5cac7dca0Sopenharmony_ci//
6cac7dca0Sopenharmony_ci//     http://www.apache.org/licenses/LICENSE-2.0
7cac7dca0Sopenharmony_ci//
8cac7dca0Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software
9cac7dca0Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS,
10cac7dca0Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11cac7dca0Sopenharmony_ci// See the License for the specific language governing permissions and
12cac7dca0Sopenharmony_ci// limitations under the License.
13cac7dca0Sopenharmony_ci
14cac7dca0Sopenharmony_ciuse libc::{c_int, c_uchar, c_uint, c_ulonglong, c_void};
15cac7dca0Sopenharmony_ci
16cac7dca0Sopenharmony_ci// Unstable interface, rust encapsulation temporarily not provided
17cac7dca0Sopenharmony_ci
18cac7dca0Sopenharmony_citype FfrtSysEventHandleT = *mut c_void;
19cac7dca0Sopenharmony_citype DestroyFunc = extern "C" fn(*mut c_void);
20cac7dca0Sopenharmony_citype FfrtFdCallBack = extern "C" fn(*const c_void, c_uint, c_uchar);
21cac7dca0Sopenharmony_citype FfrtExecHook = extern "C" fn(*mut c_void);
22cac7dca0Sopenharmony_citype FfrtTimerHandle = *mut c_void;
23cac7dca0Sopenharmony_ci
24cac7dca0Sopenharmony_ci#[link(name = "ffrt")]
25cac7dca0Sopenharmony_ci// sys_event.h
26cac7dca0Sopenharmony_ciextern "C" {
27cac7dca0Sopenharmony_ci    #![allow(unused)]
28cac7dca0Sopenharmony_ci    fn ffrt_sys_event_create(ty: c_int, fd: usize, filter: usize) -> FfrtSysEventHandleT;
29cac7dca0Sopenharmony_ci    fn ffrt_sys_event_wait(event: FfrtSysEventHandleT, sec: i64) -> c_int;
30cac7dca0Sopenharmony_ci    fn ffrt_sys_event_destroy(event: FfrtSysEventHandleT, func: DestroyFunc, arg: *mut c_void);
31cac7dca0Sopenharmony_ci
32cac7dca0Sopenharmony_ci    /// Registers the fd to ffrt's epoll. Callback will be called when io events
33cac7dca0Sopenharmony_ci    /// arrived.
34cac7dca0Sopenharmony_ci    pub fn ffrt_poller_register(
35cac7dca0Sopenharmony_ci        fd: c_int,
36cac7dca0Sopenharmony_ci        events: c_uint,
37cac7dca0Sopenharmony_ci        data: *const c_void,
38cac7dca0Sopenharmony_ci        callback: FfrtFdCallBack,
39cac7dca0Sopenharmony_ci    ) -> c_int;
40cac7dca0Sopenharmony_ci
41cac7dca0Sopenharmony_ci    /// Deregisters the fd from ffrt's epoll.
42cac7dca0Sopenharmony_ci    pub fn ffrt_poller_deregister(fd: c_int) -> c_int;
43cac7dca0Sopenharmony_ci
44cac7dca0Sopenharmony_ci    /// Registers a timer to ffrt's timer poller. Callback will be called when
45cac7dca0Sopenharmony_ci    /// timer events arrived.
46cac7dca0Sopenharmony_ci    pub fn ffrt_timer_start(
47cac7dca0Sopenharmony_ci        duration: c_ulonglong,
48cac7dca0Sopenharmony_ci        waker: *mut c_void,
49cac7dca0Sopenharmony_ci        callback: FfrtExecHook,
50cac7dca0Sopenharmony_ci    ) -> FfrtTimerHandle;
51cac7dca0Sopenharmony_ci
52cac7dca0Sopenharmony_ci    /// Deregisters the timer from ffrt's timer poller
53cac7dca0Sopenharmony_ci    pub fn ffrt_timer_stop(handle: FfrtTimerHandle);
54cac7dca0Sopenharmony_ci
55cac7dca0Sopenharmony_ci    /// Checks whether the timer has expired. A returned value of 1 indicates
56cac7dca0Sopenharmony_ci    /// the timer has reached its deadline, otherwise, the timer has not expired
57cac7dca0Sopenharmony_ci    /// yet.
58cac7dca0Sopenharmony_ci    pub fn ffrt_timer_query(handle: FfrtTimerHandle) -> c_int;
59cac7dca0Sopenharmony_ci
60cac7dca0Sopenharmony_ci    /// Wakes up the poller to poll timer/io events.
61cac7dca0Sopenharmony_ci    pub fn ffrt_poller_wakeup();
62cac7dca0Sopenharmony_ci}
63