mirror of
https://gitee.com/openharmony/interface_sdk_c
synced 2024-11-27 08:51:29 +00:00
!1528 短时任务C API
Merge pull request !1528 from lipengfei/OpenHarmony-5.0.1-Release
This commit is contained in:
commit
79a10b0694
35
backgroundtasks/transient/BUILD.gn
Normal file
35
backgroundtasks/transient/BUILD.gn
Normal file
@ -0,0 +1,35 @@
|
||||
# Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
import("//build/ohos.gni")
|
||||
import("//build/ohos/ndk/ndk.gni")
|
||||
|
||||
ohos_ndk_library("libtransient_task_ndk") {
|
||||
output_name = "transient_task"
|
||||
output_extension = "so"
|
||||
ndk_description_file = "./libtransient_task.ndk.json"
|
||||
system_capability =
|
||||
"SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask"
|
||||
system_capability_headers = [
|
||||
"transient_task/transient_task_api.h",
|
||||
"transient_task/transient_task_type.h",
|
||||
]
|
||||
}
|
||||
|
||||
ohos_ndk_headers("transient_task_header") {
|
||||
dest_dir = "$ndk_headers_out_dir/transient_task"
|
||||
sources = [
|
||||
"include/transient_task_api.h",
|
||||
"include/transient_task_type.h",
|
||||
]
|
||||
}
|
107
backgroundtasks/transient/include/transient_task_api.h
Normal file
107
backgroundtasks/transient/include/transient_task_api.h
Normal file
@ -0,0 +1,107 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_BACKGROUOND_TASK_MANAGER_TRANSIENT_TASK_API_H
|
||||
#define OHOS_BACKGROUOND_TASK_MANAGER_TRANSIENT_TASK_API_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "transient_task_type.h"
|
||||
|
||||
/**
|
||||
* @addtogroup TransientTask
|
||||
* @{
|
||||
*
|
||||
* @brief Provide C interface for the Transient task management.
|
||||
*
|
||||
* @since 13
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file transient_task_api.h
|
||||
*
|
||||
* @brief Declares the APIs for Transient task management.
|
||||
*
|
||||
* @library libtransient_task.so
|
||||
* @kit BackgroundTasksKit
|
||||
* @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
|
||||
* @since 13
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* @brief Requests delayed transition to the suspended state.
|
||||
*
|
||||
* @param reason Indicates the reason for delayed transition to the suspended state.
|
||||
* @param callback Indicates the callback delay time expired.
|
||||
* @param delaySuspendInfo Indicates the info of delay request.
|
||||
* @return {@link ERR_TRANSIENT_TASK_OK} 0 - Success.
|
||||
* {@link ERR_TRANSIENT_TASK_INVALID_PARAM} 401 - Invalid parameter.
|
||||
* {@link ERR_TRANSIENT_TASK_PARCEL_FAILED} 9800002 - Parcelable failed.
|
||||
* {@link ERR_TRANSIENT_TASK_TRANSACTION_FAILED} 9800003 - Transact failed.
|
||||
* {@link ERR_TRANSIENT_TASK_SYS_NOT_READY} 9800004 - System service not ready.
|
||||
* {@link ERR_TRANSIENT_TASK_CLIENT_INFO_VERIFICATION_FAILED} 9900001 - uid or pid info verify failed.
|
||||
* {@link ERR_TRANSIENT_TASK_SERVICE_VERIFICATION_FAILED} 9900002 - Transient task verification failed.
|
||||
* @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
|
||||
* @since 13
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_BackgroundTaskManager_RequestSuspendDelay(const char* reason,
|
||||
TransientTask_Callback callback, TransientTask_DelaySuspendInfo *info);
|
||||
|
||||
/**
|
||||
* @brief Obtains the remaining time before an application enters the suspended state.
|
||||
*
|
||||
* @param requestId Indicates the identifier of the delay request.
|
||||
* @param time Indicates the remaining Time.
|
||||
* @return {@link ERR_TRANSIENT_TASK_OK} 0 - Success.
|
||||
* {@link ERR_TRANSIENT_TASK_INVALID_PARAM} 401 - Invalid parameter.
|
||||
* {@link ERR_TRANSIENT_TASK_PARCEL_FAILED} 9800002 - Parcelable failed.
|
||||
* {@link ERR_TRANSIENT_TASK_TRANSACTION_FAILED} 9800003 - Transact failed.
|
||||
* {@link ERR_TRANSIENT_TASK_SYS_NOT_READY} 9800004 - System service not ready.
|
||||
* {@link ERR_TRANSIENT_TASK_CLIENT_INFO_VERIFICATION_FAILED} 9900001 - uid or pid info verify failed.
|
||||
* {@link ERR_TRANSIENT_TASK_SERVICE_VERIFICATION_FAILED} 9900002 - Transient task verification failed.
|
||||
* @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
|
||||
* @since 13
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_BackgroundTaskManager_GetRemainingDelayTime(int32_t requestId, int32_t *delayTime);
|
||||
|
||||
/**
|
||||
* @brief Cancels delayed transition to the suspended state.
|
||||
*
|
||||
* @param requestId Indicates the identifier of the delay request.
|
||||
* @return {@link ERR_TRANSIENT_TASK_OK} 0 - Success.
|
||||
* {@link ERR_TRANSIENT_TASK_INVALID_PARAM} 401 - Invalid parameter.
|
||||
* {@link ERR_TRANSIENT_TASK_PARCEL_FAILED} 9800002 - Parcelable failed.
|
||||
* {@link ERR_TRANSIENT_TASK_TRANSACTION_FAILED} 9800003 - Transact failed.
|
||||
* {@link ERR_TRANSIENT_TASK_SYS_NOT_READY} 9800004 - System service not ready.
|
||||
* {@link ERR_TRANSIENT_TASK_CLIENT_INFO_VERIFICATION_FAILED} 9900001 - uid or pid info verify failed.
|
||||
* {@link ERR_TRANSIENT_TASK_SERVICE_VERIFICATION_FAILED} 9900002 - Transient task verification failed.
|
||||
* @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
|
||||
* @since 13
|
||||
* @version 1.0
|
||||
*/
|
||||
int32_t OH_BackgroundTaskManager_CancelSuspendDelay(int32_t requestId);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
#endif
|
104
backgroundtasks/transient/include/transient_task_type.h
Normal file
104
backgroundtasks/transient/include/transient_task_type.h
Normal file
@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (c) 2024 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef OHOS_BACKGROUOND_TASK_MANAGER_TRANSIENT_TASK_TYPE_H
|
||||
#define OHOS_BACKGROUOND_TASK_MANAGER_TRANSIENT_TASK_TYPE_H
|
||||
|
||||
/**
|
||||
* @addtogroup TransientTask
|
||||
* @{
|
||||
|
||||
* @brief Provide C interface for the transient task management.
|
||||
* @since 13
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file transient_task_type.h
|
||||
*
|
||||
* @brief Defines the data structures for the C APIs of transient task.
|
||||
*
|
||||
* @library libtransient_task.so
|
||||
* @kit BackgroundTasksKit
|
||||
* @syscap SystemCapability.ResourceSchedule.BackgroundTaskManager.TransientTask
|
||||
* @since 11
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/**
|
||||
* @brief Enum for transient task error code.
|
||||
* @since 13
|
||||
*/
|
||||
typedef enum TransientTask_ErrorCode {
|
||||
/**
|
||||
* @error result is ok.
|
||||
*/
|
||||
ERR_TRANSIENT_TASK_OK = 0,
|
||||
/**
|
||||
* @error Parameter error. Possible causes:
|
||||
* 1. Mandatory parameters are left unspecified;
|
||||
* 2. Incorrect parameters types.
|
||||
*/
|
||||
ERR_TRANSIENT_TASK_INVALID_PARAM = 401,
|
||||
/**
|
||||
* @error Parcel operation failed.
|
||||
*/
|
||||
ERR_TRANSIENT_TASK_PARCEL_FAILED = 9800002,
|
||||
/**
|
||||
* @error Internal transaction failed.
|
||||
*/
|
||||
ERR_TRANSIENT_TASK_TRANSACTION_FAILED = 9800003,
|
||||
/**
|
||||
* @error System service operation failed.
|
||||
*/
|
||||
ERR_TRANSIENT_TASK_SYS_NOT_READY = 9800004,
|
||||
/**
|
||||
* Caller information verification failed for a transient task.
|
||||
*/
|
||||
ERR_TRANSIENT_TASK_CLIENT_INFO_VERIFICATION_FAILED = 9900001,
|
||||
/**
|
||||
* Transient task verification failed.
|
||||
*/
|
||||
ERR_TRANSIENT_TASK_SERVICE_VERIFICATION_FAILED = 9900002,
|
||||
} TransientTask_ErrorCode;
|
||||
|
||||
/**
|
||||
* @brief Define DelaySuspendInfo for TransientTask.
|
||||
*
|
||||
* @since 13
|
||||
* @version 1.0
|
||||
*/
|
||||
typedef struct TransientTask_DelaySuspendInfo {
|
||||
/** The unique identifier of the delay request */
|
||||
int32_t requestId;
|
||||
/** The actual delay duration (ms) */
|
||||
int32_t actualDelayTime;
|
||||
} TransientTask_DelaySuspendInfo;
|
||||
|
||||
/**
|
||||
* @brief Define a callback function when delay time expired.
|
||||
* @since 13
|
||||
*/
|
||||
typedef void (*TransientTask_Callback)(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
/** @} */
|
||||
#endif
|
14
backgroundtasks/transient/libtransient_task.ndk.json
Normal file
14
backgroundtasks/transient/libtransient_task.ndk.json
Normal file
@ -0,0 +1,14 @@
|
||||
[
|
||||
{
|
||||
"first_introduced": "13",
|
||||
"name": "OH_BackgroundTaskManager_RequestSuspendDelay"
|
||||
},
|
||||
{
|
||||
"first_introduced": "13",
|
||||
"name": "OH_BackgroundTaskManager_GetRemainingDelayTime"
|
||||
},
|
||||
{
|
||||
"first_introduced": "13",
|
||||
"name": "OH_BackgroundTaskManager_CancelSuspendDelay"
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue
Block a user