diff --git a/camera_hdf/hdi_impl/BUILD.gn b/camera_hdf/hdi_impl/BUILD.gn index bd015647ae621a705ae6261d33ef7e9418159893..a33bd3b367860cf8b8832531a07319fde3527d4f 100644 --- a/camera_hdf/hdi_impl/BUILD.gn +++ b/camera_hdf/hdi_impl/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -31,12 +31,6 @@ ohos_shared_library("distributed_camera_hdf") { "../interfaces/hdi_ipc/server/provider", "//utils/native/base/include", "//utils/system/safwk/native/include", - "${common_path}/include/utils", - "${common_path}/include/constants", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include/", - "${fwk_utils_path}/include", - "${fwk_utils_path}/include/log", "${display_hdf_path}/interfaces/include", "${hdf_framework_path}/include/utils", "${hdf_framework_path}/include/core", @@ -77,12 +71,12 @@ ohos_shared_library("distributed_camera_hdf") { "src/dstream_operator/dimage_buffer.cpp", "src/dstream_operator/doffline_stream_operator.cpp", "src/dstream_operator/dstream_operator.cpp", + "src/utils/anonymous_string.cpp", "src/utils/dcamera.cpp", + "src/utils/dh_log.cpp", ] deps = [ - "${common_path}:distributed_camera_utils", - "${fwk_utils_path}:distributedhardwareutils", "//drivers/adapter/uhdf2/ipc:libhdf_ipc_adapter", "//drivers/peripheral/camera/interfaces/metadata:metadata", "//drivers/peripheral/display/hal:hdi_display_gralloc", diff --git a/camera_hdf/hdi_impl/include/dstream_operator/dimage_buffer.h b/camera_hdf/hdi_impl/include/dstream_operator/dimage_buffer.h index 101343790fb0364ffdc79abc4d1353205a4fec2f..207e4c440d0b8c446245356aac205ba72f95eef1 100644 --- a/camera_hdf/hdi_impl/include/dstream_operator/dimage_buffer.h +++ b/camera_hdf/hdi_impl/include/dstream_operator/dimage_buffer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -18,7 +18,6 @@ #include #include "constants.h" -#include "distributed_camera_constants.h" namespace OHOS { namespace DistributedHardware { diff --git a/camera_hdf/hdi_impl/include/utils/anonymous_string.h b/camera_hdf/hdi_impl/include/utils/anonymous_string.h new file mode 100644 index 0000000000000000000000000000000000000000..8cbfaaaa59bd85db986c8a23da870941f4c5e016 --- /dev/null +++ b/camera_hdf/hdi_impl/include/utils/anonymous_string.h @@ -0,0 +1,27 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_CAMERA_ANONYMOUS_STRING_H +#define OHOS_DISTRIBUTED_CAMERA_ANONYMOUS_STRING_H + +#include + +namespace OHOS { +namespace DistributedHardware { +std::string GetAnonyString(const std::string &value); +std::string GetAnonyInt32(const int32_t value); +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_CAMERA_ANONYMOUS_STRING_H diff --git a/camera_hdf/hdi_impl/include/utils/constants.h b/camera_hdf/hdi_impl/include/utils/constants.h index 818115cbe62fa22659e4a5eb6c36ca1404208ab9..fd3b6928217b82485a900638dca0af70f711472d 100644 --- a/camera_hdf/hdi_impl/include/utils/constants.h +++ b/camera_hdf/hdi_impl/include/utils/constants.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -54,6 +54,36 @@ const uint32_t WAIT_OPEN_TIMEOUT_SEC = 5; const std::string ENCODE_TYPE_STR_H264 = "OMX_hisi_video_encoder_avc"; const std::string ENCODE_TYPE_STR_H265 = "OMX_hisi_video_encoder_hevc"; const std::string ENCODE_TYPE_STR_JPEG = "jpeg"; +const std::string DH_LOG_TITLE_TAG = "DHFWK"; +constexpr int32_t LOG_MAX_LEN = 4096; + +typedef enum { + OHOS_CAMERA_FORMAT_INVALID = 0, + OHOS_CAMERA_FORMAT_RGBA_8888, + OHOS_CAMERA_FORMAT_YCBCR_420_888, + OHOS_CAMERA_FORMAT_YCRCB_420_SP, + OHOS_CAMERA_FORMAT_JPEG, +} DCameraFormat; + +typedef enum { + DCAMERA_MESSAGE = 0, + DCAMERA_OPERATION = 1, +} DCameraEventType; + +typedef enum { + DCAMERA_EVENT_CHANNEL_DISCONNECTED = 0, + DCAMERA_EVENT_CHANNEL_CONNECTED = 1, + DCAMERA_EVENT_CAMERA_SUCCESS = 2, + + DCAMERA_EVENT_CAMERA_ERROR = -1, + DCAMERA_EVENT_OPEN_CHANNEL_ERROR = -2, + DCAMERA_EVENT_CLOSE_CHANNEL_ERROR = -3, + DCAMERA_EVENT_CONFIG_STREAMS_ERROR = -4, + DCAMERA_EVENT_RELEASE_STREAMS_ERROR = -5, + DCAMERA_EVENT_START_CAPTURE_ERROR = -6, + DCAMERA_EVENT_STOP_CAPTURE_ERROR = -7, + DCAMERA_EVENT_UPDATE_SETTINGS_ERROR = -8, +} DCameraEventResult; enum DCameraBufferUsage : uint64_t { CAMERA_USAGE_SW_READ_OFTEN = (1 << 0), diff --git a/camera_hdf/hdi_impl/include/utils/dcamera.h b/camera_hdf/hdi_impl/include/utils/dcamera.h index 40ce77aa696036bfacfe3ea04b719d0f49e23e13..af8b610ea116411f2ea8ec4cf12cdf466044a43f 100644 --- a/camera_hdf/hdi_impl/include/utils/dcamera.h +++ b/camera_hdf/hdi_impl/include/utils/dcamera.h @@ -24,6 +24,7 @@ namespace DistributedHardware { using namespace OHOS::Camera; using RetCode = uint32_t; using MetaType = int32_t; +const std::string BASE_64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; CamRetCode MapToExternalRetCode(DCamRetCode retCode); @@ -32,6 +33,12 @@ DCamRetCode MapToInternalRetCode(CamRetCode retCode); uint64_t GetCurrentLocalTimeStamp(); void SplitString(const std::string &str, std::vector &tokens, const std::string &delimiters); + +std::string Base64Encode(const unsigned char *toEncode, unsigned int len); + +std::string Base64Decode(const std::string& basicString); + +bool IsBase64(unsigned char c); } // namespace DistributedHardware } // namespace OHOS #endif // DISTRIBUTED_CAMERA_H diff --git a/camera_hdf/hdi_impl/include/utils/dh_log.h b/camera_hdf/hdi_impl/include/utils/dh_log.h new file mode 100644 index 0000000000000000000000000000000000000000..6a8e38014564dce6b3fbf55f023bd9dc6632be1c --- /dev/null +++ b/camera_hdf/hdi_impl/include/utils/dh_log.h @@ -0,0 +1,43 @@ +/* + * 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. + */ + +#ifndef OHOS_DCAMERA_LOG_H +#define OHOS_DCAMERA_LOG_H + +namespace OHOS { +namespace DistributedHardware { +typedef enum { + DH_LOG_DEBUG, + DH_LOG_INFO, + DH_LOG_WARN, + DH_LOG_ERROR, +} DHLogLevel; + +void DHLog(DHLogLevel logLevel, const char *fmt, ...); + +#define ULOGD(fmt, ...) DHLog(DH_LOG_DEBUG, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define ULOGI(fmt, ...) DHLog(DH_LOG_INFO, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define ULOGW(fmt, ...) DHLog(DH_LOG_WARN, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define ULOGE(fmt, ...) DHLog(DH_LOG_ERROR, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DCAMERA_LOG_H diff --git a/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h b/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h new file mode 100644 index 0000000000000000000000000000000000000000..d7e1c1ee1cdc7897263df65212abe49685e8e796 --- /dev/null +++ b/camera_hdf/hdi_impl/include/utils/distributed_hardware_log.h @@ -0,0 +1,38 @@ +/* + * 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. + */ + +#ifndef OHOS_DISTRIBUTED_CAMERA_LOG_H +#define OHOS_DISTRIBUTED_CAMERA_LOG_H + +#include + +#include "dh_log.h" + +namespace OHOS { +namespace DistributedHardware { +#define DHLOGD(fmt, ...) DHLog(DH_LOG_DEBUG, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define DHLOGI(fmt, ...) DHLog(DH_LOG_INFO, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define DHLOGW(fmt, ...) DHLog(DH_LOG_WARN, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) + +#define DHLOGE(fmt, ...) DHLog(DH_LOG_ERROR, \ + (std::string("[") + DH_LOG_TAG + "][" + __FUNCTION__ + "]:" + fmt).c_str(), ##__VA_ARGS__) +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DISTRIBUTED_CAMERA_LOG_H diff --git a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp index 490aad110c9753a574d0c8c8009dc347a7d070b1..c198d35d5dc83748b77ceb247edaa3f2925e39fd 100644 --- a/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp +++ b/camera_hdf/hdi_impl/src/dcamera_device/dcamera_device.cpp @@ -18,9 +18,10 @@ #include #include #include "anonymous_string.h" +#include "constants.h" +#include "dcamera.h" #include "dcamera_host.h" #include "dcamera_provider.h" -#include "dcamera_utils_tools.h" #include "distributed_hardware_log.h" #include "metadata_utils.h" diff --git a/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp b/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp index aaf8aa350288e5456462345df1c59d20528aa608..82fbd581c8364d2ea5477f7649136ebc703784d3 100644 --- a/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp +++ b/camera_hdf/hdi_impl/src/dcamera_device/dmetadata_processor.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -18,7 +18,7 @@ #include #include "dbuffer_manager.h" -#include "dcamera_utils_tools.h" +#include "dcamera.h" #include "distributed_hardware_log.h" #include "json/json.h" #include "metadata_utils.h" diff --git a/camera_hdf/hdi_impl/src/dstream_operator/dbuffer_manager.cpp b/camera_hdf/hdi_impl/src/dstream_operator/dbuffer_manager.cpp index 0b7e38d6dcedd067dba9f982fc773a236e764b28..0ab0ef89566ca36766e80f78c213a54387842720 100644 --- a/camera_hdf/hdi_impl/src/dstream_operator/dbuffer_manager.cpp +++ b/camera_hdf/hdi_impl/src/dstream_operator/dbuffer_manager.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -15,7 +15,6 @@ #include "dbuffer_manager.h" #include -#include "distributed_camera_constants.h" #include "distributed_hardware_log.h" namespace OHOS { diff --git a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp index 10fa5767879a317826010b3e3f181dae4aa1c0e3..2d6bbca123c9023a68f9b456d24ee303e6a567dd 100644 --- a/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp +++ b/camera_hdf/hdi_impl/src/dstream_operator/dstream_operator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021 Huawei Device Co., Ltd. + * Copyright (c) 2021-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 @@ -16,7 +16,7 @@ #include "dstream_operator.h" #include "dbuffer_manager.h" #include "dcamera_provider.h" -#include "dcamera_utils_tools.h" +#include "dcamera.h" #include "distributed_hardware_log.h" #include "json/json.h" #include "metadata_utils.h" diff --git a/camera_hdf/hdi_impl/src/utils/anonymous_string.cpp b/camera_hdf/hdi_impl/src/utils/anonymous_string.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b6cfa82d2b2b478b8119021bc5a1ee3fcfbe7aa2 --- /dev/null +++ b/camera_hdf/hdi_impl/src/utils/anonymous_string.cpp @@ -0,0 +1,68 @@ +/* + * 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 "anonymous_string.h" + +#include "securec.h" + +namespace OHOS { +namespace DistributedHardware { +std::string GetAnonyString(const std::string &value) +{ + constexpr size_t INT32_SHORT_ID_LENGTH = 20; + constexpr size_t INT32_PLAINTEXT_LENGTH = 4; + constexpr size_t INT32_MIN_ID_LENGTH = 3; + std::string res; + std::string tmpStr("******"); + size_t strLen = value.length(); + if (strLen < INT32_MIN_ID_LENGTH) { + return tmpStr; + } + + if (strLen <= INT32_SHORT_ID_LENGTH) { + res += value[0]; + res += tmpStr; + res += value[strLen - 1]; + } else { + res.append(value, 0, INT32_PLAINTEXT_LENGTH); + res += tmpStr; + res.append(value, strLen - INT32_PLAINTEXT_LENGTH, INT32_PLAINTEXT_LENGTH); + } + + return res; +} + +std::string GetAnonyInt32(const int32_t value) +{ + constexpr int32_t INT32_STRING_LENGTH = 40; + char tempBuffer[INT32_STRING_LENGTH] = ""; + int32_t secRet = sprintf_s(tempBuffer, INT32_STRING_LENGTH, "%d", value); + if (secRet <= 0) { + std::string nullString(""); + return nullString; + } + size_t length = strlen(tempBuffer); + for (size_t i = 1; i <= length - 1; i++) { + tempBuffer[i] = '*'; + } + if (length == 0x01) { + tempBuffer[0] = '*'; + } + + std::string tempString(tempBuffer); + return tempString; +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/camera_hdf/hdi_impl/src/utils/dcamera.cpp b/camera_hdf/hdi_impl/src/utils/dcamera.cpp index 73b778516e237fb018e44e8ffce92c9656188311..c618cc5aa79abcd02bd0a3dc82a2340b0f16a069 100644 --- a/camera_hdf/hdi_impl/src/utils/dcamera.cpp +++ b/camera_hdf/hdi_impl/src/utils/dcamera.cpp @@ -18,6 +18,13 @@ namespace OHOS { namespace DistributedHardware { +const int OFFSET2 = 2; +const int OFFSET4 = 4; +const int OFFSET6 = 6; +const int INDEX_FIRST = 0; +const int INDEX_SECOND = 1; +const int INDEX_THIRD = 2; +const int INDEX_FORTH = 3; CamRetCode MapToExternalRetCode(DCamRetCode retCode) { switch (retCode) { @@ -85,5 +92,102 @@ void SplitString(const std::string &str, std::vector &tokens, const tokens.push_back(str.substr(lastPos)); } } + +std::string Base64Encode(const unsigned char *toEncode, unsigned int len) +{ + std::string ret; + uint32_t i = 0; + unsigned char charArray3[3]; + unsigned char charArray4[4]; + + while (len--) { + charArray3[i++] = *(toEncode++); + if (i == sizeof(charArray3)) { + charArray4[INDEX_FIRST] = (charArray3[INDEX_FIRST] & 0xfc) >> OFFSET2; + charArray4[INDEX_SECOND] = ((charArray3[INDEX_FIRST] & 0x03) << OFFSET4) + + ((charArray3[INDEX_SECOND] & 0xf0) >> OFFSET4); + charArray4[INDEX_THIRD] = ((charArray3[INDEX_SECOND] & 0x0f) << OFFSET2) + + ((charArray3[INDEX_THIRD] & 0xc0) >> OFFSET6); + charArray4[INDEX_FORTH] = charArray3[INDEX_THIRD] & 0x3f; + for (i = 0; i < sizeof(charArray4); i++) { + ret += BASE_64_CHARS[charArray4[i]]; + } + i = 0; + } + } + + if (i) { + uint32_t j = 0; + for (j = i; j < sizeof(charArray3); j++) { + charArray3[j] = '\0'; + } + charArray4[INDEX_FIRST] = (charArray3[INDEX_FIRST] & 0xfc) >> OFFSET2; + charArray4[INDEX_SECOND] = ((charArray3[INDEX_FIRST] & 0x03) << OFFSET4) + + ((charArray3[INDEX_SECOND] & 0xf0) >> OFFSET4); + charArray4[INDEX_THIRD] = ((charArray3[INDEX_SECOND] & 0x0f) << OFFSET2) + + ((charArray3[INDEX_THIRD] & 0xc0) >> OFFSET6); + charArray4[INDEX_FORTH] = charArray3[INDEX_THIRD] & 0x3f; + for (j = 0; j < i + 1; j++) { + ret += BASE_64_CHARS[charArray4[j]]; + } + while (i++ < sizeof(charArray3)) { + ret += '='; + } + } + return ret; +} + +std::string Base64Decode(const std::string& basicString) +{ + std::string ret; + uint32_t i = 0; + int index = 0; + int len = static_cast(basicString.size()); + unsigned char charArray3[3]; + unsigned char charArray4[4]; + + while (len-- && (basicString[index] != '=') && IsBase64(basicString[index])) { + charArray4[i++] = basicString[index]; + index++; + if (i == sizeof(charArray4)) { + for (i = 0; i < sizeof(charArray4); i++) { + charArray4[i] = BASE_64_CHARS.find(charArray4[i]); + } + charArray3[INDEX_FIRST] = (charArray4[INDEX_FIRST] << OFFSET2) + + ((charArray4[INDEX_SECOND] & 0x30) >> OFFSET4); + charArray3[INDEX_SECOND] = ((charArray4[INDEX_SECOND] & 0xf) << OFFSET4) + + ((charArray4[INDEX_THIRD] & 0x3c) >> OFFSET2); + charArray3[INDEX_THIRD] = ((charArray4[INDEX_THIRD] & 0x3) << OFFSET6) + charArray4[INDEX_FORTH]; + for (i = 0; i < sizeof(charArray3); i++) { + ret += charArray3[i]; + } + i = 0; + } + } + + if (i) { + uint32_t j = 0; + for (j = i; j < sizeof(charArray4); j++) { + charArray4[j] = 0; + } + for (j = 0; j < sizeof(charArray4); j++) { + charArray4[j] = BASE_64_CHARS.find(charArray4[j]); + } + charArray3[INDEX_FIRST] = (charArray4[INDEX_FIRST] << OFFSET2) + + ((charArray4[INDEX_SECOND] & 0x30) >> OFFSET4); + charArray3[INDEX_SECOND] = ((charArray4[INDEX_SECOND] & 0xf) << OFFSET4) + + ((charArray4[INDEX_THIRD] & 0x3c) >> OFFSET2); + charArray3[INDEX_THIRD] = ((charArray4[INDEX_THIRD] & 0x3) << OFFSET6) + charArray4[INDEX_FORTH]; + for (j = 0; j < i - 1; j++) { + ret += charArray3[j]; + } + } + return ret; +} + +bool IsBase64(unsigned char c) +{ + return (isalnum(c) || (c == '+') || (c == '/')); +} } // namespace DistributedHardware } // namespace OHOS diff --git a/camera_hdf/hdi_impl/src/utils/dh_log.cpp b/camera_hdf/hdi_impl/src/utils/dh_log.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f2278de4feefe578a8223fbcc686201c7b2d1d7d --- /dev/null +++ b/camera_hdf/hdi_impl/src/utils/dh_log.cpp @@ -0,0 +1,87 @@ +/* + * 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 "dh_log.h" + +#include "securec.h" + +#include "constants.h" + +#ifdef HI_LOG_ENABLE +#include "hilog/log.h" +#else +#include +#endif + +namespace OHOS { +namespace DistributedHardware { +static void DHLogOut(DHLogLevel logLevel, const char *logBuf) +{ +#ifdef HI_LOG_ENABLE + LogLevel hiLogLevel = LOG_INFO; + switch (logLevel) { + case DH_LOG_DEBUG: + hiLogLevel = LOG_DEBUG; + break; + case DH_LOG_INFO: + hiLogLevel = LOG_INFO; + break; + case DH_LOG_WARN: + hiLogLevel = LOG_WARN; + break; + case DH_LOG_ERROR: + hiLogLevel = LOG_ERROR; + break; + default: + break; + } + (void)HiLogPrint(LOG_CORE, hiLogLevel, LOG_DOMAIN, DH_LOG_TITLE_TAG.c_str(), "%{public}s", logBuf); +#else + switch (logLevel) { + case DH_LOG_DEBUG: + printf("[D]%s\n", logBuf); + break; + case DH_LOG_INFO: + printf("[I]%s\n", logBuf); + break; + case DH_LOG_WARN: + printf("[W]%s\n", logBuf); + break; + case DH_LOG_ERROR: + printf("[E]%s\n", logBuf); + break; + default: + break; + } +#endif +} + +void DHLog(DHLogLevel logLevel, const char *fmt, ...) +{ + char logBuf[LOG_MAX_LEN] = {0}; + va_list arg; + + (void)memset_s(&arg, sizeof(va_list), 0, sizeof(va_list)); + va_start(arg, fmt); + int32_t ret = vsprintf_s(logBuf, sizeof(logBuf), fmt, arg); + va_end(arg); + if (ret < 0) { + DHLogOut(logLevel, "DH log length error."); + return; + } + DHLogOut(logLevel, logBuf); +} +} // namespace DistributedHardware +} // namespace OHOS diff --git a/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn b/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn index 12ae6f5ecc9e56fd3806d782bed5fc96ad469db2..51957d0dc1572cbb5fdd3d3925d89b3f98040fd6 100644 --- a/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn +++ b/camera_hdf/interfaces/hdi_ipc/client/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2021 Huawei Device Co., Ltd. +# Copyright (c) 2021-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 @@ -24,10 +24,7 @@ ohos_shared_library("distributed_camera_hdf_client") { "//utils/system/safwk/native/include", "${camera_hdf_path}/camera/interfaces/include", "${camera_hdf_path}/camera/interfaces/hdi_ipc", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include/", - "${fwk_utils_path}/include", - "${fwk_utils_path}/include/log", + "${distributedcamera_hdf_path}/hdi_impl/include/utils", "${hdf_framework_path}/include/utils", "${hdf_uhdf_path}/include/hdi", "${hdf_uhdf_path}/osal/include", @@ -67,7 +64,7 @@ ohos_shared_library("distributed_camera_hdf_client") { ] deps = [ - "${fwk_utils_path}:distributedhardwareutils", + "${distributedcamera_hdf_path}/hdi_impl:distributed_camera_hdf", "${hdf_uhdf_path}/hdi:libhdi", "//drivers/peripheral/camera/interfaces/metadata:metadata", "//drivers/peripheral/display/hal:hdi_display_gralloc",