From 36bdc620667c71941f7b4565acda681a6fd2a0f3 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Tue, 17 May 2022 22:49:22 +0800 Subject: [PATCH 1/8] =?UTF-8?q?js=E4=BF=A1=E6=81=AF=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- common/include/dm_constants.h | 32 +++++ .../kits/js/include/native_devicemanager_js.h | 3 + .../kits/js/src/native_devicemanager_js.cpp | 4 + utils/BUILD.gn | 6 + utils/include/errormessage/errormessage.h | 49 +++++++ utils/src/errormessage/errormessage.cpp | 126 ++++++++++++++++++ 6 files changed, 220 insertions(+) create mode 100644 utils/include/errormessage/errormessage.h create mode 100644 utils/src/errormessage/errormessage.cpp diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 4ff3d02b..1a303db2 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -199,6 +199,38 @@ const int32_t MAX_EVENT_NUMBER = 10; const int32_t EXPAND_TWICE = 2; const int32_t SEC_TO_MM = 1000; const int32_t MAX_EVENTS = 5; + +// error code info +const std::string DM_FAILED_INFO = "dm process execution failed."; +const std::string DM_TIME_OUT_INFO = "dm process execution timeout."; +const std::string DM_NOT_INIT_INFO = "dm service is not initialized, please try again later."; +const std::string DM_INIT_REPEATED_INFO = "dm service repeated initialization."; +const std::string DM_INIT_FAILED_INFO = "dm service initialize failed."; +const std::string DM_UNINIT_FAILED_INFO = "dm Service uninitialization failed."; +const std::string DM_POINT_NULL_INFO = "dm service null pointer exception occurred."; +const std::string DM_INPUT_PARAMETER_EMPTY_INFO = "the function call input parameter is empty."; +const std::string DM_NO_PERMISSION_INFO = "no permission for function call."; +const std::string DM_MALLOC_FAILED_INFO = "memory allocation failed."; +const std::string DM_DISCOVERY_FAILED_INFO = "device discovery failed."; +const std::string DM_MAP_KEY_ALREADY_EXISTS_INFO = "map key already exists."; +const std::string DM_PROFILE_EVENTS_FAILED_INFO = "process profile events failed."; +const std::string DM_IPC_WRITE_FAILED_INFO = "ipc write object failed."; +const std::string DM_IPC_COPY_FAILED_INFO = "ipc copy data failed."; +const std::string DM_IPC_SEND_REQUEST_FAILED_INFO = "ipc send request failed."; +const std::string DM_UNSUPPORTED_IPC_COMMAND_INFO = "ipc command not supported."; +const std::string DM_IPC_RESPOND_FAILED_INFO = "ipc process failed to receive response."; +const std::string DM_IPC_WRITE_TOKEN_INFO = "ipc write token failed."; +const std::string DM_DISCOVERY_REPEATED_INFO = "repeat device discovery warning."; +const std::string DM_UNSUPPORTED_AUTH_TYPE_INFO = "auth type not supported."; +const std::string DM_AUTH_BUSINESS_BUSY_INFO = "authentication service is busy."; +const std::string DM_AUTH_OPEN_SESSION_FAILED_INFO = "open auth session failed."; +const std::string DM_AUTH_PEER_REJECT_INFO = "remote device refused to authorization."; +const std::string DM_AUTH_REJECT_INFO = "local device refused to authorization."; +const std::string DM_AUTH_FAILED_INFO = "authentication failed."; +const std::string DM_AUTH_NOT_START_INFO = "auth process not started."; +const std::string DM_AUTH_MESSAGE_INCOMPLETE_INFO = "authentication message is incomplete."; +const std::string DM_CREATE_GROUP_FAILED_INFO = "create group failed."; +const std::string DM_ERROR_CODE_DEFAULT_INFO = "error code undefined."; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_CONSTANTS_H diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index 8db0b602..6b0883f8 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -25,6 +25,7 @@ #include "dm_native_event.h" #include "dm_subscribe_info.h" #include "dm_anonymous.h" +#include "errormessage/errormessage.h" #include "napi/native_api.h" #include "napi/native_node_api.h" #include "nlohmann/json.hpp" @@ -311,5 +312,7 @@ private: std::string bundleName_; static AuthAsyncCallbackInfo authAsyncCallbackInfo_; static AuthAsyncCallbackInfo verifyAsyncCallbackInfo_; + std::shared_ptr errorMessage_ = + std::make_shared(); }; #endif // OHOS_DM_NATIVE_DEVICEMANAGER_JS_H diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index f057d9cf..b4cb83bc 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -489,6 +489,8 @@ void DeviceManagerNapi::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedRe napi_create_object(env_, &result); SetValueInt32(env_, "subscribeId", (int)subscribeId, result); SetValueInt32(env_, "reason", (int)failedReason, result); + std::string errCodeInfo = errorMessage_->GetErrorString((int)failedReason); + SetValueUtf8String(env_, "errInfo", errCodeInfo, result); OnEvent("discoverFail", DM_NAPI_ARGS_ONE, &result); } @@ -510,6 +512,8 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str napi_create_object(env_, &result[0]); SetValueInt32(env_, "code", status, result[0]); SetValueInt32(env_, "reason", reason, result[0]); + std::string errCodeInfo = errorMessage_->GetErrorString((int)reason); + SetValueUtf8String(env_, "errInfo", errCodeInfo, result[0]); napi_get_undefined(env_, &result[1]); } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index e877585c..bf4fb711 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -37,12 +37,14 @@ if (defined(ohos_lite)) { "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", "//third_party/bounds_checking_function/include", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//utils/include/errormessage", ] sources = [ "${utils_path}/src/dm_anonymous.cpp", "${utils_path}/src/dm_log.cpp", "${utils_path}/src/dm_random.cpp", + "${utils_path}/src/errormessage/errormessage.cpp", "${utils_path}/src/permission/lite/permission_manager.cpp", ] @@ -88,11 +90,13 @@ if (defined(ohos_lite)) { "//foundation/communication/dsoftbus/interfaces/kits/transport", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", + "//utils/include/errormessage", ] sources = [ "src/dm_anonymous.cpp", "src/dm_log.cpp", "src/dm_random.cpp", + "src/errormessage/errormessage.cpp", "src/fwkload/lite/dm_distributed_hardware_load.cpp", "src/ipc/lite/ipc_cmd_register.cpp", "src/permission/lite/permission_manager.cpp", @@ -125,6 +129,7 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc/model", "include/permission/standard", "//third_party/mbedtls/include/mbedtls", + "//utils/include/errormessage", ] } @@ -134,6 +139,7 @@ if (defined(ohos_lite)) { "src/dm_hash.cpp", "src/dm_log.cpp", "src/dm_random.cpp", + "src/errormessage/errormessage.cpp", "src/ipc/standard/ipc_cmd_register.cpp", ] if (support_jsapi) { diff --git a/utils/include/errormessage/errormessage.h b/utils/include/errormessage/errormessage.h new file mode 100644 index 00000000..86774958 --- /dev/null +++ b/utils/include/errormessage/errormessage.h @@ -0,0 +1,49 @@ +/* + * 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_DM_ERROMSG_H +#define OHOS_DM_ERROMSG_H + +#include +#include +#include "dm_log.h" +#include "dm_constants.h" + +namespace OHOS { +namespace DistributedHardware { +class ErrorMessage { +public: + /** + * @tc.name: ErrorMessage::ErrorMessage + * @tc.desc: Dm Error Message Info Constructor. + * @tc.type: FUNC + */ + ErrorMessage(); + /** + * @tc.name: ErrorMessage::~ErrorMessage + * @tc.desc: Dm Error Message Info destructor. + * @tc.type: FUNC + */ + virtual ~ErrorMessage(); + /** + * @tc.name: ErrorMessage::GetErrorString + * @tc.desc: Get Error String. + * @tc.type: FUNC + */ + std::string GetErrorString(int); +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif // OHOS_DM_ERROMSG_H diff --git a/utils/src/errormessage/errormessage.cpp b/utils/src/errormessage/errormessage.cpp new file mode 100644 index 00000000..24106f6a --- /dev/null +++ b/utils/src/errormessage/errormessage.cpp @@ -0,0 +1,126 @@ +/* + * 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 "errormessage/errormessage.h" + +namespace OHOS { +namespace DistributedHardware { +ErrorMessage::ErrorMessage() +{ + LOGI("ErrorMessage construct."); +} + +ErrorMessage::~ErrorMessage() +{ + LOGI("ErrorMessage Destructor."); +} + +std::string ErrorMessage::GetErrorString(int failedReason) +{ + LOGI("Enter PermissionManager::GetErrorString"); + std::string tmpStr; + switch (failedReason) { + case ERR_DM_FAILED: + tmpStr = DM_FAILED_INFO; + break; + case ERR_DM_TIME_OUT: + tmpStr = DM_TIME_OUT_INFO; + break; + case ERR_DM_NOT_INIT: + tmpStr = DM_NOT_INIT_INFO; + break; + case ERR_DM_INIT_REPEATED: + tmpStr = DM_INIT_REPEATED_INFO; + break; + case ERR_DM_INIT_FAILED: + tmpStr = DM_INIT_FAILED_INFO; + break; + case ERR_DM_UNINIT_FAILED: + tmpStr = DM_UNINIT_FAILED_INFO; + break; + case ERR_DM_POINT_NULL: + tmpStr = DM_POINT_NULL_INFO; + break; + case ERR_DM_INPUT_PARAMETER_EMPTY: + tmpStr = DM_INPUT_PARAMETER_EMPTY_INFO; + break; + case ERR_DM_NO_PERMISSION: + tmpStr = DM_NO_PERMISSION_INFO; + break; + case ERR_DM_MALLOC_FAILED: + tmpStr = DM_MALLOC_FAILED_INFO; + break; + case ERR_DM_DISCOVERY_FAILED: + tmpStr = DM_DISCOVERY_FAILED_INFO; + break; + case ERR_DM_MAP_KEY_ALREADY_EXISTS: + tmpStr = DM_MAP_KEY_ALREADY_EXISTS_INFO; + break; + case DM_PROFILE_EVENTS_FAILED: + tmpStr = DM_PROFILE_EVENTS_FAILED_INFO; + break; + case ERR_DM_IPC_WRITE_FAILED: + tmpStr = DM_IPC_WRITE_FAILED_INFO; + break; + case ERR_DM_IPC_COPY_FAILED: + tmpStr = DM_IPC_COPY_FAILED_INFO; + break; + case ERR_DM_IPC_SEND_REQUEST_FAILED: + tmpStr = DM_IPC_SEND_REQUEST_FAILED_INFO; + break; + case ERR_DM_UNSUPPORTED_IPC_COMMAND: + tmpStr = DM_UNSUPPORTED_IPC_COMMAND_INFO; + break; + case ERR_DM_IPC_RESPOND_FAILED: + tmpStr = DM_IPC_RESPOND_FAILED_INFO; + break; + case ERR_DM_IPC_WRITE_TOKEN_FAILED: + tmpStr = DM_IPC_WRITE_TOKEN_INFO; + break; + case ERR_DM_DISCOVERY_REPEATED: + tmpStr = DM_DISCOVERY_REPEATED_INFO; + break; + case ERR_DM_UNSUPPORTED_AUTH_TYPE: + tmpStr = DM_UNSUPPORTED_AUTH_TYPE_INFO; + break; + case ERR_DM_AUTH_OPEN_SESSION_FAILED: + tmpStr = DM_AUTH_OPEN_SESSION_FAILED_INFO; + break; + case ERR_DM_AUTH_PEER_REJECT: + tmpStr = DM_AUTH_PEER_REJECT_INFO; + break; + case ERR_DM_AUTH_REJECT: + tmpStr = DM_AUTH_REJECT_INFO; + break; + case ERR_DM_AUTH_FAILED: + tmpStr = DM_AUTH_FAILED_INFO; + break; + case ERR_DM_AUTH_NOT_START: + tmpStr = DM_AUTH_NOT_START_INFO; + break; + case ERR_DM_AUTH_MESSAGE_INCOMPLETE: + tmpStr = DM_AUTH_MESSAGE_INCOMPLETE_INFO; + break; + case ERR_DM_CREATE_GROUP_FAILED: + tmpStr = DM_CREATE_GROUP_FAILED_INFO; + break; + default: + tmpStr = DM_ERROR_CODE_DEFAULT_INFO; + break; + } + return tmpStr; +} +} // namespace DistributedHardware +} // namespace OHOS From 8c6aa6c781dad290232e9a8a7e7ef61b69b16af7 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Fri, 20 May 2022 10:21:21 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E6=A3=80=E8=A7=86=E6=84=8F=E8=A7=81?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=20Signed-off-by:=20wangyb0625=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/js/include/native_devicemanager_js.h | 4 +- .../kits/js/src/native_devicemanager_js.cpp | 4 +- utils/BUILD.gn | 12 +- .../errormessage.h => dm_error_message.h} | 23 +--- utils/src/dm_error_message.cpp | 71 ++++++++++ utils/src/errormessage/errormessage.cpp | 126 ------------------ 6 files changed, 81 insertions(+), 159 deletions(-) rename utils/include/{errormessage/errormessage.h => dm_error_message.h} (62%) create mode 100644 utils/src/dm_error_message.cpp delete mode 100644 utils/src/errormessage/errormessage.cpp diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index 6b0883f8..3efde146 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -25,7 +25,7 @@ #include "dm_native_event.h" #include "dm_subscribe_info.h" #include "dm_anonymous.h" -#include "errormessage/errormessage.h" +#include "dm_error_message.h" #include "napi/native_api.h" #include "napi/native_node_api.h" #include "nlohmann/json.hpp" @@ -312,7 +312,5 @@ private: std::string bundleName_; static AuthAsyncCallbackInfo authAsyncCallbackInfo_; static AuthAsyncCallbackInfo verifyAsyncCallbackInfo_; - std::shared_ptr errorMessage_ = - std::make_shared(); }; #endif // OHOS_DM_NATIVE_DEVICEMANAGER_JS_H diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index b4cb83bc..05042785 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -489,7 +489,7 @@ void DeviceManagerNapi::OnDiscoveryFailed(uint16_t subscribeId, int32_t failedRe napi_create_object(env_, &result); SetValueInt32(env_, "subscribeId", (int)subscribeId, result); SetValueInt32(env_, "reason", (int)failedReason, result); - std::string errCodeInfo = errorMessage_->GetErrorString((int)failedReason); + std::string errCodeInfo = OHOS::DistributedHardware::GetErrorString((int)failedReason); SetValueUtf8String(env_, "errInfo", errCodeInfo, result); OnEvent("discoverFail", DM_NAPI_ARGS_ONE, &result); } @@ -512,7 +512,7 @@ void DeviceManagerNapi::OnAuthResult(const std::string &deviceId, const std::str napi_create_object(env_, &result[0]); SetValueInt32(env_, "code", status, result[0]); SetValueInt32(env_, "reason", reason, result[0]); - std::string errCodeInfo = errorMessage_->GetErrorString((int)reason); + std::string errCodeInfo = OHOS::DistributedHardware::GetErrorString((int)reason); SetValueUtf8String(env_, "errInfo", errCodeInfo, result[0]); napi_get_undefined(env_, &result[1]); } diff --git a/utils/BUILD.gn b/utils/BUILD.gn index bf4fb711..a938e8ff 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -37,14 +37,14 @@ if (defined(ohos_lite)) { "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", "//third_party/bounds_checking_function/include", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//utils/include/errormessage", + "//utils/include/dm_error_message", ] sources = [ "${utils_path}/src/dm_anonymous.cpp", + "${utils_path}/src/dm_error_message.cpp", "${utils_path}/src/dm_log.cpp", "${utils_path}/src/dm_random.cpp", - "${utils_path}/src/errormessage/errormessage.cpp", "${utils_path}/src/permission/lite/permission_manager.cpp", ] @@ -90,13 +90,13 @@ if (defined(ohos_lite)) { "//foundation/communication/dsoftbus/interfaces/kits/transport", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//utils/include/errormessage", + "//utils/include/dm_error_message", ] sources = [ "src/dm_anonymous.cpp", + "src/dm_error_message.cpp", "src/dm_log.cpp", "src/dm_random.cpp", - "src/errormessage/errormessage.cpp", "src/fwkload/lite/dm_distributed_hardware_load.cpp", "src/ipc/lite/ipc_cmd_register.cpp", "src/permission/lite/permission_manager.cpp", @@ -129,17 +129,17 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc/model", "include/permission/standard", "//third_party/mbedtls/include/mbedtls", - "//utils/include/errormessage", + "//utils/include/dm_error_message", ] } ohos_shared_library("devicemanagerutils") { sources = [ "src/dm_anonymous.cpp", + "src/dm_error_message.cpp", "src/dm_hash.cpp", "src/dm_log.cpp", "src/dm_random.cpp", - "src/errormessage/errormessage.cpp", "src/ipc/standard/ipc_cmd_register.cpp", ] if (support_jsapi) { diff --git a/utils/include/errormessage/errormessage.h b/utils/include/dm_error_message.h similarity index 62% rename from utils/include/errormessage/errormessage.h rename to utils/include/dm_error_message.h index 86774958..52e22059 100644 --- a/utils/include/errormessage/errormessage.h +++ b/utils/include/dm_error_message.h @@ -16,34 +16,13 @@ #ifndef OHOS_DM_ERROMSG_H #define OHOS_DM_ERROMSG_H -#include #include #include "dm_log.h" #include "dm_constants.h" namespace OHOS { namespace DistributedHardware { -class ErrorMessage { -public: - /** - * @tc.name: ErrorMessage::ErrorMessage - * @tc.desc: Dm Error Message Info Constructor. - * @tc.type: FUNC - */ - ErrorMessage(); - /** - * @tc.name: ErrorMessage::~ErrorMessage - * @tc.desc: Dm Error Message Info destructor. - * @tc.type: FUNC - */ - virtual ~ErrorMessage(); - /** - * @tc.name: ErrorMessage::GetErrorString - * @tc.desc: Get Error String. - * @tc.type: FUNC - */ - std::string GetErrorString(int); -}; +std::string GetErrorString(int failedReason); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_ERROMSG_H diff --git a/utils/src/dm_error_message.cpp b/utils/src/dm_error_message.cpp new file mode 100644 index 00000000..d9e24471 --- /dev/null +++ b/utils/src/dm_error_message.cpp @@ -0,0 +1,71 @@ +/* + * 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 "dm_error_message.h" + +namespace OHOS { +namespace DistributedHardware { +typedef struct ERROR_INFO +{ + int errCode; + std::string errMsg; +}ERROR_INFO; + +static ERROR_INFO g_errorMessages[] = +{ + {ERR_DM_FAILED, DM_FAILED_INFO}, + {ERR_DM_TIME_OUT, DM_TIME_OUT_INFO}, + {ERR_DM_NOT_INIT, DM_NOT_INIT_INFO}, + {ERR_DM_INIT_REPEATED, DM_INIT_REPEATED_INFO}, + {ERR_DM_INIT_FAILED, DM_INIT_FAILED_INFO}, + {ERR_DM_UNINIT_FAILED, DM_UNINIT_FAILED_INFO}, + {ERR_DM_POINT_NULL, DM_POINT_NULL_INFO}, + {ERR_DM_INPUT_PARAMETER_EMPTY, DM_INPUT_PARAMETER_EMPTY_INFO}, + {ERR_DM_NO_PERMISSION, DM_NO_PERMISSION_INFO}, + {ERR_DM_MALLOC_FAILED, DM_MALLOC_FAILED_INFO}, + {ERR_DM_DISCOVERY_FAILED, DM_DISCOVERY_FAILED_INFO}, + {ERR_DM_MAP_KEY_ALREADY_EXISTS, DM_MAP_KEY_ALREADY_EXISTS_INFO}, + {DM_PROFILE_EVENTS_FAILED, DM_PROFILE_EVENTS_FAILED_INFO}, + {ERR_DM_IPC_WRITE_FAILED, DM_IPC_WRITE_FAILED_INFO}, + {ERR_DM_IPC_COPY_FAILED, DM_IPC_COPY_FAILED_INFO}, + {ERR_DM_IPC_SEND_REQUEST_FAILED, DM_IPC_SEND_REQUEST_FAILED_INFO}, + {ERR_DM_UNSUPPORTED_IPC_COMMAND, DM_UNSUPPORTED_IPC_COMMAND_INFO}, + {ERR_DM_IPC_RESPOND_FAILED, DM_IPC_RESPOND_FAILED_INFO}, + {ERR_DM_IPC_WRITE_TOKEN_FAILED, DM_IPC_WRITE_TOKEN_INFO}, + {ERR_DM_DISCOVERY_REPEATED, DM_DISCOVERY_REPEATED_INFO}, + {ERR_DM_UNSUPPORTED_AUTH_TYPE, DM_UNSUPPORTED_AUTH_TYPE_INFO}, + {ERR_DM_AUTH_BUSINESS_BUSY, DM_AUTH_BUSINESS_BUSY_INFO}, + {ERR_DM_AUTH_OPEN_SESSION_FAILED, DM_AUTH_OPEN_SESSION_FAILED_INFO}, + {ERR_DM_AUTH_PEER_REJECT, DM_AUTH_PEER_REJECT_INFO}, + {ERR_DM_AUTH_REJECT, DM_AUTH_REJECT_INFO}, + {ERR_DM_AUTH_FAILED, DM_AUTH_FAILED_INFO}, + {ERR_DM_AUTH_NOT_START, DM_AUTH_NOT_START_INFO}, + {ERR_DM_AUTH_MESSAGE_INCOMPLETE, DM_AUTH_MESSAGE_INCOMPLETE_INFO}, + {ERR_DM_CREATE_GROUP_FAILED, DM_CREATE_GROUP_FAILED_INFO}, +}; + +std::string GetErrorString(int failedReason) +{ + std::string g_errorMessage = "dm process execution failed."; + for (int i =0; i Date: Fri, 20 May 2022 11:12:09 +0800 Subject: [PATCH 3/8] =?UTF-8?q?codecheck=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- utils/include/dm_error_message.h | 3 ++- utils/src/dm_error_message.cpp | 13 +++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/utils/include/dm_error_message.h b/utils/include/dm_error_message.h index 52e22059..ba5dfe8e 100644 --- a/utils/include/dm_error_message.h +++ b/utils/include/dm_error_message.h @@ -16,10 +16,11 @@ #ifndef OHOS_DM_ERROMSG_H #define OHOS_DM_ERROMSG_H -#include #include "dm_log.h" #include "dm_constants.h" +#include + namespace OHOS { namespace DistributedHardware { std::string GetErrorString(int failedReason); diff --git a/utils/src/dm_error_message.cpp b/utils/src/dm_error_message.cpp index d9e24471..3f82bf28 100644 --- a/utils/src/dm_error_message.cpp +++ b/utils/src/dm_error_message.cpp @@ -17,14 +17,12 @@ namespace OHOS { namespace DistributedHardware { -typedef struct ERROR_INFO -{ +typedef struct ERROR_INFO { int errCode; std::string errMsg; -}ERROR_INFO; +} ERROR_INFO; -static ERROR_INFO g_errorMessages[] = -{ +static ERROR_INFO g_errorMessages[] = { {ERR_DM_FAILED, DM_FAILED_INFO}, {ERR_DM_TIME_OUT, DM_TIME_OUT_INFO}, {ERR_DM_NOT_INIT, DM_NOT_INIT_INFO}, @@ -59,9 +57,8 @@ static ERROR_INFO g_errorMessages[] = std::string GetErrorString(int failedReason) { std::string g_errorMessage = "dm process execution failed."; - for (int i =0; i Date: Fri, 20 May 2022 11:16:59 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=20Signed-off-by:=20wangyb0625=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/include/dm_constants.h | 1 - 1 file changed, 1 deletion(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 1a303db2..6651e13f 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -230,7 +230,6 @@ const std::string DM_AUTH_FAILED_INFO = "authentication failed."; const std::string DM_AUTH_NOT_START_INFO = "auth process not started."; const std::string DM_AUTH_MESSAGE_INCOMPLETE_INFO = "authentication message is incomplete."; const std::string DM_CREATE_GROUP_FAILED_INFO = "create group failed."; -const std::string DM_ERROR_CODE_DEFAULT_INFO = "error code undefined."; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_CONSTANTS_H From ce5c15baf1f96fe23fab0a7fdb810c6f3eee1c1b Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Fri, 20 May 2022 11:57:32 +0800 Subject: [PATCH 5/8] codex Signed-off-by: wangyb0625 --- utils/src/dm_error_message.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/dm_error_message.cpp b/utils/src/dm_error_message.cpp index 3f82bf28..a5a516af 100644 --- a/utils/src/dm_error_message.cpp +++ b/utils/src/dm_error_message.cpp @@ -58,7 +58,7 @@ std::string GetErrorString(int failedReason) { std::string g_errorMessage = "dm process execution failed."; for (int32_t i = 0; i < sizeof(g_errorMessages); i++) { - if(failedReason == g_errorMessages[i].errCode){ + if (failedReason == g_errorMessages[i].errCode) { g_errorMessage = g_errorMessages[i].errMsg; } } From 5350d187804e0358303253748c3560dc78c68b76 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Fri, 20 May 2022 19:09:23 +0800 Subject: [PATCH 6/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- common/include/dm_constants.h | 31 ---------------- utils/BUILD.gn | 1 - utils/src/dm_error_message.cpp | 65 +++++++++++++++++----------------- 3 files changed, 33 insertions(+), 64 deletions(-) diff --git a/common/include/dm_constants.h b/common/include/dm_constants.h index 6651e13f..4ff3d02b 100755 --- a/common/include/dm_constants.h +++ b/common/include/dm_constants.h @@ -199,37 +199,6 @@ const int32_t MAX_EVENT_NUMBER = 10; const int32_t EXPAND_TWICE = 2; const int32_t SEC_TO_MM = 1000; const int32_t MAX_EVENTS = 5; - -// error code info -const std::string DM_FAILED_INFO = "dm process execution failed."; -const std::string DM_TIME_OUT_INFO = "dm process execution timeout."; -const std::string DM_NOT_INIT_INFO = "dm service is not initialized, please try again later."; -const std::string DM_INIT_REPEATED_INFO = "dm service repeated initialization."; -const std::string DM_INIT_FAILED_INFO = "dm service initialize failed."; -const std::string DM_UNINIT_FAILED_INFO = "dm Service uninitialization failed."; -const std::string DM_POINT_NULL_INFO = "dm service null pointer exception occurred."; -const std::string DM_INPUT_PARAMETER_EMPTY_INFO = "the function call input parameter is empty."; -const std::string DM_NO_PERMISSION_INFO = "no permission for function call."; -const std::string DM_MALLOC_FAILED_INFO = "memory allocation failed."; -const std::string DM_DISCOVERY_FAILED_INFO = "device discovery failed."; -const std::string DM_MAP_KEY_ALREADY_EXISTS_INFO = "map key already exists."; -const std::string DM_PROFILE_EVENTS_FAILED_INFO = "process profile events failed."; -const std::string DM_IPC_WRITE_FAILED_INFO = "ipc write object failed."; -const std::string DM_IPC_COPY_FAILED_INFO = "ipc copy data failed."; -const std::string DM_IPC_SEND_REQUEST_FAILED_INFO = "ipc send request failed."; -const std::string DM_UNSUPPORTED_IPC_COMMAND_INFO = "ipc command not supported."; -const std::string DM_IPC_RESPOND_FAILED_INFO = "ipc process failed to receive response."; -const std::string DM_IPC_WRITE_TOKEN_INFO = "ipc write token failed."; -const std::string DM_DISCOVERY_REPEATED_INFO = "repeat device discovery warning."; -const std::string DM_UNSUPPORTED_AUTH_TYPE_INFO = "auth type not supported."; -const std::string DM_AUTH_BUSINESS_BUSY_INFO = "authentication service is busy."; -const std::string DM_AUTH_OPEN_SESSION_FAILED_INFO = "open auth session failed."; -const std::string DM_AUTH_PEER_REJECT_INFO = "remote device refused to authorization."; -const std::string DM_AUTH_REJECT_INFO = "local device refused to authorization."; -const std::string DM_AUTH_FAILED_INFO = "authentication failed."; -const std::string DM_AUTH_NOT_START_INFO = "auth process not started."; -const std::string DM_AUTH_MESSAGE_INCOMPLETE_INFO = "authentication message is incomplete."; -const std::string DM_CREATE_GROUP_FAILED_INFO = "create group failed."; } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_CONSTANTS_H diff --git a/utils/BUILD.gn b/utils/BUILD.gn index a938e8ff..fe0ae501 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -90,7 +90,6 @@ if (defined(ohos_lite)) { "//foundation/communication/dsoftbus/interfaces/kits/transport", "//foundation/communication/dsoftbus/interfaces/inner_kits/transport", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//utils/include/dm_error_message", ] sources = [ "src/dm_anonymous.cpp", diff --git a/utils/src/dm_error_message.cpp b/utils/src/dm_error_message.cpp index a5a516af..17c2d474 100644 --- a/utils/src/dm_error_message.cpp +++ b/utils/src/dm_error_message.cpp @@ -23,46 +23,47 @@ typedef struct ERROR_INFO { } ERROR_INFO; static ERROR_INFO g_errorMessages[] = { - {ERR_DM_FAILED, DM_FAILED_INFO}, - {ERR_DM_TIME_OUT, DM_TIME_OUT_INFO}, - {ERR_DM_NOT_INIT, DM_NOT_INIT_INFO}, - {ERR_DM_INIT_REPEATED, DM_INIT_REPEATED_INFO}, - {ERR_DM_INIT_FAILED, DM_INIT_FAILED_INFO}, - {ERR_DM_UNINIT_FAILED, DM_UNINIT_FAILED_INFO}, - {ERR_DM_POINT_NULL, DM_POINT_NULL_INFO}, - {ERR_DM_INPUT_PARAMETER_EMPTY, DM_INPUT_PARAMETER_EMPTY_INFO}, - {ERR_DM_NO_PERMISSION, DM_NO_PERMISSION_INFO}, - {ERR_DM_MALLOC_FAILED, DM_MALLOC_FAILED_INFO}, - {ERR_DM_DISCOVERY_FAILED, DM_DISCOVERY_FAILED_INFO}, - {ERR_DM_MAP_KEY_ALREADY_EXISTS, DM_MAP_KEY_ALREADY_EXISTS_INFO}, - {DM_PROFILE_EVENTS_FAILED, DM_PROFILE_EVENTS_FAILED_INFO}, - {ERR_DM_IPC_WRITE_FAILED, DM_IPC_WRITE_FAILED_INFO}, - {ERR_DM_IPC_COPY_FAILED, DM_IPC_COPY_FAILED_INFO}, - {ERR_DM_IPC_SEND_REQUEST_FAILED, DM_IPC_SEND_REQUEST_FAILED_INFO}, - {ERR_DM_UNSUPPORTED_IPC_COMMAND, DM_UNSUPPORTED_IPC_COMMAND_INFO}, - {ERR_DM_IPC_RESPOND_FAILED, DM_IPC_RESPOND_FAILED_INFO}, - {ERR_DM_IPC_WRITE_TOKEN_FAILED, DM_IPC_WRITE_TOKEN_INFO}, - {ERR_DM_DISCOVERY_REPEATED, DM_DISCOVERY_REPEATED_INFO}, - {ERR_DM_UNSUPPORTED_AUTH_TYPE, DM_UNSUPPORTED_AUTH_TYPE_INFO}, - {ERR_DM_AUTH_BUSINESS_BUSY, DM_AUTH_BUSINESS_BUSY_INFO}, - {ERR_DM_AUTH_OPEN_SESSION_FAILED, DM_AUTH_OPEN_SESSION_FAILED_INFO}, - {ERR_DM_AUTH_PEER_REJECT, DM_AUTH_PEER_REJECT_INFO}, - {ERR_DM_AUTH_REJECT, DM_AUTH_REJECT_INFO}, - {ERR_DM_AUTH_FAILED, DM_AUTH_FAILED_INFO}, - {ERR_DM_AUTH_NOT_START, DM_AUTH_NOT_START_INFO}, - {ERR_DM_AUTH_MESSAGE_INCOMPLETE, DM_AUTH_MESSAGE_INCOMPLETE_INFO}, - {ERR_DM_CREATE_GROUP_FAILED, DM_CREATE_GROUP_FAILED_INFO}, + {ERR_DM_FAILED, "dm process execution failed."}, + {ERR_DM_TIME_OUT, "dm process execution timeout."}, + {ERR_DM_NOT_INIT, "dm service is not initialized, please try again later."}, + {ERR_DM_INIT_REPEATED, "dm service repeated initialization."}, + {ERR_DM_INIT_FAILED, "dm service initialize failed."}, + {ERR_DM_UNINIT_FAILED, "dm Service uninitialization failed."}, + {ERR_DM_POINT_NULL, "dm service null pointer exception occurred."}, + {ERR_DM_INPUT_PARAMETER_EMPTY, "the function call input parameter is empty."}, + {ERR_DM_NO_PERMISSION, "no permission for function call."}, + {ERR_DM_MALLOC_FAILED, "memory allocation failed."}, + {ERR_DM_DISCOVERY_FAILED, "device discovery failed."}, + {ERR_DM_MAP_KEY_ALREADY_EXISTS, "map key already exists."}, + {DM_PROFILE_EVENTS_FAILED, "process profile events failed."}, + {ERR_DM_IPC_WRITE_FAILED, "ipc write object failed."}, + {ERR_DM_IPC_COPY_FAILED, "ipc copy data failed."}, + {ERR_DM_IPC_SEND_REQUEST_FAILED, "ipc send request failed."}, + {ERR_DM_UNSUPPORTED_IPC_COMMAND, "ipc command not supported."}, + {ERR_DM_IPC_RESPOND_FAILED, "ipc process failed to receive response."}, + {ERR_DM_IPC_WRITE_TOKEN_FAILED, "ipc write token failed."}, + {ERR_DM_DISCOVERY_REPEATED, "repeat device discovery warning."}, + {ERR_DM_UNSUPPORTED_AUTH_TYPE, "auth type not supported."}, + {ERR_DM_AUTH_BUSINESS_BUSY, "authentication service is busy."}, + {ERR_DM_AUTH_OPEN_SESSION_FAILED, "open auth session failed."}, + {ERR_DM_AUTH_PEER_REJECT, "remote device refused to authorization."}, + {ERR_DM_AUTH_REJECT, "local device refused to authorization."}, + {ERR_DM_AUTH_FAILED, "authentication failed."}, + {ERR_DM_AUTH_NOT_START, "auth process not started."}, + {ERR_DM_AUTH_MESSAGE_INCOMPLETE, "authentication message is incomplete."}, + {ERR_DM_CREATE_GROUP_FAILED, "create group failed."}, }; std::string GetErrorString(int failedReason) { - std::string g_errorMessage = "dm process execution failed."; + std::string errorMessage = "dm process execution failed."; for (int32_t i = 0; i < sizeof(g_errorMessages); i++) { if (failedReason == g_errorMessages[i].errCode) { - g_errorMessage = g_errorMessages[i].errMsg; + errorMessage = g_errorMessages[i].errMsg; + break; } } - return g_errorMessage; + return errorMessage; } } // namespace DistributedHardware } // namespace OHOS From ac763e54687a4d35b2888006c640a9e8d09842aa Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Mon, 23 May 2022 17:53:37 +0800 Subject: [PATCH 7/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- utils/BUILD.gn | 1 - utils/src/dm_error_message.cpp | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/utils/BUILD.gn b/utils/BUILD.gn index fe0ae501..3642053a 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -128,7 +128,6 @@ if (defined(ohos_lite)) { "${common_path}/include/ipc/model", "include/permission/standard", "//third_party/mbedtls/include/mbedtls", - "//utils/include/dm_error_message", ] } diff --git a/utils/src/dm_error_message.cpp b/utils/src/dm_error_message.cpp index 17c2d474..40008196 100644 --- a/utils/src/dm_error_message.cpp +++ b/utils/src/dm_error_message.cpp @@ -56,7 +56,7 @@ static ERROR_INFO g_errorMessages[] = { std::string GetErrorString(int failedReason) { - std::string errorMessage = "dm process execution failed."; + std::string errorMessage = "undefined error code."; for (int32_t i = 0; i < sizeof(g_errorMessages); i++) { if (failedReason == g_errorMessages[i].errCode) { errorMessage = g_errorMessages[i].errMsg; From 901409ca2f8b62a46433327a7f56489ddd3410fa Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Tue, 24 May 2022 09:20:07 +0800 Subject: [PATCH 8/8] =?UTF-8?q?=E5=88=A0=E9=99=A4=E5=A4=9A=E4=BD=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- utils/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/utils/BUILD.gn b/utils/BUILD.gn index 3642053a..ff1b4842 100644 --- a/utils/BUILD.gn +++ b/utils/BUILD.gn @@ -37,7 +37,6 @@ if (defined(ohos_lite)) { "//base/hiviewdfx/hilog_lite/interfaces/native/innerkits", "//third_party/bounds_checking_function/include", "//foundation/distributedschedule/samgr_lite/interfaces/kits/samgr", - "//utils/include/dm_error_message", ] sources = [