diff --git a/common/include/constants/distributed_camera_constants.h b/common/include/constants/distributed_camera_constants.h index bf517f2ff9a2844442ee85ad714937276f19314a..071d54d1fab0e380d9824c395241a76a007e21be 100644 --- a/common/include/constants/distributed_camera_constants.h +++ b/common/include/constants/distributed_camera_constants.h @@ -22,6 +22,10 @@ namespace OHOS { namespace DistributedHardware { + +const std::string DH_LOG_TITLE_TAG = "DCAMERA"; +constexpr int32_t LOG_MAX_LEN = 4096; + typedef enum { DCAMERA_SRV_STATE_NOT_START, DCAMERA_SRV_STATE_RUNNING diff --git a/common/include/utils/dh_log.h b/common/include/utils/dh_log.h new file mode 100644 index 0000000000000000000000000000000000000000..6a8e38014564dce6b3fbf55f023bd9dc6632be1c --- /dev/null +++ b/common/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/common/include/utils/distributed_hardware_log.h b/common/include/utils/distributed_hardware_log.h new file mode 100644 index 0000000000000000000000000000000000000000..d7e1c1ee1cdc7897263df65212abe49685e8e796 --- /dev/null +++ b/common/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/common/src/utils/dh_log.cpp b/common/src/utils/dh_log.cpp new file mode 100644 index 0000000000000000000000000000000000000000..c5eb4bec0d92f2d34909e3735a0c6500c176d37f --- /dev/null +++ b/common/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 "distributed_camera_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/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn b/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn index 08504b1b7e4b829978e98fbf094df006c46e6d65..ef651f5d1753692e21da29b187a7e165af709910 100644 --- a/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/camera_sink/BUILD.gn @@ -19,9 +19,7 @@ ohos_shared_library("distributed_camera_sink_sdk") { include_dirs = [ "//utils/native/base/include", "//utils/system/safwk/native/include", - "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", ] diff --git a/interfaces/inner_kits/native_cpp/camera_source/BUILD.gn b/interfaces/inner_kits/native_cpp/camera_source/BUILD.gn index 756242d97d1765544c214514984528bc7bf52740..a07075a68bfdc9347f39af266931e8bdac91dff6 100644 --- a/interfaces/inner_kits/native_cpp/camera_source/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/camera_source/BUILD.gn @@ -19,9 +19,7 @@ ohos_shared_library("distributed_camera_source_sdk") { include_dirs = [ "//utils/native/base/include", "//utils/system/safwk/native/include", - "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", - "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", ] diff --git a/services/cameraservice/cameraoperator/client/BUILD.gn b/services/cameraservice/cameraoperator/client/BUILD.gn index 879511f68f85de81a39deeb1afc23685c6d28602..ead27494df2fa53ebfe36ae545b29b67f849d7fa 100644 --- a/services/cameraservice/cameraoperator/client/BUILD.gn +++ b/services/cameraservice/cameraoperator/client/BUILD.gn @@ -32,9 +32,6 @@ ohos_shared_library("distributed_camera_client") { "${camerastandard_path}/services/camera_service/binder/client/include", "${camerastandard_path}/services/camera_service/binder/server/include", "${camerastandard_path}/services/camera_service/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", ] diff --git a/services/cameraservice/cameraoperator/handler/BUILD.gn b/services/cameraservice/cameraoperator/handler/BUILD.gn index 6a61f09528f3d131b403877c353934a9dde7f86d..9e2b5ab78d2a278754b3aac22214986a4afa1e08 100644 --- a/services/cameraservice/cameraoperator/handler/BUILD.gn +++ b/services/cameraservice/cameraoperator/handler/BUILD.gn @@ -32,9 +32,7 @@ ohos_shared_library("distributed_camera_handler") { "${camerastandard_path}/services/camera_service/binder/server/include", "${camerastandard_path}/services/camera_service/include", "${mediastandard_path}/interfaces/innerkits/native/media/include", - "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", ] diff --git a/services/cameraservice/sinkservice/BUILD.gn b/services/cameraservice/sinkservice/BUILD.gn index 6780bc1a88896cc22d072b0b530a87a73baa5767..42178f46a8878f1c8e3e0c815f49cbed4daf1ae6 100644 --- a/services/cameraservice/sinkservice/BUILD.gn +++ b/services/cameraservice/sinkservice/BUILD.gn @@ -30,10 +30,8 @@ ohos_shared_library("distributed_camera_sink") { "${camerastandard_path}/services/camera_service/binder/client/include", "${camerastandard_path}/services/camera_service/binder/server/include", "${camerastandard_path}/services/camera_service/include", - "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/eventbus", - "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", "//third_party/jsoncpp/include", ] diff --git a/services/cameraservice/sourceservice/BUILD.gn b/services/cameraservice/sourceservice/BUILD.gn index 1929f4e8edea4b04e72cb5d73fe86a75ff20d616..12b63f2734bf7dba0793cab064f6f20fb3c4f4d9 100644 --- a/services/cameraservice/sourceservice/BUILD.gn +++ b/services/cameraservice/sourceservice/BUILD.gn @@ -20,10 +20,8 @@ ohos_shared_library("distributed_camera_source") { include_dirs = [ "//utils/native/base/include", "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", "${fwk_utils_path}/include/eventbus", - "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", "//third_party/jsoncpp/include", "//drivers/peripheral/base", diff --git a/services/channel/BUILD.gn b/services/channel/BUILD.gn index 75cab6f2d604420d519801815528e4e8e52a4e00..c5a55dd21e2465d65cf2fbb2e4f5d92a58c7e1f4 100644 --- a/services/channel/BUILD.gn +++ b/services/channel/BUILD.gn @@ -20,9 +20,7 @@ ohos_shared_library("distributed_camera_channel") { include_dirs = [ "//utils/native/base/include", "//utils/system/safwk/native/include", - "${fwk_common_path}/log/include", "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", "${fwk_utils_path}/include", ] diff --git a/services/data_process/BUILD.gn b/services/data_process/BUILD.gn index 72e5e377d5af72c9746bc1171a4c89efb74b1c65..c22614ceec31cd1a29d1bde230e4dad07ee54522 100644 --- a/services/data_process/BUILD.gn +++ b/services/data_process/BUILD.gn @@ -24,10 +24,8 @@ ohos_shared_library("distributed_camera_data_process") { "//foundation/graphic/graphic_2d/interfaces/innerkits/common", "//foundation/graphic/graphic_2d/interfaces/innerkits/surface", "//drivers/peripheral/display/interfaces/include", + "//foundation/multimedia/media_standard/interfaces/innerkits/native/media/include", "//foundation/multimedia/player_framework/interfaces/innerkits/native/media/include", - "${fwk_common_path}/log/include", - "${fwk_common_path}/utils/include", - "${fwk_utils_path}/include/log", "${fwk_utils_path}/include/eventbus", "${fwk_utils_path}/include", ]