diff --git a/README.md b/README.md index 7939d274f..959da5d1f 100644 --- a/README.md +++ b/README.md @@ -45,8 +45,13 @@ ``` + ## 相关仓 [interface_sdk_c](https://gitee.com/openharmony-sig/interface_sdk_c/) + [C API编码规范](https://gitee.com/openharmony-sig/interface_sdk_c/blob/master/docs/capi_naming.md): 描述了OpenHarmony C API的设计规范,指导开发者如何设计发布一个接口。 + [C API构建指南](https://gitee.com/openharmony-sig/interface_sdk_c/blob/master/docs/howto_add.md):描述了如何在build.gn中添加C API的构建目标。 + + diff --git a/multimedia/audio_framework/common/native_audiostream_base.h b/multimedia/audio_framework/common/native_audiostream_base.h index 9270d8437..4d4cc435b 100644 --- a/multimedia/audio_framework/common/native_audiostream_base.h +++ b/multimedia/audio_framework/common/native_audiostream_base.h @@ -35,8 +35,8 @@ * @version 1.0 */ -#ifndef ST_NATIVE_AUDIOSTREAM_BASE_H -#define ST_NATIVE_AUDIOSTREAM_BASE_H +#ifndef NATIVE_AUDIOSTREAM_BASE_H +#define NATIVE_AUDIOSTREAM_BASE_H #include @@ -479,7 +479,7 @@ typedef struct OH_AudioRenderer_Callbacks_Struct { * * @since 10 */ - int32_t (*OH_AudioRenderer_OnInterrptEvent)( + int32_t (*OH_AudioRenderer_OnInterruptEvent)( OH_AudioRenderer* renderer, void* userData, OH_AudioInterrupt_ForceType type, @@ -532,8 +532,8 @@ typedef struct OH_AudioCapturer_Callbacks_Struct { * * @since 10 */ - int32_t (*OH_AudioCapturer_OnInterrptEvent)( - OH_AudioCapturer* renderer, + int32_t (*OH_AudioCapturer_OnInterruptEvent)( + OH_AudioCapturer* capturer, void* userData, OH_AudioInterrupt_ForceType type, OH_AudioInterrupt_Hint hint); @@ -553,4 +553,4 @@ typedef struct OH_AudioCapturer_Callbacks_Struct { } #endif -#endif // ST_NATIVE_AUDIOSTREAM_BASE_H +#endif // NATIVE_AUDIOSTREAM_BASE_H diff --git a/multimedia/av_codec/avcodec_audio_channel_layout.h b/multimedia/av_codec/avcodec_audio_channel_layout.h index 364bd6a12..4b6354d2b 100644 --- a/multimedia/av_codec/avcodec_audio_channel_layout.h +++ b/multimedia/av_codec/avcodec_audio_channel_layout.h @@ -146,14 +146,18 @@ enum AudioChannelLayout : uint64_t { AudioChannelSet::TOP_FRONT_LEFT | AudioChannelSet::TOP_FRONT_RIGHT), STEREO_DOWNMIX = (AudioChannelSet::STEREO_LEFT | AudioChannelSet::STEREO_RIGHT), - HOA_FIRST = AudioChannelSet::AMBISONICS_ACN0 | AudioChannelSet::AMBISONICS_ACN1 | AudioChannelSet::AMBISONICS_ACN2 | - AudioChannelSet::AMBISONICS_ACN3, - HOA_SECOND = HOA_FIRST | AudioChannelSet::AMBISONICS_ACN4 | AudioChannelSet::AMBISONICS_ACN5 | - AudioChannelSet::AMBISONICS_ACN6 | AudioChannelSet::AMBISONICS_ACN7 | AudioChannelSet::AMBISONICS_ACN8, - HOA_THIRD = HOA_SECOND | AudioChannelSet::AMBISONICS_ACN9 | AudioChannelSet::AMBISONICS_ACN10 | - AudioChannelSet::AMBISONICS_ACN11 | AudioChannelSet::AMBISONICS_ACN12 | - AudioChannelSet::AMBISONICS_ACN13 | AudioChannelSet::AMBISONICS_ACN14 | - AudioChannelSet::AMBISONICS_ACN15, + CH_2POINT0POINT2 = (STEREO | AudioChannelSet::TOP_SIDE_LEFT | AudioChannelSet::TOP_SIDE_RIGHT), + CH_2POINT1POINT2 = (CH_2POINT0POINT2 | AudioChannelSet::LOW_FREQUENCY), + CH_3POINT0POINT2 = (CH_2POINT0POINT2 | AudioChannelSet::FRONT_CENTER), + HOA_ORDER1_ACN_N3D = 0x100000000001, + HOA_ORDER1_ACN_SN3D = 0x100000001001, + HOA_ORDER1_FUMA = 0x100000000101, + HOA_ORDER2_ACN_N3D = 0x100000000002, + HOA_ORDER2_ACN_SN3D = 0x100000001002, + HOA_ORDER2_FUMA = 0x100000000102, + HOA_ORDER3_ACN_N3D = 0x100000000003, + HOA_ORDER3_ACN_SN3D = 0x100000001003, + HOA_ORDER3_FUMA = 0x100000000103, }; #ifdef __cplusplus } diff --git a/multimedia/av_codec/native_avcodec_base.h b/multimedia/av_codec/native_avcodec_base.h index bedee4004..4d43427ca 100644 --- a/multimedia/av_codec/native_avcodec_base.h +++ b/multimedia/av_codec/native_avcodec_base.h @@ -160,6 +160,10 @@ extern const char *OH_AVCODEC_MIMETYPE_VIDEO_MPEG4; extern const char *OH_AVCODEC_MIMETYPE_IMAGE_JPG; extern const char *OH_AVCODEC_MIMETYPE_IMAGE_PNG; extern const char *OH_AVCODEC_MIMETYPE_IMAGE_BMP; +extern const char *OH_AVCODEC_MIMETYPE_AUDIO_AVS3DA; +extern const char *OH_AVCODEC_MIMETYPE_AUDIO_AMR_NB; +extern const char *OH_AVCODEC_MIMETYPE_AUDIO_AMR_WB; +extern const char *OH_AVCODEC_MIMETYPE_AUDIO_OPUS; /** * @brief The extra data's key of surface Buffer @@ -184,7 +188,7 @@ extern const char *OH_MD_KEY_TRACK_TYPE; extern const char *OH_MD_KEY_CODEC_MIME; /* Key for duration, value type is int64_t. */ extern const char *OH_MD_KEY_DURATION; -/* Key for bitrate, value type is uint32_t. */ +/* Key for bitrate, value type is int64_t. */ extern const char *OH_MD_KEY_BITRATE; /* Key for max input size, value type is uint32_t */ extern const char *OH_MD_KEY_MAX_INPUT_SIZE; @@ -255,6 +259,18 @@ extern const char *OH_MD_KEY_DESCRIPTION; extern const char *OH_MD_KEY_LYRICS; /* source format Key for track count, value type is uint32_t */ extern const char *OH_MD_KEY_TRACK_COUNT; +/* Key for type of file, value type is int32_t, see @OH_FileType */ +extern const char *OH_MD_KEY_FILE_TYPE; +/* Key for whether the file contains video tracks, value type is boolean */ +extern const char *OH_MD_KEY_HAS_VIDEO; +/* Key for whether the file contains audio tracks, value type is boolean */ +extern const char *OH_MD_KEY_HAS_AUDIO; +/* Key for author of file, value type is string */ +extern const char *OH_MD_KEY_AUTHOR; +/* Key for composer of file, value type is string */ +extern const char *OH_MD_KEY_COMPOSER; +/* Key for cover of file, value type is uint8_t pointer */ +extern const char *OH_MD_KEY_COVER; /* Key for the desired encoding channel layout, value type is int64_t, this key is only supported for encoders */ extern const char *OH_MD_KEY_CHANNEL_LAYOUT; /* Key for bits per coded sample, value type is uint32_t, supported for flac encoder, see @OH_BitsPerSample */ @@ -275,6 +291,32 @@ extern const char *OH_MD_KEY_SCALING_MODE; extern const char *OH_MD_MAX_INPUT_BUFFER_COUNT; /* Key for max output buffer count, value type is int32_t */ extern const char *OH_MD_MAX_OUTPUT_BUFFER_COUNT; +/* Key for codec compression level, value type is uint32_t */ +extern const char *OH_MD_KEY_COMPRESSION_LEVEL; +/* Key for encode level, value type is int32_t. see @OH_HEVCLevel. */ +extern const char *OH_MD_KEY_LEVEL; +/* Key for chroma location, value type is int32_t. see @OH_ChromaLocation. */ +extern const char *OH_MD_KEY_VIDEO_CHROMA_LOCATION; + +/** + * @brief File type. + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 10 + * @version 1.0 + */ +typedef enum OH_FileType { + FILE_TYPE_UNKNOW = 0, + FILE_TYPE_MP4 = 101, + FILE_TYPE_MPEGTS = 102, + FILE_TYPE_MKV = 103, + FILE_TYPE_AMR = 201, + FILE_TYPE_AAC = 202, + FILE_TYPE_MP3 = 203, + FILE_TYPE_FLAC = 204, + FILE_TYPE_OGG = 205, + FILE_TYPE_M4A = 206, + FILE_TYPE_WAV = 207, +} OH_FileType; /** * @brief Media type. @@ -349,6 +391,27 @@ typedef enum OH_HEVCProfile { HEVC_PROFILE_MAIN_10_HDR10_PLUS = 4, } OH_HEVCProfile; +/** + * @brief HEVC Level + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 10 + */ +enum OH_HEVCLevel { + HEVC_LEVEL_1 = 0, + HEVC_LEVEL_2 = 1, + HEVC_LEVEL_21 = 2, + HEVC_LEVEL_3 = 3, + HEVC_LEVEL_31 = 4, + HEVC_LEVEL_4 = 5, + HEVC_LEVEL_41 = 6, + HEVC_LEVEL_5 = 7, + HEVC_LEVEL_51 = 8, + HEVC_LEVEL_52 = 9, + HEVC_LEVEL_6 = 10, + HEVC_LEVEL_61 = 11, + HEVC_LEVEL_62 = 12, +}; + /** * @brief Color Primary * @syscap SystemCapability.Multimedia.Media.CodecBase @@ -415,6 +478,21 @@ typedef enum OH_MatrixCoefficient { MATRIX_COEFFICIENT_ICTCP = 14, } OH_MatrixCoefficient; +/** + * @brief Chroma Location + * @syscap SystemCapability.Multimedia.Media.CodecBase + * @since 10 + */ +enum OH_ChromaLocation { + CHROMA_LOC_UNSPECIFIED = 0, + CHROMA_LOC_LEFT = 1, ///< MPEG-2/4 4:2:0, H.264 default for 4:2:0 + CHROMA_LOC_CENTER = 2, ///< MPEG-1 4:2:0, JPEG 4:2:0, H.263 4:2:0 + CHROMA_LOC_TOPLEFT = 3, ///< ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2 + CHROMA_LOC_TOP = 4, + CHROMA_LOC_BOTTOMLEFT = 5, + CHROMA_LOC_BOTTOM = 6, +}; + /** * @brief Scaling Mode * @syscap SystemCapability.Multimedia.Media.CodecBase diff --git a/multimedia/av_codec/native_avsource.h b/multimedia/av_codec/native_avsource.h index fe6ab38dc..5a9e71e0c 100644 --- a/multimedia/av_codec/native_avsource.h +++ b/multimedia/av_codec/native_avsource.h @@ -31,8 +31,7 @@ typedef struct OH_AVSource OH_AVSource; * @brief Creates an OH_AVSource instance that models the media at the URI. * @syscap SystemCapability.Multimedia.Media.Spliter * @param uri An URI for a remote media resource. - * @return Returns AV_ERR_OK if the execution is successful, - * otherwise returns a specific error code, refer to {@link OH_AVErrCode} + * @return Returns a pointer to an OH_AVSource instance * @since 10 */ OH_AVSource *OH_AVSource_CreateWithURI(char *uri); @@ -43,8 +42,7 @@ OH_AVSource *OH_AVSource_CreateWithURI(char *uri); * @param fd The fileDescriptor of data source. * @param offset The offset into the file to start reading. * @param size The file size in bytes. - * @return Returns AV_ERR_OK if the execution is successful, - * otherwise returns a specific error code, refer to {@link OH_AVErrCode} + * @return Returns a pointer to an OH_AVSource instance * @since 10 */ OH_AVSource *OH_AVSource_CreateWithFD(int32_t fd, int64_t offset, int64_t size); diff --git a/resourceschedule/ffrt/c/condition_variable.h b/resourceschedule/ffrt/c/condition_variable.h index 0754521bb..3f4c75c0e 100644 --- a/resourceschedule/ffrt/c/condition_variable.h +++ b/resourceschedule/ffrt/c/condition_variable.h @@ -1,118 +1,118 @@ -/* - * Copyright (c) 2023 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. - */ - -/** - * @addtogroup Ffrt - * @{ - * - * @brief ffrt provides APIs. - * - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * - * @since 10 - */ - - /** - * @file condition_variable.h - * - * @brief Declares the condition variable interfaces in C. - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -#ifndef FFRT_API_C_CONDITION_VARIABLE_H -#define FFRT_API_C_CONDITION_VARIABLE_H -#include -#include "type_def.h" - -/** - * @brief Initializes a condition variable. - * - * @param cond Indicates a pointer to the condition variable. - * @param attr Indicates a pointer to the condition variable attribute. - * @return Returns ffrt_thrd_success if the condition variable is initialized; - returns ffrt_thrd_error otherwise. - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_cond_init(ffrt_cond_t* cond, const ffrt_condattr_t* attr); - -/** - * @brief Unblocks at least one of the threads that are blocked on a condition variable. - * - * @param cond Indicates a pointer to the condition variable. - * @return Returns ffrt_thrd_success if the thread is unblocked; - returns ffrt_thrd_error otherwise. - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_cond_signal(ffrt_cond_t* cond); - -/** - * @brief Unblocks all threads currently blocked on a condition variable. - * - * @param cond Indicates a pointer to the condition variable. - * @return Returns ffrt_thrd_success if the threads are unblocked; - returns ffrt_thrd_error otherwise. - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_cond_broadcast(ffrt_cond_t* cond); - -/** - * @brief Blocks the calling thread. - * - * @param cond Indicates a pointer to the condition variable. - * @param mutex Indicates a pointer to the mutex. - * @return Returns ffrt_thrd_success if the thread is unblocked after being blocked; - returns ffrt_thrd_error otherwise. - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_cond_wait(ffrt_cond_t* cond, ffrt_mutex_t* mutex); - -/** - * @brief Blocks the calling thread for a given duration. - * - * @param cond Indicates a pointer to the condition variable. - * @param mutex Indicates a pointer to the mutex. - * @param time_point Indicates the maximum duration that the thread is blocked. - * If ffrt_cond_signal or ffrt_cond_broadcast is not called to unblock the thread - * when the maximum duration reaches, the thread is automatically unblocked. - * @return Returns ffrt_thrd_success if the thread is unblocked after being blocked; - returns ffrt_thrd_timedout if the maximum duration reaches; - returns ffrt_thrd_error if the blocking fails. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_cond_timedwait(ffrt_cond_t* cond, ffrt_mutex_t* mutex, const struct timespec* time_point); - -/** - * @brief Destroys a condition variable. - * - * @param cond Indicates a pointer to the condition variable. - * @return Returns ffrt_thrd_success if the condition variable is destroyed; - returns ffrt_thrd_error otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_cond_destroy(ffrt_cond_t* cond); -#endif +/* + * Copyright (c) 2023 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. + */ + +/** + * @addtogroup Ffrt + * @{ + * + * @brief ffrt provides APIs. + * + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * + * @since 10 + */ + + /** + * @file condition_variable.h + * + * @brief Declares the condition variable interfaces in C. + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +#ifndef FFRT_API_C_CONDITION_VARIABLE_H +#define FFRT_API_C_CONDITION_VARIABLE_H +#include +#include "type_def.h" + +/** + * @brief Initializes a condition variable. + * + * @param cond Indicates a pointer to the condition variable. + * @param attr Indicates a pointer to the condition variable attribute. + * @return Returns ffrt_thrd_success if the condition variable is initialized; + returns ffrt_thrd_error otherwise. + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_cond_init(ffrt_cond_t* cond, const ffrt_condattr_t* attr); + +/** + * @brief Unblocks at least one of the threads that are blocked on a condition variable. + * + * @param cond Indicates a pointer to the condition variable. + * @return Returns ffrt_thrd_success if the thread is unblocked; + returns ffrt_thrd_error otherwise. + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_cond_signal(ffrt_cond_t* cond); + +/** + * @brief Unblocks all threads currently blocked on a condition variable. + * + * @param cond Indicates a pointer to the condition variable. + * @return Returns ffrt_thrd_success if the threads are unblocked; + returns ffrt_thrd_error otherwise. + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_cond_broadcast(ffrt_cond_t* cond); + +/** + * @brief Blocks the calling thread. + * + * @param cond Indicates a pointer to the condition variable. + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the thread is unblocked after being blocked; + returns ffrt_thrd_error otherwise. + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_cond_wait(ffrt_cond_t* cond, ffrt_mutex_t* mutex); + +/** + * @brief Blocks the calling thread for a given duration. + * + * @param cond Indicates a pointer to the condition variable. + * @param mutex Indicates a pointer to the mutex. + * @param time_point Indicates the maximum duration that the thread is blocked. + * If ffrt_cond_signal or ffrt_cond_broadcast is not called to unblock the thread + * when the maximum duration reaches, the thread is automatically unblocked. + * @return Returns ffrt_thrd_success if the thread is unblocked after being blocked; + returns ffrt_thrd_timedout if the maximum duration reaches; + returns ffrt_thrd_error if the blocking fails. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_cond_timedwait(ffrt_cond_t* cond, ffrt_mutex_t* mutex, const struct timespec* time_point); + +/** + * @brief Destroys a condition variable. + * + * @param cond Indicates a pointer to the condition variable. + * @return Returns ffrt_thrd_success if the condition variable is destroyed; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_cond_destroy(ffrt_cond_t* cond); +#endif diff --git a/resourceschedule/ffrt/c/mutex.h b/resourceschedule/ffrt/c/mutex.h index 27f483bb7..b914fd316 100644 --- a/resourceschedule/ffrt/c/mutex.h +++ b/resourceschedule/ffrt/c/mutex.h @@ -1,96 +1,96 @@ -/* - * Copyright (c) 2023 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. - */ - -/** - * @addtogroup Ffrt - * @{ - * - * @brief ffrt provides APIs. - * - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * - * @since 10 - */ - - /** - * @file mutex.h - * - * @brief Declares the mutex interfaces in C. - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -#ifndef FFRT_API_C_MUTEX_H -#define FFRT_API_C_MUTEX_H -#include "type_def.h" - -/** - * @brief Initializes a mutex. - * - * @param mutex Indicates a pointer to the mutex. - * @param attr Indicates a pointer to the mutex attribute. - * @return Returns ffrt_thrd_success if the mutex is initialized; - returns ffrt_thrd_error otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_mutex_init(ffrt_mutex_t* mutex, const ffrt_mutexattr_t* attr); - -/** - * @brief Locks a mutex. - * - * @param mutex Indicates a pointer to the mutex. - * @return Returns ffrt_thrd_success if the mutex is locked; - returns ffrt_thrd_error or blocks the calling thread otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_mutex_lock(ffrt_mutex_t* mutex); - -/** - * @brief Unlocks a mutex. - * - * @param mutex Indicates a pointer to the mutex. - * @return Returns ffrt_thrd_success if the mutex is unlocked; - returns ffrt_thrd_error otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_mutex_unlock(ffrt_mutex_t* mutex); - -/** - * @brief Attempts to lock a mutex. - * - * @param mutex Indicates a pointer to the mutex. - * @return Returns ffrt_thrd_success if the mutex is locked; - returns ffrt_thrd_error or ffrt_thrd_busy otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_mutex_trylock(ffrt_mutex_t* mutex); - -/** - * @brief Destroys a mutex. - * - * @param mutex Indicates a pointer to the mutex. - * @return Returns ffrt_thrd_success if the mutex is destroyed; - returns ffrt_thrd_error otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_mutex_destroy(ffrt_mutex_t* mutex); -#endif +/* + * Copyright (c) 2023 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. + */ + +/** + * @addtogroup Ffrt + * @{ + * + * @brief ffrt provides APIs. + * + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * + * @since 10 + */ + +/** + * @file mutex.h + * + * @brief Declares the mutex interfaces in C. + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +#ifndef FFRT_API_C_MUTEX_H +#define FFRT_API_C_MUTEX_H +#include "type_def.h" + +/** + * @brief Initializes a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @param attr Indicates a pointer to the mutex attribute. + * @return Returns ffrt_thrd_success if the mutex is initialized; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_mutex_init(ffrt_mutex_t* mutex, const ffrt_mutexattr_t* attr); + +/** + * @brief Locks a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the mutex is locked; + returns ffrt_thrd_error or blocks the calling thread otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_mutex_lock(ffrt_mutex_t* mutex); + +/** + * @brief Unlocks a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the mutex is unlocked; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_mutex_unlock(ffrt_mutex_t* mutex); + +/** + * @brief Attempts to lock a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the mutex is locked; + returns ffrt_thrd_error or ffrt_thrd_busy otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_mutex_trylock(ffrt_mutex_t* mutex); + +/** + * @brief Destroys a mutex. + * + * @param mutex Indicates a pointer to the mutex. + * @return Returns ffrt_thrd_success if the mutex is destroyed; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_mutex_destroy(ffrt_mutex_t* mutex); +#endif diff --git a/resourceschedule/ffrt/c/queue.h b/resourceschedule/ffrt/c/queue.h index 2691f8e08..0ee3d375a 100644 --- a/resourceschedule/ffrt/c/queue.h +++ b/resourceschedule/ffrt/c/queue.h @@ -1,192 +1,192 @@ -/* - * Copyright (c) 2023 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. - */ - -/** - * @addtogroup Ffrt - * @{ - * - * @brief ffrt provides APIs. - * - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * - * @since 10 - */ - -/** - * @file queue.h - * - * @brief Declares the queue interfaces in C. - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -#ifndef FFRT_API_C_QUEUE_H -#define FFRT_API_C_QUEUE_H - -#include "type_def.h" - -typedef enum { ffrt_queue_serial, ffrt_queue_max } ffrt_queue_type_t; -typedef void* ffrt_queue_t; - -/** - * @brief Initializes the queue attribute. - * - * @param attr Indicates a pointer to the queue attribute. - * @return Returns 0 if the queue attribute is initialized; - returns -1 otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_queue_attr_init(ffrt_queue_attr_t* attr); - -/** - * @brief Destroys a queue attribute. - * - * @param attr Indicates a pointer to the queue attribute. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_queue_attr_destroy(ffrt_queue_attr_t* attr); - -/** - * @brief Sets the QoS for a queue attribute. - * - * @param attr Indicates a pointer to the queue attribute. - * @param attr Indicates the QoS. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_queue_attr_set_qos(ffrt_queue_attr_t* attr, ffrt_qos_t qos); - -/** - * @brief Obtains the QoS of a queue attribute. - * - * @param attr Indicates a pointer to the queue attribute. - * @return Returns the QoS. - * @since 10 - * @version 1.0 - */ -FFRT_C_API ffrt_qos_t ffrt_queue_attr_get_qos(const ffrt_queue_attr_t* attr); - -/** - * @brief Set the serial queue task execution timeout. - * - * @param attr Serial Queue Property Pointer. - * @param timeout_us Serial queue task execution timeout. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_queue_attr_set_timeout(ffrt_queue_attr_t* attr, uint64_t timeout_us); - -/** - * @brief Get the serial queue task execution timeout. - * - * @param attr Serial Queue Property Pointer. - * @return Returns the serial queue task execution timeout. - * @since 10 - * @version 1.0 - */ -FFRT_C_API uint64_t ffrt_queue_attr_get_timeout(const ffrt_queue_attr_t* attr); - -/** - * @brief Set the serial queue timeout callback function. - * - * @param attr Serial Queue Property Pointer. - * @param f Serial queue timeout callback function. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_queue_attr_set_callback(ffrt_queue_attr_t* attr, ffrt_function_header_t* f); - -/** - * @brief Get the serial queue task timeout callback function. - * - * @param attr Serial Queue Property Pointer. - * @return Returns the serial queue task timeout callback function. - * @since 10 - * @version 1.0 - */ -FFRT_C_API ffrt_function_header_t* ffrt_queue_attr_get_callback(const ffrt_queue_attr_t* attr); - -/** - * @brief Creates a queue. - * - * @param type Indicates the queue type. - * @param name Indicates a pointer to the queue name. - * @param attr Indicates a pointer to the queue attribute. - * @return Returns a non-null queue handle if the queue is created; - returns a null pointer otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API ffrt_queue_t ffrt_queue_create(ffrt_queue_type_t type, const char* name, const ffrt_queue_attr_t* attr); - -/** - * @brief Destroys a queue. - * - * @param queue Indicates a queue handle. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_queue_destroy(ffrt_queue_t queue); - -/** - * @brief Submits a task to a queue. - * - * @param queue Indicates a queue handle. - * @param f Indicates a pointer to the task executor. - * @param attr Indicates a pointer to the task attribute. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_queue_submit(ffrt_queue_t queue, ffrt_function_header_t* f, const ffrt_task_attr_t* attr); - -/** - * @brief Submits a task to the queue, and obtains a task handle. - * - * @param queue Indicates a queue handle. - * @param f Indicates a pointer to the task executor. - * @param attr Indicates a pointer to the task attribute. - * @return Returns a non-null task handle if the task is submitted; - returns a null pointer otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API ffrt_task_handle_t ffrt_queue_submit_h( - ffrt_queue_t queue, ffrt_function_header_t* f, const ffrt_task_attr_t* attr); - -/** - * @brief Waits until a task in the queue is complete. - * - * @param handle Indicates a task handle. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_queue_wait(ffrt_task_handle_t handle); - -/** - * @brief Cancels a task in the queue. - * - * @param handle Indicates a task handle. - * @return Returns 0 if the task is canceled; - returns -1 otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_queue_cancel(ffrt_task_handle_t handle); - +/* + * Copyright (c) 2023 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. + */ + +/** + * @addtogroup Ffrt + * @{ + * + * @brief ffrt provides APIs. + * + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * + * @since 10 + */ + +/** + * @file queue.h + * + * @brief Declares the queue interfaces in C. + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +#ifndef FFRT_API_C_QUEUE_H +#define FFRT_API_C_QUEUE_H + +#include "type_def.h" + +typedef enum { ffrt_queue_serial, ffrt_queue_max } ffrt_queue_type_t; +typedef void* ffrt_queue_t; + +/** + * @brief Initializes the queue attribute. + * + * @param attr Indicates a pointer to the queue attribute. + * @return Returns 0 if the queue attribute is initialized; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_queue_attr_init(ffrt_queue_attr_t* attr); + +/** + * @brief Destroys a queue attribute. + * + * @param attr Indicates a pointer to the queue attribute. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_queue_attr_destroy(ffrt_queue_attr_t* attr); + +/** + * @brief Sets the QoS for a queue attribute. + * + * @param attr Indicates a pointer to the queue attribute. + * @param attr Indicates the QoS. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_queue_attr_set_qos(ffrt_queue_attr_t* attr, ffrt_qos_t qos); + +/** + * @brief Obtains the QoS of a queue attribute. + * + * @param attr Indicates a pointer to the queue attribute. + * @return Returns the QoS. + * @since 10 + * @version 1.0 + */ +FFRT_C_API ffrt_qos_t ffrt_queue_attr_get_qos(const ffrt_queue_attr_t* attr); + +/** + * @brief Set the serial queue task execution timeout. + * + * @param attr Serial Queue Property Pointer. + * @param timeout_us Serial queue task execution timeout. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_queue_attr_set_timeout(ffrt_queue_attr_t* attr, uint64_t timeout_us); + +/** + * @brief Get the serial queue task execution timeout. + * + * @param attr Serial Queue Property Pointer. + * @return Returns the serial queue task execution timeout. + * @since 10 + * @version 1.0 + */ +FFRT_C_API uint64_t ffrt_queue_attr_get_timeout(const ffrt_queue_attr_t* attr); + +/** + * @brief Set the serial queue timeout callback function. + * + * @param attr Serial Queue Property Pointer. + * @param f Serial queue timeout callback function. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_queue_attr_set_callback(ffrt_queue_attr_t* attr, ffrt_function_header_t* f); + +/** + * @brief Get the serial queue task timeout callback function. + * + * @param attr Serial Queue Property Pointer. + * @return Returns the serial queue task timeout callback function. + * @since 10 + * @version 1.0 + */ +FFRT_C_API ffrt_function_header_t* ffrt_queue_attr_get_callback(const ffrt_queue_attr_t* attr); + +/** + * @brief Creates a queue. + * + * @param type Indicates the queue type. + * @param name Indicates a pointer to the queue name. + * @param attr Indicates a pointer to the queue attribute. + * @return Returns a non-null queue handle if the queue is created; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API ffrt_queue_t ffrt_queue_create(ffrt_queue_type_t type, const char* name, const ffrt_queue_attr_t* attr); + +/** + * @brief Destroys a queue. + * + * @param queue Indicates a queue handle. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_queue_destroy(ffrt_queue_t queue); + +/** + * @brief Submits a task to a queue. + * + * @param queue Indicates a queue handle. + * @param f Indicates a pointer to the task executor. + * @param attr Indicates a pointer to the task attribute. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_queue_submit(ffrt_queue_t queue, ffrt_function_header_t* f, const ffrt_task_attr_t* attr); + +/** + * @brief Submits a task to the queue, and obtains a task handle. + * + * @param queue Indicates a queue handle. + * @param f Indicates a pointer to the task executor. + * @param attr Indicates a pointer to the task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API ffrt_task_handle_t ffrt_queue_submit_h( + ffrt_queue_t queue, ffrt_function_header_t* f, const ffrt_task_attr_t* attr); + +/** + * @brief Waits until a task in the queue is complete. + * + * @param handle Indicates a task handle. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_queue_wait(ffrt_task_handle_t handle); + +/** + * @brief Cancels a task in the queue. + * + * @param handle Indicates a task handle. + * @return Returns 0 if the task is canceled; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_queue_cancel(ffrt_task_handle_t handle); + #endif // FFRT_API_C_QUEUE_H \ No newline at end of file diff --git a/resourceschedule/ffrt/c/sleep.h b/resourceschedule/ffrt/c/sleep.h index ed2e47860..121ab7b73 100644 --- a/resourceschedule/ffrt/c/sleep.h +++ b/resourceschedule/ffrt/c/sleep.h @@ -1,59 +1,59 @@ -/* - * Copyright (c) 2023 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. - */ - -/** - * @addtogroup Ffrt - * @{ - * - * @brief ffrt provides APIs. - * - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * - * @since 10 - */ - -/** - * @file sleep.h - * - * @brief Declares the sleep and yield interfaces in C. - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -#ifndef FFRT_API_C_SLEEP_H -#define FFRT_API_C_SLEEP_H -#include "type_def.h" - -/** - * @brief Suspends the calling thread for a given duration. - * - * @param usec Indicates the duration that the calling thread is suspended, in microseconds. - * @return Returns ffrt_thrd_success if the thread is suspended; - returns ffrt_thrd_error otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_usleep(uint64_t usec); - -/** - * @brief Passes control to other tasks so that they can be executed. - * - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_yield(void); -#endif +/* + * Copyright (c) 2023 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. + */ + +/** + * @addtogroup Ffrt + * @{ + * + * @brief ffrt provides APIs. + * + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * + * @since 10 + */ + +/** + * @file sleep.h + * + * @brief Declares the sleep and yield interfaces in C. + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +#ifndef FFRT_API_C_SLEEP_H +#define FFRT_API_C_SLEEP_H +#include "type_def.h" + +/** + * @brief Suspends the calling thread for a given duration. + * + * @param usec Indicates the duration that the calling thread is suspended, in microseconds. + * @return Returns ffrt_thrd_success if the thread is suspended; + returns ffrt_thrd_error otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_usleep(uint64_t usec); + +/** + * @brief Passes control to other tasks so that they can be executed. + * + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_yield(void); +#endif diff --git a/resourceschedule/ffrt/c/task.h b/resourceschedule/ffrt/c/task.h index acbac9281..c6fd7f42c 100644 --- a/resourceschedule/ffrt/c/task.h +++ b/resourceschedule/ffrt/c/task.h @@ -1,204 +1,207 @@ -/* - * Copyright (c) 2023 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. - */ - -/** - * @addtogroup Ffrt - * @{ - * - * @brief ffrt provides APIs. - * - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * - * @since 10 - */ - - /** - * @file task.h - * - * @brief Declares the task interfaces in C. - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -#ifndef FFRT_API_C_TASK_H -#define FFRT_API_C_TASK_H -#include "type_def.h" - -/** - * @brief Initializes a task attribute. - * - * @param attr Indicates a pointer to the task attribute. - * @return Returns 0 if the task attribute is initialized; - returns -1 otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_task_attr_init(ffrt_task_attr_t* attr); - -/** - * @brief Sets a task name. - * - * @param attr Indicates a pointer to the task attribute. - * @param name Indicates a pointer to the task name. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_task_attr_set_name(ffrt_task_attr_t* attr, const char* name); - -/** - * @brief Obtains a task name. - * - * @param attr Indicates a pointer to the task attribute. - * @return Returns a non-null pointer to the task name if the name is obtained; - returns a null pointer otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API const char* ffrt_task_attr_get_name(const ffrt_task_attr_t* attr); - -/** - * @brief Destroys a task attribute. - * - * @param attr Indicates a pointer to the task attribute. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_task_attr_destroy(ffrt_task_attr_t* attr); - -/** - * @brief Sets the QoS for a task attribute. - * - * @param attr Indicates a pointer to the task attribute. - * @param qos Indicates the QoS. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_task_attr_set_qos(ffrt_task_attr_t* attr, ffrt_qos_t qos); - -/** - * @brief Obtains the QoS of a task attribute. - * - * @param attr Indicates a pointer to the task attribute. - * @return Returns the QoS, which is ffrt_qos_default by default. - * @since 10 - * @version 1.0 - */ -FFRT_C_API ffrt_qos_t ffrt_task_attr_get_qos(const ffrt_task_attr_t* attr); - -/** - * @brief Sets the task delay time. - * - * @param attr Indicates a pointer to the task attribute. - * @param delay_us Indicates the delay time, in microseconds. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_task_attr_set_delay(ffrt_task_attr_t* attr, uint64_t delay_us); - -/** - * @brief Obtains the task delay time. - * - * @param attr Indicates a pointer to the task attribute. - * @return Returns the delay time. - * @since 10 - * @version 1.0 - */ -FFRT_C_API uint64_t ffrt_task_attr_get_delay(const ffrt_task_attr_t* attr); -/** - * @brief Updates the QoS of this task. - * - * @param qos Indicates the new QoS. - * @return Returns 0 if the QoS is updated; - returns -1 otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API int ffrt_this_task_update_qos(ffrt_qos_t task_qos); -/** - * @brief Obtains the ID of this task. - * - * @return Returns the task ID. - * @since 10 - * @version 1.0 - */ -FFRT_C_API uint64_t ffrt_this_task_get_id(void); - -/** - * @brief Applies for memory for the function execution structure. - * - * @param kind Indicates the type of the function execution structure, which can be common or queue. - * @return Returns a non-null pointer if the memory is allocated; - returns a null pointer otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void *ffrt_alloc_auto_managed_function_storage_base(ffrt_function_kind_t kind); - -/** - * @brief Submits a task. - * - * @param f Indicates a pointer to the task executor. - * @param in_deps Indicates a pointer to the input dependencies. - * @param out_deps Indicates a pointer to the output dependencies. - * @param attr Indicates a pointer to the task attribute. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_submit_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, - const ffrt_task_attr_t* attr); - -/** - * @brief Submits a task, and obtains a task handle. - * - * @param f Indicates a pointer to the task executor. - * @param in_deps Indicates a pointer to the input dependencies. - * @param out_deps Indicates a pointer to the output dependencies. - * @param attr Indicates a pointer to the task attribute. - * @return Returns a non-null task handle if the task is submitted; - returns a null pointer otherwise. - * @since 10 - * @version 1.0 - */ -FFRT_C_API ffrt_task_handle_t ffrt_submit_h_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, - const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr); - -/** - * @brief Destroys a task handle. - * - * @param handle Indicates a task handle. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_task_handle_destroy(ffrt_task_handle_t handle); - -/** - * @brief Waits until the dependent tasks are complete. - * - * @param deps Indicates a pointer to the dependent tasks. - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_wait_deps(const ffrt_deps_t* deps); - -/** - * @brief Waits until all submitted tasks are complete. - * - * @since 10 - * @version 1.0 - */ -FFRT_C_API void ffrt_wait(void); -#endif +/* + * Copyright (c) 2023 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. + */ + +/** + * @addtogroup Ffrt + * @{ + * + * @brief ffrt provides APIs. + * + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * + * @since 10 + */ + + /** + * @file task.h + * + * @brief Declares the task interfaces in C. + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +#ifndef FFRT_API_C_TASK_H +#define FFRT_API_C_TASK_H +#include "type_def.h" + +/** + * @brief Initializes a task attribute. + * + * @param attr Indicates a pointer to the task attribute. + * @return Returns 0 if the task attribute is initialized; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_task_attr_init(ffrt_task_attr_t* attr); + +/** + * @brief Sets a task name. + * + * @param attr Indicates a pointer to the task attribute. + * @param name Indicates a pointer to the task name. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_task_attr_set_name(ffrt_task_attr_t* attr, const char* name); + +/** + * @brief Obtains a task name. + * + * @param attr Indicates a pointer to the task attribute. + * @return Returns a non-null pointer to the task name if the name is obtained; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API const char* ffrt_task_attr_get_name(const ffrt_task_attr_t* attr); + +/** + * @brief Destroys a task attribute. + * + * @param attr Indicates a pointer to the task attribute. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_task_attr_destroy(ffrt_task_attr_t* attr); + +/** + * @brief Sets the QoS for a task attribute. + * + * @param attr Indicates a pointer to the task attribute. + * @param qos Indicates the QoS. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_task_attr_set_qos(ffrt_task_attr_t* attr, ffrt_qos_t qos); + +/** + * @brief Obtains the QoS of a task attribute. + * + * @param attr Indicates a pointer to the task attribute. + * @return Returns the QoS, which is ffrt_qos_default by default. + * @since 10 + * @version 1.0 + */ +FFRT_C_API ffrt_qos_t ffrt_task_attr_get_qos(const ffrt_task_attr_t* attr); + +/** + * @brief Sets the task delay time. + * + * @param attr Indicates a pointer to the task attribute. + * @param delay_us Indicates the delay time, in microseconds. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_task_attr_set_delay(ffrt_task_attr_t* attr, uint64_t delay_us); + +/** + * @brief Obtains the task delay time. + * + * @param attr Indicates a pointer to the task attribute. + * @return Returns the delay time. + * @since 10 + * @version 1.0 + */ +FFRT_C_API uint64_t ffrt_task_attr_get_delay(const ffrt_task_attr_t* attr); + +/** + * @brief Updates the QoS of this task. + * + * @param qos Indicates the new QoS. + * @return Returns 0 if the QoS is updated; + returns -1 otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API int ffrt_this_task_update_qos(ffrt_qos_t qos); + +/** + * @brief Obtains the ID of this task. + * + * @return Returns the task ID. + * @since 10 + * @version 1.0 + */ +FFRT_C_API uint64_t ffrt_this_task_get_id(void); + +/** + * @brief Applies for memory for the function execution structure. + * + * @param kind Indicates the type of the function execution structure, which can be common or queue. + * @return Returns a non-null pointer if the memory is allocated; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void *ffrt_alloc_auto_managed_function_storage_base(ffrt_function_kind_t kind); + +/** + * @brief Submits a task. + * + * @param f Indicates a pointer to the task executor. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @param attr Indicates a pointer to the task attribute. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_submit_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, const ffrt_deps_t* out_deps, + const ffrt_task_attr_t* attr); + +/** + * @brief Submits a task, and obtains a task handle. + * + * @param f Indicates a pointer to the task executor. + * @param in_deps Indicates a pointer to the input dependencies. + * @param out_deps Indicates a pointer to the output dependencies. + * @param attr Indicates a pointer to the task attribute. + * @return Returns a non-null task handle if the task is submitted; + returns a null pointer otherwise. + * @since 10 + * @version 1.0 + */ +FFRT_C_API ffrt_task_handle_t ffrt_submit_h_base(ffrt_function_header_t* f, const ffrt_deps_t* in_deps, + const ffrt_deps_t* out_deps, const ffrt_task_attr_t* attr); + +/** + * @brief Destroys a task handle. + * + * @param handle Indicates a task handle. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_task_handle_destroy(ffrt_task_handle_t handle); + +/** + * @brief Waits until the dependent tasks are complete. + * + * @param deps Indicates a pointer to the dependent tasks. + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_wait_deps(const ffrt_deps_t* deps); + +/** + * @brief Waits until all submitted tasks are complete. + * + * @since 10 + * @version 1.0 + */ +FFRT_C_API void ffrt_wait(void); + +#endif diff --git a/resourceschedule/ffrt/c/type_def.h b/resourceschedule/ffrt/c/type_def.h index 7cc4798a9..1cedf23b9 100644 --- a/resourceschedule/ffrt/c/type_def.h +++ b/resourceschedule/ffrt/c/type_def.h @@ -1,175 +1,189 @@ -/* - * Copyright (c) 2023 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. - */ - -/** - * @addtogroup Ffrt - * @{ - * - * @brief ffrt provides APIs. - * - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * - * @since 10 - */ - - /** - * @file type_def.h - * - * @brief Declares common types. - * - * @syscap SystemCapability.Resourceschedule.Ffrt.Core - * @since 10 - * @version 1.0 - */ -#ifndef FFRT_API_C_TYPE_DEF_H -#define FFRT_API_C_TYPE_DEF_H -#include -#include - -#ifdef __cplusplus -#define FFRT_C_API extern "C" -#else -#define FFRT_C_API -#endif - -/** - * @brief Enumerates the task QoS types. - * - */ -typedef enum { - ffrt_qos_inherit = -1, - /** Background task. */ - ffrt_qos_background, - /** Real-time tool. */ - ffrt_qos_utility, - /** Default type. */ - ffrt_qos_default, - /** User initiated. */ - ffrt_qos_user_initiated, -} ffrt_qos_default_t; -typedef int ffrt_qos_t; - -typedef void(*ffrt_function_t)(void*); - -/** - * @brief Defines a task executor. - * - */ -typedef struct { - /** Function used to execute a task. */ - ffrt_function_t exec; - /** Function used to destroy a task. */ - ffrt_function_t destroy; - uint64_t reserve[2]; -} ffrt_function_header_t; - -/** - * @brief Defines the storage size of multiple types of structs. - * - */ -typedef enum { - /** Task attribute storage size. */ - ffrt_task_attr_storage_size = 128, - /** Task executor storage size. */ - ffrt_auto_managed_function_storage_size = 64 + sizeof(ffrt_function_header_t), - /* Mutex storage size. */ - ffrt_mutex_storage_size = 64, - /** Condition variable storage size. */ - ffrt_cond_storage_size = 64, - /** Queue storage size. */ - ffrt_queue_attr_storage_size = 128, -} ffrt_storage_size_t; - -/** - * @brief Enumerates the task types. - * - */ -typedef enum { - /** General task. */ - ffrt_function_kind_general, - /** Queue task. */ - ffrt_function_kind_queue -} ffrt_function_kind_t; - -typedef enum { - ffrt_dependence_data, - ffrt_dependence_task, -} ffrt_dependence_type_t; - -typedef struct { - ffrt_dependence_type_t type; - const void* ptr; -} ffrt_dependence_t; - -/** - * @brief Defines the dependency struct. - * - */ -typedef struct { - /** Number of dependencies. */ - uint32_t len; - /** Dependent data. */ - const ffrt_dependence_t* items; -} ffrt_deps_t; - -typedef struct { - uint32_t storage[(ffrt_task_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; -} ffrt_task_attr_t; - -typedef struct { - uint32_t storage[(ffrt_queue_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; -} ffrt_queue_attr_t; - -typedef void* ffrt_task_handle_t; - -typedef enum { - ffrt_error = -1, - ffrt_success = 0, - ffrt_error_nomem = ENOMEM, - ffrt_error_timedout = ETIMEDOUT, - ffrt_error_busy = EBUSY, - ffrt_error_inval = EINVAL -} ffrt_error_t; - -typedef struct { - long storage; -} ffrt_condattr_t; - -typedef struct { - long storage; -} ffrt_mutexattr_t; - -typedef struct { - uint32_t storage[(ffrt_mutex_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; -} ffrt_mutex_t; - -typedef struct { - uint32_t storage[(ffrt_cond_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; -} ffrt_cond_t; - -#ifdef __cplusplus -namespace ffrt { -enum qos_default { - qos_inherit = ffrt_qos_inherit, - qos_background = ffrt_qos_background, - qos_utility = ffrt_qos_utility, - qos_default = ffrt_qos_default, - qos_user_initiated = ffrt_qos_user_initiated, -}; -using qos = int; -} -#endif -#endif +/* + * Copyright (c) 2023 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. + */ + +/** + * @addtogroup Ffrt + * @{ + * + * @brief ffrt provides APIs. + * + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * + * @since 10 + */ + + /** + * @file type_def.h + * + * @brief Declares common types. + * + * @syscap SystemCapability.Resourceschedule.Ffrt.Core + * @since 10 + * @version 1.0 + */ +#ifndef FFRT_API_C_TYPE_DEF_H +#define FFRT_API_C_TYPE_DEF_H +#include +#include + +#ifdef __cplusplus +#define FFRT_C_API extern "C" +#else +#define FFRT_C_API +#endif + +/** + * @brief Enumerates the task QoS types. + * + */ +typedef enum { + /** Inheritance. */ + ffrt_qos_inherit = -1, + /** Background task. */ + ffrt_qos_background, + /** Real-time tool. */ + ffrt_qos_utility, + /** Default type. */ + ffrt_qos_default, + /** User initiated. */ + ffrt_qos_user_initiated, +} ffrt_qos_default_t; +typedef int ffrt_qos_t; + +typedef void(*ffrt_function_t)(void*); + +/** + * @brief Defines a task executor. + * + */ +typedef struct { + /** Function used to execute a task. */ + ffrt_function_t exec; + /** Function used to destroy a task. */ + ffrt_function_t destroy; + /** Need to be set to 0. */ + uint64_t reserve[2]; +} ffrt_function_header_t; + +/** + * @brief Defines the storage size of multiple types of structs. + * + */ +typedef enum { + /** Task attribute storage size. */ + ffrt_task_attr_storage_size = 128, + /** Task executor storage size. */ + ffrt_auto_managed_function_storage_size = 64 + sizeof(ffrt_function_header_t), + /* Mutex storage size. */ + ffrt_mutex_storage_size = 64, + /** Condition variable storage size. */ + ffrt_cond_storage_size = 64, + /** Queue storage size. */ + ffrt_queue_attr_storage_size = 128, +} ffrt_storage_size_t; + +/** + * @brief Enumerates the task types. + * + */ +typedef enum { + /** General task. */ + ffrt_function_kind_general, + /** Queue task. */ + ffrt_function_kind_queue +} ffrt_function_kind_t; + +/** + * @brief dependency type. + * + */ +typedef enum { + /** Data dependency type. */ + ffrt_dependence_data, + /** Task dependency type. */ + ffrt_dependence_task, +} ffrt_dependence_type_t; + +/** + * @brief dependency data structure. + * + */ +typedef struct { + /** Dependency type. */ + ffrt_dependence_type_t type; + /** Dependency pointer. */ + const void* ptr; +} ffrt_dependence_t; + +/** + * @brief Defines the dependency struct. + * + */ +typedef struct { + /** Number of dependencies. */ + uint32_t len; + /** Dependent data. */ + const ffrt_dependence_t* items; +} ffrt_deps_t; + +typedef struct { + uint32_t storage[(ffrt_task_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; +} ffrt_task_attr_t; + +typedef struct { + uint32_t storage[(ffrt_queue_attr_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; +} ffrt_queue_attr_t; + +typedef void* ffrt_task_handle_t; + +typedef enum { + ffrt_error = -1, + ffrt_success = 0, + ffrt_error_nomem = ENOMEM, + ffrt_error_timedout = ETIMEDOUT, + ffrt_error_busy = EBUSY, + ffrt_error_inval = EINVAL +} ffrt_error_t; + +typedef struct { + long storage; +} ffrt_condattr_t; + +typedef struct { + long storage; +} ffrt_mutexattr_t; + +typedef struct { + uint32_t storage[(ffrt_mutex_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; +} ffrt_mutex_t; + +typedef struct { + uint32_t storage[(ffrt_cond_storage_size + sizeof(uint32_t) - 1) / sizeof(uint32_t)]; +} ffrt_cond_t; + +#ifdef __cplusplus +namespace ffrt { +enum qos_default { + qos_inherit = ffrt_qos_inherit, + qos_background = ffrt_qos_background, + qos_utility = ffrt_qos_utility, + qos_default = ffrt_qos_default, + qos_user_initiated = ffrt_qos_user_initiated, +}; +using qos = int; +} +#endif +#endif diff --git a/security/huks/src/native_huks_api.c b/security/huks/src/native_huks_api.c deleted file mode 100644 index 2a6ab5cd2..000000000 --- a/security/huks/src/native_huks_api.c +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -#include "native_huks_api.h" - -#include "hks_api.h" -#include "hks_errcode_adapter.h" -#include "native_huks_api_adapter.h" - -static struct OH_Huks_Result ConvertApiResult(int32_t ret) -{ - struct HksResult result = HksConvertErrCode(ret); - return *((struct OH_Huks_Result *)(&result)); -} - -struct OH_Huks_Result OH_Huks_GetSdkVersion(struct OH_Huks_Blob *sdkVersion) -{ - int32_t result = HksGetSdkVersion((struct HksBlob *) sdkVersion); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_GenerateKeyItem(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *paramSetIn, struct OH_Huks_ParamSet *paramSetOut) -{ - int32_t result = HksGenerateKey((const struct HksBlob *) keyAlias, - (const struct HksParamSet *) paramSetIn, (struct HksParamSet *) paramSetOut); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_ImportKeyItem(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *key) -{ - int32_t result = HksImportKey((const struct HksBlob *) keyAlias, - (const struct HksParamSet *) paramSet, (const struct HksBlob *) key); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_ImportWrappedKeyItem(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_Blob *wrappingKeyAlias, const struct OH_Huks_ParamSet *paramSet, - const struct OH_Huks_Blob *wrappedKeyData) -{ - int32_t result = HksImportWrappedKey((const struct HksBlob *) keyAlias, - (const struct HksBlob *) wrappingKeyAlias, (const struct HksParamSet *) paramSet, - (const struct HksBlob *) wrappedKeyData); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_ExportPublicKeyItem(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_Blob *key) -{ - int32_t result = HksExportPublicKey((const struct HksBlob *) keyAlias, - (const struct HksParamSet *) paramSet, (struct HksBlob *) key); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_DeleteKeyItem(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *paramSet) -{ - int32_t result = HksDeleteKey((const struct HksBlob *) keyAlias, (const struct HksParamSet *) paramSet); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_GetKeyItemParamSet(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *paramSetIn, struct OH_Huks_ParamSet *paramSetOut) -{ - int32_t result = HksGetKeyParamSet((const struct HksBlob *) keyAlias, - (const struct HksParamSet *) paramSetIn, (struct HksParamSet *) paramSetOut); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_IsKeyItemExist(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *paramSet) -{ - int32_t result = HksKeyExist((const struct HksBlob *) keyAlias, (const struct HksParamSet *) paramSet); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_AttestKeyItem(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_CertChain *certChain) -{ - int32_t result = HuksAttestAdapter(keyAlias, paramSet, certChain); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_InitSession(const struct OH_Huks_Blob *keyAlias, - const struct OH_Huks_ParamSet *paramSet, struct OH_Huks_Blob *handle, struct OH_Huks_Blob *token) -{ - int32_t result = HksInit((const struct HksBlob *) keyAlias, - (const struct HksParamSet *) paramSet, (struct HksBlob *) handle, (struct HksBlob *) token); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_UpdateSession(const struct OH_Huks_Blob *handle, - const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData) -{ - int32_t result = HksUpdate((const struct HksBlob *) handle, - (const struct HksParamSet *) paramSet, (const struct HksBlob *) inData, (struct HksBlob *) outData); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_FinishSession(const struct OH_Huks_Blob *handle, - const struct OH_Huks_ParamSet *paramSet, const struct OH_Huks_Blob *inData, struct OH_Huks_Blob *outData) -{ - int32_t result = HksFinish((const struct HksBlob *) handle, - (const struct HksParamSet *) paramSet, (const struct HksBlob *) inData, (struct HksBlob *) outData); - return ConvertApiResult(result); -} - -struct OH_Huks_Result OH_Huks_AbortSession(const struct OH_Huks_Blob *handle, - const struct OH_Huks_ParamSet *paramSet) -{ - int32_t result = HksAbort((const struct HksBlob *) handle, (const struct HksParamSet *) paramSet); - return ConvertApiResult(result); -} diff --git a/security/huks/src/native_huks_api_adapter.c b/security/huks/src/native_huks_api_adapter.c deleted file mode 100644 index 792b6b50e..000000000 --- a/security/huks/src/native_huks_api_adapter.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -#include "hks_api.h" -#include "hks_param.h" - -#include "native_huks_api_adapter.h" -#include "native_huks_param.h" - -int32_t HuksAttestAdapter(const struct OH_Huks_Blob *keyAlias, const struct OH_Huks_ParamSet *paramSet, - struct OH_Huks_CertChain *certChain) -{ - int32_t ret; - struct HksParamSet *newParamSet = NULL; - do { - if (paramSet == NULL) { - ret = HKS_ERROR_NULL_POINTER; - break; - } - ret = HksCheckParamSet((struct HksParamSet *)paramSet, paramSet->paramSetSize); - if (ret != HKS_SUCCESS) { - break; - } - ret = HksInitParamSet(&newParamSet); - if (ret != HKS_SUCCESS) { - break; - } - ret = HksFreshParamSet((struct HksParamSet *)paramSet, false); - if (ret != HKS_SUCCESS) { - break; - } - ret = HksAddParams(newParamSet, (const struct HksParam *)paramSet->params, paramSet->paramsCnt); - if (ret != HKS_SUCCESS) { - break; - } - struct HksParam isBase64Param = { .tag = HKS_TAG_ATTESTATION_BASE64, .boolParam = true }; - ret = HksAddParams(newParamSet, &isBase64Param, 1); - if (ret != HKS_SUCCESS) { - break; - } - ret = HksBuildParamSet(&newParamSet); - if (ret != HKS_SUCCESS) { - break; - } - ret = HksAttestKey((const struct HksBlob *)keyAlias, (struct HksParamSet *)newParamSet, - (struct HksCertChain *)certChain); - } while (0); - HksFreeParamSet(&newParamSet); - return ret; -} \ No newline at end of file diff --git a/security/huks/src/native_huks_param.c b/security/huks/src/native_huks_param.c deleted file mode 100644 index 9fab8b6c4..000000000 --- a/security/huks/src/native_huks_param.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2022 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. - */ - -#include "native_huks_param.h" - -#include "hks_param.h" -#include "hks_errcode_adapter.h" - -static struct OH_Huks_Result ConvertParamResult(int32_t ret) -{ - struct HksResult result = HksConvertErrCode(ret); - return *((struct OH_Huks_Result *)(&result)); -} - -struct OH_Huks_Result OH_Huks_InitParamSet(struct OH_Huks_ParamSet **paramSet) -{ - int32_t result = HksInitParamSet((struct HksParamSet **) paramSet); - return ConvertParamResult(result); -} - -struct OH_Huks_Result OH_Huks_AddParams(struct OH_Huks_ParamSet *paramSet, - const struct OH_Huks_Param *params, uint32_t paramCnt) -{ - int32_t result = HksAddParams((struct HksParamSet *) paramSet, - (const struct HksParam *) params, paramCnt); - return ConvertParamResult(result); -} - -struct OH_Huks_Result OH_Huks_BuildParamSet(struct OH_Huks_ParamSet **paramSet) -{ - int32_t result = HksBuildParamSet((struct HksParamSet **) paramSet); - return ConvertParamResult(result); -} - -void OH_Huks_FreeParamSet(struct OH_Huks_ParamSet **paramSet) -{ - HksFreeParamSet((struct HksParamSet **) paramSet); -} - -struct OH_Huks_Result OH_Huks_CopyParamSet(const struct OH_Huks_ParamSet *fromParamSet, - uint32_t fromParamSetSize, struct OH_Huks_ParamSet **paramSet) -{ - int32_t result = HksGetParamSet((const struct HksParamSet *) fromParamSet, - fromParamSetSize, (struct HksParamSet **) paramSet); - return ConvertParamResult(result); -} - -struct OH_Huks_Result OH_Huks_GetParam(const struct OH_Huks_ParamSet *paramSet, uint32_t tag, - struct OH_Huks_Param **param) -{ - int32_t result = HksGetParam((const struct HksParamSet *) paramSet, tag, (struct HksParam **) param); - return ConvertParamResult(result); -} - -struct OH_Huks_Result OH_Huks_FreshParamSet(struct OH_Huks_ParamSet *paramSet, bool isCopy) -{ - int32_t result = HksFreshParamSet((struct HksParamSet *) paramSet, isCopy); - return ConvertParamResult(result); -} - -struct OH_Huks_Result OH_Huks_IsParamSetTagValid(const struct OH_Huks_ParamSet *paramSet) -{ - int32_t result = HksCheckParamSetTag((const struct HksParamSet *) paramSet); - return ConvertParamResult(result); -} - -struct OH_Huks_Result OH_Huks_IsParamSetValid(const struct OH_Huks_ParamSet *paramSet, uint32_t size) -{ - int32_t result = HksCheckParamSet((const struct HksParamSet *) paramSet, size); - return ConvertParamResult(result); -} - -struct OH_Huks_Result OH_Huks_CheckParamMatch(const struct OH_Huks_Param *baseParam, const struct OH_Huks_Param *param) -{ - int32_t result = HksCheckParamMatch((const struct HksParam *) baseParam, (const struct HksParam *) param); - return ConvertParamResult(result); -}