From 8d5776f06a3e5f806f362e3c8dbf3235218d4f07 Mon Sep 17 00:00:00 2001 From: yudechen Date: Tue, 12 Apr 2022 10:19:40 +0800 Subject: [PATCH] add two napi. Signed-off-by: yudechen Change-Id: Ie9cf8c444ce36af4603ee42669e4796a40b64db9 --- BUILD.gn | 21 +++++++- interfaces/inner_api/syscap_interface.c | 67 +++++++++++++++++++++++++ interfaces/inner_api/syscap_interface.h | 48 ++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 interfaces/inner_api/syscap_interface.c create mode 100644 interfaces/inner_api/syscap_interface.h diff --git a/BUILD.gn b/BUILD.gn index 12f7bad..5af0dc9 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -92,6 +92,25 @@ ohos_shared_library("syscap_tool_shared") { part_name = "syscap_codec" } +ohos_shared_library("syscap_interface_shared") { + include_dirs = [ "./interfaces/inner_api/include" ] + sources = [ "./interfaces/inner_api/syscap_interface.c" ] + + deps = [ "//third_party/bounds_checking_function:libsec_static" ] + + if (defined(ohos_lite)) { + deps += [ "//build/lite/config/component/cJSON:cjson_static" ] + } else { + deps += [ "//third_party/cJSON:cjson_static" ] + } + + subsystem_name = "developtools" + part_name = "syscap_codec" +} + group("syscap_codec") { - deps = [ ":syscap_tool_shared" ] + deps = [ + ":syscap_interface_shared", + ":syscap_tool_shared", + ] } diff --git a/interfaces/inner_api/syscap_interface.c b/interfaces/inner_api/syscap_interface.c new file mode 100644 index 0000000..8b239c2 --- /dev/null +++ b/interfaces/inner_api/syscap_interface.c @@ -0,0 +1,67 @@ +/* + * Copyright (C) 2022-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 +#include +#include +#include +#include +#include +#include "syscap_interface.h" + +#define PCID_OUT_BUFFER 32 +#define MAX_SYSCAP_STR_LEN 128 + +#define PRINT_ERR(...) \ + do { \ + printf("ERROR: in file %s at line %d -> ", __FILE__, __LINE__); \ + printf(__VA_ARGS__); \ + } while (0) + +bool EncodeOsSyscap(int output[32]) +{ + uint8_t *outputArray = (uint8_t *)malloc(sizeof(int) * PCID_OUT_BUFFER); + if (outputArray == NULL) { + PRINT_ERR("malloc failed."); + return false; + } + (void)memset_s(outputArray, sizeof(int) * PCID_OUT_BUFFER, 0, sizeof(int) * PCID_OUT_BUFFER); + + uint16_t countBytes = PCID_OUT_BUFFER * sizeof(int); + for (uint16_t i = 0; i < countBytes; i++) { + outputArray[i] |= 0XFF; + } + int ret = memcpy_s(output, sizeof(int) * PCID_OUT_BUFFER, outputArray, sizeof(int) * PCID_OUT_BUFFER); + if (ret != 0) { + PRINT_ERR("memcpy_s failed."); + free(outputArray); + return false; + } + free(outputArray); + return true; +} + +bool EncodePrivateSyscap(char *output, int *outputLen) +{ + static char syscapStr[MAX_SYSCAP_STR_LEN] = "Systemcapability.Ai.AiEngine"; + int ret = strcpy_s(output, MAX_SYSCAP_STR_LEN, syscapStr); + if (ret != 0) { + PRINT_ERR("strcpy_s failed."); + return false; + } + *outputLen = strlen(syscapStr); + + return true; +} \ No newline at end of file diff --git a/interfaces/inner_api/syscap_interface.h b/interfaces/inner_api/syscap_interface.h new file mode 100644 index 0000000..1649a96 --- /dev/null +++ b/interfaces/inner_api/syscap_interface.h @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2022-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. + */ + +#ifndef _SYSCAP_INTERFACE_H +#define _SYSCAP_INTERFACE_H + +#include +#include + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +typedef struct ProductCompatibilityIDHead { + uint16_t apiVersion : 15; + uint16_t apiVersionType : 1; + uint16_t systemType : 3; + uint16_t reserved : 13; + uint32_t manufacturerID; +} PCIDHead; // to do + + +bool EncodeOsSyscap(int output[32]); +bool DecodeOsSyscap(int input[32], char **output, int *outputCnt, int** outputLen); +bool EncodePrivateSyscap(char *output, int *outputLen); +bool DecodePrivateSyscap(char *input, int inputLen, char *output, int *outputCnt, int **outputLen); + +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ + +#endif /* _SYSCAP_INTERFACE_H */ \ No newline at end of file -- Gitee