From 043154bb9a2be83f2809381229a7ae9631ddb896 Mon Sep 17 00:00:00 2001 From: xxxx Date: Mon, 19 Sep 2022 14:35:03 +0800 Subject: [PATCH] Description:fix static scanning issues. Match-id-a12e8551fc8372cb182553c08027e09cbc18265b --- README_zh.md | 26 ++-- common/include/dinput_struct_data.cpp | 57 --------- common/include/dinput_struct_data.h | 38 ------ common/include/input_hub.cpp | 52 ++------ common/include/input_hub.h | 3 - common/include/white_list_util.cpp | 33 +---- common/include/white_list_util.h | 7 +- .../include/i_start_stop_result_call_back.h | 1 - interfaces/inner_kits/BUILD.gn | 1 - interfaces/inner_kits/test/unittest/BUILD.gn | 1 - .../ipc/src/distributed_input_client.cpp | 4 +- .../src/distributed_input_sink_manager.cpp | 14 +- .../src/distributed_input_sink_switch.cpp | 14 +- services/source/inputinject/BUILD.gn | 1 - .../include/distributed_input_inject.h | 1 - services/source/sourcemanager/BUILD.gn | 1 - .../src/distributed_input_source_manager.cpp | 120 ++++++++---------- .../test/sourcemanagerunittest/BUILD.gn | 1 - .../distributed_input_source_transport.h | 1 + .../distributed_input_source_transport.cpp | 27 ++-- 20 files changed, 113 insertions(+), 290 deletions(-) delete mode 100644 common/include/dinput_struct_data.cpp delete mode 100644 common/include/dinput_struct_data.h diff --git a/README_zh.md b/README_zh.md index 32a5e21..1e9a280 100644 --- a/README_zh.md +++ b/README_zh.md @@ -35,8 +35,11 @@ ``` /foundation/distributedhardware/distributed_input ├── common # 分布式输入常量定义和公共函数 +├── dfx_utils # 分布式输入实现DFX业务的相关实现 ├── frameworks # 分布式输入innerkit接口使用到的回调函数定义 ├── inputdevicehandler # 分布式输入实现分布式硬件管理框架定义的能力查询接口实现 +├── interfaces # 分布式输入实现对外接口模块 +├── low_latency # 分布式输入实现输入事件跨设备低时延传输能力业务 ├── sa_profile # 分布式输入的SA配置信息 ├── services # 分布式输入的SA具体实现 │ └── common # 分布式输入实现用到的公共常量定义 @@ -50,13 +53,14 @@ │ └── transport # 分布式输入source侧事件接收 ├── sinkhandler # 分布式输入实现的分布式硬件管理框架定义的sink侧部件接入接口 ├── sourcehandler # 分布式输入实现的分布式硬件管理框架定义的source侧部件接入接口 -└── test # 分布式输入的外部接口UT用例 +└── test # 分布式输入fuzz测试的实现 +├── utils # 分布式输入工具类的实现 ``` ## **约束** -**语言限制**:C++语言。 -**组网环境**:必须确保设备在同一个局域网中。 -**操作系统限制**:OpenHarmony操作系统。 +**语言限制**:C++语言。 +**组网环境**:必须确保设备在同一个局域网中。 +**操作系统限制**:OpenHarmony操作系统。 ## **说明** ### **接口说明** @@ -80,21 +84,21 @@ #### **4. 设备下线** 设备下线后,分布式硬件管理框架去使能下线设备的输入外设,移除分布式输入驱动,此时下线设备的分布式输入外设不可用。 -## **涉及仓** +## **相关仓** **** -**分布式硬件子系统:** +**分布式硬件子系统:** 设备管理 -[device_manager](https://gitee.com/openharmony/device_manager) +[device_manager](https://gitee.com/openharmony/distributedhardware_device_manager) 分步式硬件管理框架 -[distributed_hardware_fwk](https://gitee.com/openharmony/distributed_hardware_fwk) +[distributed_hardware_fwk](https://gitee.com/openharmony/distributedhardware_distributed_hardware_fwk) 分布式相机 -[distributed_camera](https://gitee.com/openharmony/distributed_camera) +[distributed_camera](https://gitee.com/openharmony/distributedhardware_distributed_camera) 分布式屏幕 -[distributed_screen](https://gitee.com/openharmony/distributed_screen) +[distributed_screen](https://gitee.com/openharmony/distributedhardware_distributed_screen) **分布式输入 -[distributed_input](https://gitee.com/openharmony-sig/distributed_input)** +[distributed_input](http://mgit-tm.rnd.huawei.com/hmf/distributedhardware/distributed_input)** diff --git a/common/include/dinput_struct_data.cpp b/common/include/dinput_struct_data.cpp deleted file mode 100644 index ad3c6c1..0000000 --- a/common/include/dinput_struct_data.cpp +++ /dev/null @@ -1,57 +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 "dinput_struct_data.h" -#include "distributed_hardware_log.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -StringDeviceData::StringDeviceData() : dhname_(""), status(0) {} - -bool StringDeviceData::Marshalling(Parcel &parcel) const -{ - if (!parcel.WriteString(dhname_)) { - DHLOGE("StringDeviceData-Marshalling write dhname_ failed"); - return false; - } - if (!parcel.WriteInt32(status)) { - DHLOGE("StringDeviceData-Marshalling write status failed"); - return false; - } - return true; -} - -sptr StringDeviceData::Unmarshalling(Parcel &parcel) -{ - sptr ptr = (std::make_unique()).release(); - if (ptr == nullptr) { - DHLOGE("StringDeviceData-Unmarshalling create ptr is null."); - return nullptr; - } - - if (!parcel.ReadString(ptr->dhname_)) { - DHLOGE("StringDeviceData-Unmarshalling read dhname_ failed."); - return nullptr; - } - if (!parcel.ReadInt32(ptr->status)) { - DHLOGE("StringDeviceData-Unmarshalling read status failed."); - return nullptr; - } - return ptr; -} -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS diff --git a/common/include/dinput_struct_data.h b/common/include/dinput_struct_data.h deleted file mode 100644 index ab51f45..0000000 --- a/common/include/dinput_struct_data.h +++ /dev/null @@ -1,38 +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. - */ - -#ifndef D_INPUT_STRUCT_DATA_H -#define D_INPUT_STRUCT_DATA_H - -#include -#include "parcel.h" - -namespace OHOS { -namespace DistributedHardware { -namespace DistributedInput { -class StringDeviceData : public Parcelable { -public: - std::string dhname_; - int32_t status; // 0 is success, -1 is error. - StringDeviceData(); - ~StringDeviceData() = default; - bool Marshalling(Parcel &parcel) const override; - static sptr Unmarshalling(Parcel &parcel); -}; -} // namespace DistributedInput -} // namespace DistributedHardware -} // namespace OHOS - -#endif // D_INPUT_STRUCT_DATA_H diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 19bab0f..da756f3 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -680,6 +680,7 @@ std::string InputHub::StringPrintf(const char* format, ...) const if (ret >= DH_SUCCESS && static_cast(ret) < sizeof(space)) { result = space; } else { + va_end(ap); return "the buffer is overflow!"; } va_end(ap); @@ -793,7 +794,6 @@ int32_t InputHub::ReadNotifyLocked() { size_t res; char eventBuf[512]; - size_t eventSize; size_t eventPos = 0; struct inotify_event *event; @@ -807,12 +807,15 @@ int32_t InputHub::ReadNotifyLocked() return ERR_DH_INPUT_HUB_GET_EVENT_FAIL; } - while (res >= sizeof(*event)) { - event = reinterpret_cast(eventBuf + eventPos); - JudgeDeviceOpenOrClose(*event); - eventSize = sizeof(*event) + event->len; - res -= eventSize; - eventPos += eventSize; + { + size_t eventSize; + while (res >= sizeof(*event)) { + event = reinterpret_cast(eventBuf + eventPos); + JudgeDeviceOpenOrClose(*event); + eventSize = sizeof(*event) + event->len; + res -= eventSize; + eventPos += eventSize; + } } return DH_SUCCESS; } @@ -855,24 +858,6 @@ void InputHub::CloseAllDevicesLocked() } } -InputHub::Device* InputHub::GetDeviceByDescriptorLocked(const std::string& descriptor) -{ - std::unique_lock deviceLock(devicesMutex_); - for (const auto& device : openingDevices_) { - if (device && descriptor == device->identifier.descriptor) { - return device.get(); - } - } - - for (const auto& [id, device] : devices_) { - if (device && descriptor == device->identifier.descriptor) { - return device.get(); - } - } - - return nullptr; -} - InputHub::Device* InputHub::GetDeviceByPathLocked(const std::string& devicePath) { std::unique_lock deviceLock(devicesMutex_); @@ -937,11 +922,6 @@ uint32_t InputHub::SizeofBitArray(uint32_t bit) return ((bit) + round) / divisor; } -bool InputHub::IsSupportInputTypes(uint32_t classes) -{ - return classes & inputTypes_; -} - void InputHub::SaveAffectDhId(bool isEnable, const std::string &dhId, AffectDhIds &affDhIds) { if (isEnable) { @@ -968,18 +948,6 @@ AffectDhIds InputHub::SetSupportInputType(bool enabled, const uint32_t &inputTyp return affDhIds; } -void InputHub::GetDeviceDhIdByFd(int32_t fd, std::string &dhId) -{ - std::unique_lock deviceLock(devicesMutex_); - for (const auto &[id, device] : devices_) { - if (device->fd == fd) { - dhId = device->identifier.descriptor; - return; - } - } - dhId.clear(); -} - AffectDhIds InputHub::SetSharingDevices(bool enabled, std::vector dhIds) { AffectDhIds affDhIds; diff --git a/common/include/input_hub.h b/common/include/input_hub.h index 52ab7fc..34a9d9b 100644 --- a/common/include/input_hub.h +++ b/common/include/input_hub.h @@ -50,7 +50,6 @@ public: AffectDhIds SetSupportInputType(bool enabled, const uint32_t &inputTypes); // return efftive dhids AffectDhIds SetSharingDevices(bool enabled, std::vector dhIds); - void GetDeviceDhIdByFd(int32_t fd, std::string &dhId); void GetDevicesInfoByType(const uint32_t inputTypes, std::map &datas); void GetDevicesInfoByDhId(std::vector dhidsVec, std::map &datas); void GetShareMousePathByDhId(std::vector dhIds, std::string &path, std::string &dhId); @@ -112,7 +111,6 @@ private: void CloseDeviceByPathLocked(const std::string& devicePath); void CloseAllDevicesLocked(); void JudgeDeviceOpenOrClose(const inotify_event& event); - Device* GetDeviceByDescriptorLocked(const std::string& descriptor); Device* GetDeviceByPathLocked(const std::string& devicePath); Device* GetDeviceByFdLocked(int fd); Device* GetSupportDeviceByFd(int fd); @@ -129,7 +127,6 @@ private: bool TestBit(uint32_t bit, const uint8_t* array); /* this macro computes the number of bytes needed to represent a bit array of the specified size */ uint32_t SizeofBitArray(uint32_t bit); - bool IsSupportInputTypes(uint32_t classes); void RecordEventLog(const RawEvent* event); void RecordDeviceLog(const int32_t deviceId, const std::string& devicePath, const InputDevice& identifier); void HandleTouchScreenEvent(struct input_event readBuffer[], const size_t count, std::vector& needFilted); diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp index f72f698..671f7c7 100644 --- a/common/include/white_list_util.cpp +++ b/common/include/white_list_util.cpp @@ -55,11 +55,9 @@ WhiteListUtil &WhiteListUtil::GetInstance(void) int32_t WhiteListUtil::Init() { - const char* const whiteListFilePath = - "/vendor/etc/distributedhardware/dinput_business_event_whitelist.cfg"; + const char* const whiteListFilePath = "/vendor/etc/distributedhardware/dinput_business_event_whitelist.cfg"; std::ifstream inFile(whiteListFilePath, std::ios::in | std::ios::binary); if (!inFile.is_open()) { - // file open error DHLOGE("WhiteListUtil Init error, file open fail path=%s", whiteListFilePath); return ERR_DH_INPUT_WHILTELIST_INIT_FAIL; } @@ -114,15 +112,8 @@ int32_t WhiteListUtil::Init() return DH_SUCCESS; } -int32_t WhiteListUtil::UnInit(void) -{ - DHLOGI("WhiteListUtil UnInit called"); - ClearWhiteList(); - return DH_SUCCESS; -} - void WhiteListUtil::ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC &vecKeyCode, - TYPE_COMBINATION_KEY_VEC &vecCombinationKey) const + TYPE_COMBINATION_KEY_VEC &vecCombinationKey) const { std::size_t pos2 = column.find(SPLIT_LINE); while (pos2 != std::string::npos) { @@ -188,8 +179,8 @@ void WhiteListUtil::GetCombKeysHash(TYPE_COMBINATION_KEY_VEC combKeys, std::unor WhiteListItemHash hash; GetAllComb(combKeys, hash, combKeys.size(), hashSets); - for (auto &hash : hashSets) { - targetSet.insert(hash + std::to_string(lastKey[0]) + std::to_string(lastKeyAction[0])); + for (auto &hashSet : hashSets) { + targetSet.insert(hashSet + std::to_string(lastKey[0]) + std::to_string(lastKeyAction[0])); } } @@ -199,7 +190,8 @@ void WhiteListUtil::GetAllComb(TYPE_COMBINATION_KEY_VEC vecs, WhiteListItemHash for (size_t i = 0; i < vecs.size(); i++) { TYPE_KEY_CODE_VEC nowVec = vecs[i]; for (int32_t code : nowVec) { - WhiteListItemHash newHash = { hash.hash + std::to_string(code), hash.len + 1 }; + std::string hashStr = hash.hash + std::to_string(code); + WhiteListItemHash newHash(hashStr, hash.len + 1); TYPE_COMBINATION_KEY_VEC leftVecs = vecs; leftVecs.erase(leftVecs.begin() + i); GetAllComb(leftVecs, newHash, targetLen, hashSets); @@ -243,19 +235,6 @@ int32_t WhiteListUtil::GetWhiteList(const std::string &deviceId, TYPE_WHITE_LIST return ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL; } -bool WhiteListUtil::CheckSubVecData(const TYPE_COMBINATION_KEY_VEC::iterator &iter2, - const TYPE_KEY_CODE_VEC::iterator &iter3) const -{ - bool bIsMatching = false; - for (TYPE_KEY_CODE_VEC::iterator iter4 = iter2->begin(); iter4 != iter2->end(); ++iter4) { - if (*iter4 == *iter3) { - bIsMatching = true; - break; - } - } - return bIsMatching; -} - std::string WhiteListUtil::GetBusinessEventHash(const BusinessEvent &event) { std::string hash = ""; diff --git a/common/include/white_list_util.h b/common/include/white_list_util.h index 6be95e5..8771665 100644 --- a/common/include/white_list_util.h +++ b/common/include/white_list_util.h @@ -37,7 +37,7 @@ struct WhiteListItemHash { WhiteListItemHash() : hash(""), len(0) {} - WhiteListItemHash(std::string hash, int32_t len) : hash(hash), len(len) {} + WhiteListItemHash(std::string &hash, int32_t len) : hash(hash), len(len) {} }; class WhiteListUtil { @@ -58,15 +58,12 @@ public: bool IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event); private: int32_t Init(); - int32_t UnInit(void); WhiteListUtil(); ~WhiteListUtil(); WhiteListUtil(const WhiteListUtil &other) = delete; const WhiteListUtil &operator=(const WhiteListUtil &other) = delete; void ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC &vecKeyCode, - TYPE_COMBINATION_KEY_VEC &vecCombinationKey) const; - bool CheckSubVecData(const TYPE_COMBINATION_KEY_VEC::iterator &iter2, - const TYPE_KEY_CODE_VEC::iterator &iter3) const; + TYPE_COMBINATION_KEY_VEC &vecCombinationKey) const; void GetCombKeysHash(TYPE_COMBINATION_KEY_VEC combKeys, std::unordered_set &targetSet); void GetAllComb(TYPE_COMBINATION_KEY_VEC vecs, WhiteListItemHash hash, int32_t targetLen, std::unordered_set &hashSets); diff --git a/frameworks/include/i_start_stop_result_call_back.h b/frameworks/include/i_start_stop_result_call_back.h index 8890247..05e654c 100644 --- a/frameworks/include/i_start_stop_result_call_back.h +++ b/frameworks/include/i_start_stop_result_call_back.h @@ -19,7 +19,6 @@ #include #include #include -#include "dinput_struct_data.h" namespace OHOS { namespace DistributedHardware { diff --git a/interfaces/inner_kits/BUILD.gn b/interfaces/inner_kits/BUILD.gn index f048241..95936c4 100644 --- a/interfaces/inner_kits/BUILD.gn +++ b/interfaces/inner_kits/BUILD.gn @@ -43,7 +43,6 @@ ohos_shared_library("libdinput_sdk") { sources = [ "${common_path}/include/white_list_util.cpp", - "${common_path}/include/dinput_struct_data.cpp", "${innerkits_path}/src/distributed_input_kit.cpp", "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", diff --git a/interfaces/inner_kits/test/unittest/BUILD.gn b/interfaces/inner_kits/test/unittest/BUILD.gn index 509fec0..a0bc825 100644 --- a/interfaces/inner_kits/test/unittest/BUILD.gn +++ b/interfaces/inner_kits/test/unittest/BUILD.gn @@ -51,7 +51,6 @@ ohos_unittest("distributed_input_inner_test") { sources = [ "${common_path}/include/white_list_util.cpp", - "${common_path}/include/dinput_struct_data.cpp", "${innerkits_path}/src/distributed_input_kit.cpp", "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 48746b3..2c068ec 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -56,7 +56,7 @@ void DistributedInputClient::RegisterDInputCb::OnResult( for (std::vector::iterator iter = DistributedInputClient::GetInstance().dHardWareFwkRstInfos.begin(); iter != DistributedInputClient::GetInstance().dHardWareFwkRstInfos.end(); - iter++) { + ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnRegisterResult(devId, dhId, status, ""); DistributedInputClient::GetInstance().dHardWareFwkRstInfos.erase(iter); @@ -72,7 +72,7 @@ void DistributedInputClient::UnregisterDInputCb::OnResult( for (std::vector::iterator iter = DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.begin(); iter != DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.end(); - iter++) { + ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnUnregisterResult(devId, dhId, status, ""); DistributedInputClient::GetInstance().dHardWareFwkUnRstInfos.erase(iter); diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index 1c3b88c..4e63c09 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -250,7 +250,7 @@ void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInputDhid(cons std::vector stopOnCmdDhIds; StringSplit(strDhids, INPUT_STRING_SPLIT_POINT, stopOnCmdDhIds); sinkManagerObj_->DeleteStopDhids(sessionId, stopOnCmdDhIds, stopIndeedDhIds); - AffectDhIds affDhIds = DistributedInputCollector::GetInstance().SetSharingDhIds(false, stopIndeedDhIds); + (void)DistributedInputCollector::GetInstance().SetSharingDhIds(false, stopIndeedDhIds); AffectDhIds stopIndeedOnes; stopIndeedOnes.noSharingDhIds = stopIndeedDhIds; DistributedInputCollector::GetInstance().ReportDhIdSharingState(stopIndeedOnes); @@ -324,7 +324,6 @@ void DistributedInputSinkManager::DInputSinkListener::CheckKeyState(const int32_ } uint32_t count = 0; - int rc = 0; int leftKeyVal = 0; int rightKeyVal = 0; int midKeyVal = 0; @@ -334,7 +333,7 @@ void DistributedInputSinkManager::DInputSinkListener::CheckKeyState(const int32_ break; } // Query all key state - rc = ioctl(fd, EVIOCGKEY(sizeof(keystate)), keystate); + int rc = ioctl(fd, EVIOCGKEY(sizeof(keystate)), keystate); if (rc < 0) { DHLOGE("read all key state failed, rc=%d ", rc); count += 1; @@ -399,9 +398,8 @@ void DistributedInputSinkManager::DeleteStopDhids(int32_t sessionId, const std:: DHLOGI("DeleteStopDhids sessionId=%d after has dhid.size=%d.", sessionId, sharingDhIdsMap_[sessionId].size()); } // find which dhid can be stop - bool isFind = false; for (auto tmp : stopDhIds) { - isFind = IsStopDhidOnCmdStillNeed(sessionId, tmp); + bool isFind = IsStopDhidOnCmdStillNeed(sessionId, tmp); if (!isFind) { stopIndeedDhIds.push_back(tmp); sharingDhIds_.erase(tmp); @@ -821,10 +819,8 @@ int32_t DistributedInputSinkManager::RegisterSharingDhIdListener(sptr& args) { DHLOGI("DistributedInputSinkManager Dump."); - std::vector argsStr; - for (auto iter : args) { - argsStr.emplace_back(Str16ToStr8(iter)); - } + std::vector argsStr(args.size()); + std::transform(args.begin(), args.end(), argsStr.begin(), [](const auto &item) {return Str16ToStr8(item);}); std::string result(""); if (!HiDumper::GetInstance().HiDump(argsStr, result)) { DHLOGI("Hidump error."); diff --git a/services/sink/transport/src/distributed_input_sink_switch.cpp b/services/sink/transport/src/distributed_input_sink_switch.cpp index 031f154..e0af6b0 100644 --- a/services/sink/transport/src/distributed_input_sink_switch.cpp +++ b/services/sink/transport/src/distributed_input_sink_switch.cpp @@ -56,7 +56,7 @@ int32_t DistributedInputSinkSwitch::StartSwitch(int32_t sessionId) return ERR_DH_INPUT_SERVER_SINK_START_SWITCH_FAIL; } else { bool findOld = false; - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { + for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); ++it) { if ((*it).sessionId == sessionId) { (*it).switchState = true; findOld = true; @@ -81,7 +81,7 @@ void DistributedInputSinkSwitch::StopSwitch(int32_t sessionId) DHLOGE("StopSwitch sessionId: %d fail,switchVector_ is null.", sessionId); } else { bool findOld = false; - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { + for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); ++it) { if ((*it).sessionId == sessionId) { (*it).switchState = false; findOld = true; @@ -103,7 +103,7 @@ void DistributedInputSinkSwitch::StopAllSwitch() if (switchVector_.empty()) { DHLOGW("StopAllSwitch switchVector_ is null."); } else { - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { + for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); ++it) { (*it).switchState = false; } DHLOGI("StopAllSwitch success."); @@ -119,7 +119,7 @@ void DistributedInputSinkSwitch::AddSession(int32_t sessionId) DHLOGI("AddSession sessionId: %d add first.", sessionId); } else { bool findOld = false; - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { + for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); ++it) { if ((*it).sessionId == sessionId) { findOld = true; break; @@ -149,7 +149,7 @@ void DistributedInputSinkSwitch::RemoveSession(int32_t sessionId) findOld = true; break; } else { - it++; + ++it; } } if (findOld) { @@ -164,7 +164,7 @@ std::vector DistributedInputSinkSwitch::GetAllSessionId() { std::unique_lock switchLock(operationMutex_); std::vector tmpVecSession; - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { + for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); ++it) { tmpVecSession.push_back((*it).sessionId); } return tmpVecSession; @@ -178,7 +178,7 @@ int32_t DistributedInputSinkSwitch::GetSwitchOpenedSession() DHLOGE("GetSwitchOpenedSession error, no data."); return ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL; } - for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { + for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); ++it) { if ((*it).switchState == true) { return (*it).sessionId; } diff --git a/services/source/inputinject/BUILD.gn b/services/source/inputinject/BUILD.gn index f58e561..62c77a1 100644 --- a/services/source/inputinject/BUILD.gn +++ b/services/source/inputinject/BUILD.gn @@ -47,7 +47,6 @@ ohos_shared_library("libdinput_inject") { "src/virtual_mouse.cpp", "src/virtual_touchpad.cpp", "src/virtual_touchscreen.cpp", - "${common_path}/include/dinput_struct_data.cpp", ] defines = [ diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index e6448a9..5ec3648 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -23,7 +23,6 @@ #include "constants_dinput.h" #include "distributed_input_handler.h" #include "distributed_input_node_manager.h" -#include "dinput_struct_data.h" #include "i_input_node_listener.h" namespace OHOS { diff --git a/services/source/sourcemanager/BUILD.gn b/services/source/sourcemanager/BUILD.gn index b8d7c2c..cb9f0e3 100644 --- a/services/source/sourcemanager/BUILD.gn +++ b/services/source/sourcemanager/BUILD.gn @@ -49,7 +49,6 @@ ohos_shared_library("libdinput_source") { sources = [ "${common_path}/include/white_list_util.cpp", - "${common_path}/include/dinput_struct_data.cpp", "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", "${ipc_path}/src/del_white_list_infos_call_back_proxy.cpp", diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index 5820c25..7528095 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -15,6 +15,7 @@ #include "distributed_input_source_manager.h" +#include #include #include #include @@ -332,7 +333,7 @@ void DistributedInputSourceManager::DInputSourceListener::onReceivedEventRemoteI RawEvent mEventBuffer[jsonSize]; int idx = 0; - for (nlohmann::json::iterator it = inputData.begin(); it != inputData.end(); ++it) { + for (auto it = inputData.begin(); it != inputData.end(); ++it) { nlohmann::json oneData = (*it); mEventBuffer[idx].when = oneData[INPUT_KEY_WHEN]; mEventBuffer[idx].type = oneData[INPUT_KEY_TYPE]; @@ -342,7 +343,7 @@ void DistributedInputSourceManager::DInputSourceListener::onReceivedEventRemoteI mEventBuffer[idx].path = oneData[INPUT_KEY_PATH]; RecordEventLog(oneData[INPUT_KEY_WHEN], oneData[INPUT_KEY_TYPE], oneData[INPUT_KEY_CODE], oneData[INPUT_KEY_VALUE], oneData[INPUT_KEY_PATH]); - idx++; + ++idx; } DistributedInputInject::GetInstance().RegisterDistributedEvent(mEventBuffer, jsonSize); } @@ -401,7 +402,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRegis const AppExecFwk::InnerEvent::Pointer &event) { std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID]; @@ -410,8 +411,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRegis InputDeviceId inputDeviceId {deviceId, dhId}; std::vector tmpInputDevId = sourceManagerObj_->GetInputDeviceId(); // Find out if the dh exists - std::vector::iterator devIt = std::find( - tmpInputDevId.begin(), tmpInputDevId.end(), inputDeviceId); + auto devIt = std::find(tmpInputDevId.begin(), tmpInputDevId.end(), inputDeviceId); if (devIt != tmpInputDevId.end()) { if (result == false) { sourceManagerObj_->RemoveInputDeviceId(deviceId, dhId); @@ -429,7 +429,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnreg const AppExecFwk::InnerEvent::Pointer &event) { std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; std::string dhId = innerMsg[INPUT_SOURCEMANAGER_KEY_HWID]; @@ -445,7 +445,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyPrepa const AppExecFwk::InnerEvent::Pointer &event) { std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; @@ -459,7 +459,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyUnpre const AppExecFwk::InnerEvent::Pointer &event) { std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; bool result = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; @@ -474,7 +474,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart const AppExecFwk::InnerEvent::Pointer &event) { std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP]; @@ -495,7 +495,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopC const AppExecFwk::InnerEvent::Pointer &event) { std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; uint32_t inputTypes = innerMsg[INPUT_SOURCEMANAGER_KEY_ITP]; @@ -528,7 +528,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart { DHLOGI("ProcessEvent NotifyStartDhidCallback()"); std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; @@ -545,7 +545,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStopD { DHLOGI("ProcessEvent NotifyStopDhidCallback()"); std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; std::string dhidStr = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; @@ -562,7 +562,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyKeySt { DHLOGI("ProcessEvent NotifyKeyStateCallback()"); std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); std::string deviceId = innerMsg[INPUT_SOURCEMANAGER_KEY_DEVID]; std::string dhid = innerMsg[INPUT_SOURCEMANAGER_KEY_DHID]; @@ -578,7 +578,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart const AppExecFwk::InnerEvent::Pointer &event) { std::shared_ptr dataMsg = event->GetSharedObject(); - nlohmann::json::iterator it = dataMsg->begin(); + auto it = dataMsg->begin(); nlohmann::json innerMsg = *(it); int32_t serType = innerMsg[INPUT_SOURCEMANAGER_KEY_RESULT]; DInputServerType startTransFlag = DInputServerType(serType); @@ -677,7 +677,7 @@ int32_t DistributedInputSourceManager::Release() DHLOGI("exit"); // 1.remove input node - for (std::vector::iterator iter = inputDevice_.begin(); iter != inputDevice_.end(); ++iter) { + for (auto iter = inputDevice_.begin(); iter != inputDevice_.end(); ++iter) { std::string devId = iter->devId; std::string dhId = iter->dhId; DHLOGI("Release() devId[%s] dhId[%s]", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); @@ -757,7 +757,7 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); // 1.Find out if the dh exists - std::vector::iterator it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); + auto it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); if (it != inputDevice_.end()) { callback->OnResult(devId, dhId, DH_SUCCESS); return DH_SUCCESS; @@ -771,7 +771,7 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st "dinput register distributed hardware failed in create input node."); DHLOGE("RegisterDistributedHardware called, create node fail."); - for (auto iter = regCallbacks_.begin(); iter != regCallbacks_.end(); iter++) { + for (auto iter = regCallbacks_.begin(); iter != regCallbacks_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnResult(iter->devId, iter->dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL); regCallbacks_.erase(iter); @@ -803,7 +803,7 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st void DistributedInputSourceManager::handleStartServerCallback(const std::string& devId) { bool isFindDevice = false; - for (std::vector::iterator iter = inputDevice_.begin(); iter != inputDevice_.end(); ++iter) { + for (auto iter = inputDevice_.begin(); iter != inputDevice_.end(); ++iter) { if (devId == iter->devId) { isFindDevice = true; break; @@ -813,7 +813,7 @@ void DistributedInputSourceManager::handleStartServerCallback(const std::string& DeviceMap_[devId] = DINPUT_SOURCE_SWITCH_OFF; // DeviceMap_ all sink device switch is off,call isstart's callback bool isAllDevSwitchOff = true; - for (auto it = DeviceMap_.begin(); it != DeviceMap_.end(); it++) { + for (auto it = DeviceMap_.begin(); it != DeviceMap_.end(); ++it) { if (it->second == DINPUT_SOURCE_SWITCH_ON) { isAllDevSwitchOff = false; break; @@ -838,7 +838,7 @@ void DistributedInputSourceManager::handleStartServerCallback(const std::string& int32_t DistributedInputSourceManager::UnregCallbackNotify(const std::string &devId, const std::string &dhId) { - for (auto iter = unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) { + for (auto iter = unregCallbacks_.begin(); iter != unregCallbacks_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { iter->callback->OnResult(iter->devId, iter->dhId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL); unregCallbacks_.erase(iter); @@ -923,7 +923,7 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std:: InputDeviceId inputDeviceId {devId, dhId}; DHLOGI("Unregister deviceId: %s, dhId: %s", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); - std::vector::iterator it = inputDevice_.begin(); + auto it = inputDevice_.begin(); if (CheckDeviceIsExists(devId, dhId, inputDeviceId, it) != DH_SUCCESS) { DHLOGE("Unregister deviceId: %s is not exist.", GetAnonyString(devId).c_str()); HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_UNREGISTER_FAIL, devId, dhId, @@ -986,7 +986,7 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput( ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL, "dinput prepare failed in transport prepare"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_PREPARE_START, DINPUT_PREPARE_TASK); DHLOGE("Can not send message by softbus, prepare fail."); - for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); iter++) { + for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); ++iter) { if (iter->devId == deviceId) { iter->preCallback->OnResult(iter->devId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL); preCallbacks_.erase(iter); @@ -1035,7 +1035,7 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput( HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL, "dinput unprepare failed in transport unprepare"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_UNPREPARE_START, DINPUT_UNPREPARE_TASK); - for (auto iter = unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); iter++) { + for (auto iter = unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); ++iter) { if (iter->devId == deviceId) { iter->unpreCallback->OnResult(iter->devId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL); unpreCallbacks_.erase(iter); @@ -1083,8 +1083,7 @@ int32_t DistributedInputSourceManager::StartRemoteInput( ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "dinput start use failed in transport start"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); DHLOGE("Start fail."); - for (std::vector::iterator iter = - staCallbacks_.begin(); iter != staCallbacks_.end(); iter++) { + for (auto iter = staCallbacks_.begin(); iter != staCallbacks_.end(); ++iter) { if (iter->devId == deviceId && iter->inputTypes == inputTypes) { iter->callback->OnResult(iter->devId, iter->inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL); staCallbacks_.erase(iter); @@ -1131,8 +1130,7 @@ int32_t DistributedInputSourceManager::StopRemoteInput( HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, deviceId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "dinput stop use failed in transport stop"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - for (std::vector::iterator iter = - stpCallbacks_.begin(); iter != stpCallbacks_.end(); iter++) { + for (auto iter = stpCallbacks_.begin(); iter != stpCallbacks_.end(); ++iter) { if (iter->devId == deviceId && iter->inputTypes == inputTypes) { iter->callback->OnResult(iter->devId, iter->inputTypes, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL); stpCallbacks_.erase(iter); @@ -1190,7 +1188,7 @@ int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &srcId ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "dinput start use failed in transport start"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); DHLOGE("StartRemoteInput called, start fail."); - for (auto it = staCallbacks_.begin(); it != staCallbacks_.end(); it++) { + for (auto it = staCallbacks_.begin(); it != staCallbacks_.end(); ++it) { if (it->devId == sinkId && it->inputTypes == inputTypes) { staCallbacks_.erase(it); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; @@ -1244,7 +1242,7 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &srcId, HisyseventUtil::GetInstance().SysEventWriteFault(DINPUT_OPT_FAIL, sinkId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "dinput stop use failed in transport stop"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - for (auto it = stpCallbacks_.begin(); it != stpCallbacks_.end(); it++) { + for (auto it = stpCallbacks_.begin(); it != stpCallbacks_.end(); ++it) { if (it->devId == sinkId && it->inputTypes == inputTypes) { stpCallbacks_.erase(it); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; @@ -1347,7 +1345,7 @@ int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string &src ret = DistributedInputSourceTransport::GetInstance().PrepareRemoteInput(sinkId); if (ret != DH_SUCCESS) { DHLOGE("Can not send message by softbus, prepare fail."); - for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); iter++) { + for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); ++iter) { if (iter->devId == sinkId) { preCallbacks_.erase(iter); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; @@ -1399,7 +1397,7 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string &s int32_t ret = DistributedInputSourceTransport::GetInstance().UnprepareRemoteInput(sinkId); if (ret != DH_SUCCESS) { DHLOGE("Can not send message by softbus, unprepare fail."); - for (auto iter = unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); iter++) { + for (auto iter = unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); ++iter) { if (iter->devId == sinkId) { unpreCallbacks_.erase(iter); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; @@ -1419,7 +1417,7 @@ bool DistributedInputSourceManager::IsStringDataSame(const std::vector::iterator it = find(newDhIds.begin(), newDhIds.end(), oDhid); + auto it = find(newDhIds.begin(), newDhIds.end(), oDhid); if (it == newDhIds.end()) { isSame = false; break; @@ -1475,7 +1473,7 @@ int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &sinkI ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "dinput start use failed in transport start"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); DHLOGE("StartRemoteInput start fail."); - for (auto iter = staStringCallbacks_.begin(); iter != staStringCallbacks_.end(); iter++) { + for (auto iter = staStringCallbacks_.begin(); iter != staStringCallbacks_.end(); ++iter) { if (iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) { staStringCallbacks_.erase(iter); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; @@ -1528,7 +1526,7 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &sinkId ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "dinput stop use failed in transport stop"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); DHLOGE("StopRemoteInput stop fail."); - for (auto iter = stpStringCallbacks_.begin(); iter != stpStringCallbacks_.end(); iter++) { + for (auto iter = stpStringCallbacks_.begin(); iter != stpStringCallbacks_.end(); ++iter) { if (iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) { stpStringCallbacks_.erase(iter); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; @@ -1586,7 +1584,7 @@ int32_t DistributedInputSourceManager::StartRemoteInput(const std::string &srcId ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL, "dinput start use failed in transport start"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); DHLOGE("StartRemoteInput start fail."); - for (auto iter = staStringCallbacks_.begin(); iter != staStringCallbacks_.end(); iter++) { + for (auto iter = staStringCallbacks_.begin(); iter != staStringCallbacks_.end(); ++iter) { if (iter->srcId == srcId && iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) { staStringCallbacks_.erase(iter); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; @@ -1640,7 +1638,7 @@ int32_t DistributedInputSourceManager::StopRemoteInput(const std::string &srcId, ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL, "dinput stop use failed in transport stop"); FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); DHLOGE("StopRemoteInput stop fail."); - for (auto iter = stpStringCallbacks_.begin(); iter != stpStringCallbacks_.end(); iter++) { + for (auto iter = stpStringCallbacks_.begin(); iter != stpStringCallbacks_.end(); ++iter) { if (iter->srcId == srcId && iter->sinkId == sinkId && IsStringDataSame(iter->dhIds, dhIds)) { stpStringCallbacks_.erase(iter); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; @@ -1847,8 +1845,7 @@ void DistributedInputSourceManager::RunRegisterCallback( const std::string& devId, const std::string& dhId, const int32_t& status) { std::lock_guard lock(operationMutex_); - for (std::vector::iterator iter = - regCallbacks_.begin(); iter != regCallbacks_.end(); iter++) { + for (auto iter = regCallbacks_.begin(); iter != regCallbacks_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_RIGISTER_MSG"); iter->callback->OnResult(devId, dhId, status); @@ -1864,8 +1861,7 @@ void DistributedInputSourceManager::RunUnregisterCallback( const std::string& devId, const std::string& dhId, const int32_t& status) { std::lock_guard lock(operationMutex_); - for (std::vector::iterator iter = - unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) { + for (auto iter = unregCallbacks_.begin(); iter != unregCallbacks_.end(); ++iter) { if (iter->devId == devId && iter->dhId == dhId) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_UNRIGISTER_MSG"); iter->callback->OnResult(devId, dhId, status); @@ -1881,8 +1877,7 @@ void DistributedInputSourceManager::RunPrepareCallback( const std::string& devId, const int32_t& status, const std::string& object) { FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_PREPARE_START, DINPUT_PREPARE_TASK); - for (std::vector::iterator iter = - preCallbacks_.begin(); iter != preCallbacks_.end(); iter++) { + for (auto iter = preCallbacks_.begin(); iter != preCallbacks_.end(); ++iter) { if (iter->devId == devId) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_PREPARE_MSG"); iter->preCallback->OnResult(devId, status); @@ -1892,8 +1887,8 @@ void DistributedInputSourceManager::RunPrepareCallback( DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_PREPARE_MSG addWhiteListCallback is null."); return; } - for (const auto& iter : addWhiteListCallbacks_) { - iter->OnResult(devId, object); + for (const auto& it : addWhiteListCallbacks_) { + it->OnResult(devId, object); } return; } @@ -1905,8 +1900,7 @@ void DistributedInputSourceManager::RunPrepareCallback( void DistributedInputSourceManager::RunUnprepareCallback(const std::string &devId, const int32_t &status) { FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_UNPREPARE_START, DINPUT_UNPREPARE_TASK); - for (std::vector::iterator iter = - unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); iter++) { + for (auto iter = unpreCallbacks_.begin(); iter != unpreCallbacks_.end(); ++iter) { if (iter->devId == devId) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_UNPREPARE_MSG"); iter->unpreCallback->OnResult(devId, status); @@ -1916,8 +1910,8 @@ void DistributedInputSourceManager::RunUnprepareCallback(const std::string &devI DHLOGE("ProcessEvent DINPUT_SOURCE_MANAGER_UNPREPARE_MSG delWhiteListCallback is null."); return; } - for (const auto& iter : delWhiteListCallbacks_) { - iter->OnResult(devId); + for (const auto& it : delWhiteListCallbacks_) { + it->OnResult(devId); } return; } @@ -1930,8 +1924,7 @@ void DistributedInputSourceManager::RunStartCallback( const std::string& devId, const uint32_t& inputTypes, const int32_t& status) { FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_START_START, DINPUT_START_TASK); - for (std::vector::iterator iter = staCallbacks_.begin(); - iter != staCallbacks_.end(); iter++) { + for (auto iter = staCallbacks_.begin(); iter != staCallbacks_.end(); ++iter) { if (iter->devId == devId && iter->inputTypes == inputTypes) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_START_MSG"); iter->callback->OnResult(devId, inputTypes, status); @@ -1945,8 +1938,7 @@ void DistributedInputSourceManager::RunStopCallback( const std::string& devId, const uint32_t& inputTypes, const int32_t& status) { FinishAsyncTrace(DINPUT_HITRACE_LABEL, DINPUT_STOP_START, DINPUT_STOP_TASK); - for (std::vector::iterator iter = stpCallbacks_.begin(); - iter != stpCallbacks_.end(); iter++) { + for (auto iter = stpCallbacks_.begin(); iter != stpCallbacks_.end(); ++iter) { if (iter->devId == devId && iter->inputTypes == inputTypes) { DHLOGI("ProcessEvent DINPUT_SOURCE_MANAGER_STOP_MSG"); iter->callback->OnResult(devId, inputTypes, status); @@ -1969,8 +1961,7 @@ void DistributedInputSourceManager::RunStartDhidCallback(const std::string &sink return; } - for (std::vector::iterator iter = staStringCallbacks_.begin(); - iter != staStringCallbacks_.end(); iter++) { + for (auto iter = staStringCallbacks_.begin(); iter != staStringCallbacks_.end(); ++iter) { if (iter->sinkId != sinkId || !IsStringDataSame(iter->dhIds, dhidsVec)) { continue; } @@ -1991,8 +1982,8 @@ void DistributedInputSourceManager::RunStopDhidCallback(const std::string &sinkI return; } - for (std::vector::iterator iter = stpStringCallbacks_.begin(); - iter != stpStringCallbacks_.end(); iter++) { + for (auto iter = stpStringCallbacks_.begin(); + iter != stpStringCallbacks_.end(); ++iter) { if (iter->sinkId != sinkId || !IsStringDataSame(iter->dhIds, dhidsVec)) { continue; } @@ -2060,7 +2051,7 @@ void DistributedInputSourceManager::RemoveInputDeviceId(const std::string device { InputDeviceId inputDeviceId {deviceId, dhId}; - std::vector::iterator it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); + auto it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); if (it == inputDevice_.end()) { return; } @@ -2074,7 +2065,7 @@ void DistributedInputSourceManager::RemoveInputDeviceId(const std::string device bool DistributedInputSourceManager::GetDeviceMapAllDevSwitchOff() { bool isAllDevSwitchOff = true; - for (auto it = DeviceMap_.begin(); it != DeviceMap_.end(); it++) { + for (auto it = DeviceMap_.begin(); it != DeviceMap_.end(); ++it) { if (it->second == DINPUT_SOURCE_SWITCH_ON) { isAllDevSwitchOff = false; break; @@ -2090,7 +2081,7 @@ void DistributedInputSourceManager::SetDeviceMapValue(const std::string deviceId uint32_t DistributedInputSourceManager::GetInputTypesMap(const std::string deviceId) { - std::map::iterator key = InputTypesMap_.find(deviceId); + auto key = InputTypesMap_.find(deviceId); if (key != InputTypesMap_.end()) { return InputTypesMap_[deviceId]; } @@ -2100,8 +2091,7 @@ uint32_t DistributedInputSourceManager::GetInputTypesMap(const std::string devic uint32_t DistributedInputSourceManager::GetAllInputTypesMap() { uint32_t rInputTypes = static_cast(DInputDeviceType::NONE); - std::map::iterator iter; - for (iter = InputTypesMap_.begin(); iter != InputTypesMap_.end(); iter++) { + for (auto iter = InputTypesMap_.begin(); iter != InputTypesMap_.end(); ++iter) { rInputTypes |= iter->second; } return rInputTypes; @@ -2110,7 +2100,7 @@ uint32_t DistributedInputSourceManager::GetAllInputTypesMap() void DistributedInputSourceManager::SetInputTypesMap(const std::string deviceId, uint32_t value) { if (value == static_cast(DInputDeviceType::NONE)) { - std::map::iterator key = InputTypesMap_.find(deviceId); + auto key = InputTypesMap_.find(deviceId); if (key != InputTypesMap_.end()) { InputTypesMap_.erase(key); return; @@ -2451,10 +2441,8 @@ void DistributedInputSourceManager::DScreenSourceSvrRecipient::OnRemoteDied(cons int32_t DistributedInputSourceManager::Dump(int32_t fd, const std::vector& args) { DHLOGI("DistributedInputSourceManager Dump."); - std::vector argsStr; - for (auto iter : args) { - argsStr.emplace_back(Str16ToStr8(iter)); - } + std::vector argsStr(args.size()); + std::transform(args.begin(), args.end(), argsStr.begin(), [](const auto &item) {return Str16ToStr8(item);}); std::string result(""); if (!HiDumper::GetInstance().HiDump(argsStr, result)) { DHLOGI("Hidump error."); diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn index 5b1c1c4..1d96565 100755 --- a/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn +++ b/services/source/sourcemanager/test/sourcemanagerunittest/BUILD.gn @@ -59,7 +59,6 @@ ohos_unittest("distributed_input_sourcemanager_test") { ] sources = [ - "${common_path}/include/dinput_struct_data.cpp", "${common_path}/include/input_hub.cpp", "${ipc_path}/src/add_white_list_infos_call_back_proxy.cpp", "${ipc_path}/src/add_white_list_infos_call_back_stub.cpp", diff --git a/services/source/transport/include/distributed_input_source_transport.h b/services/source/transport/include/distributed_input_source_transport.h index 87783a9..eff348e 100644 --- a/services/source/transport/include/distributed_input_source_transport.h +++ b/services/source/transport/include/distributed_input_source_transport.h @@ -77,6 +77,7 @@ private: void NotifyResponseKeyState(int32_t sessionId, const nlohmann::json &recMsg); void NotifyReceivedEventRemoteInput(int32_t sessionId, const nlohmann::json &recMsg); void CalculateLatency(int32_t sessionId, const nlohmann::json &recMsg); + std::string JointDhIds(const std::vector &dhids); private: std::map sessionDevMap_; diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index 3647781..bc454fc 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -423,14 +423,7 @@ int32_t DistributedInputSourceTransport::StartRemoteInput(const std::string &dev jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_START_DHID; jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - std::string strTmp = ""; - for (auto iter : dhids) { - strTmp = strTmp + iter + "."; - } - if (!strTmp.empty()) { - strTmp.erase(strTmp.end() - 1); // delete the last '.' char - } - jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strTmp; + jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = JointDhIds(dhids); std::string smsg = jsonStr.dump(); int32_t ret = SendMsg(sessionId, smsg); if (ret != DH_SUCCESS) { @@ -456,14 +449,7 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &devi jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SOURCE_MSG_STOP_DHID; jsonStr[DINPUT_SOFTBUS_KEY_DEVICE_ID] = deviceId; jsonStr[DINPUT_SOFTBUS_KEY_SESSION_ID] = sessionId; - std::string strTmp = ""; - for (auto iter : dhids) { - strTmp = strTmp + iter + "."; - } - if (!strTmp.empty()) { - strTmp.erase(strTmp.end() - 1); // delete the last '.' char - } - jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = strTmp; + jsonStr[DINPUT_SOFTBUS_KEY_VECTOR_DHID] = JointDhIds(dhids); std::string smsg = jsonStr.dump(); int32_t ret = SendMsg(sessionId, smsg); if (ret != DH_SUCCESS) { @@ -476,6 +462,15 @@ int32_t DistributedInputSourceTransport::StopRemoteInput(const std::string &devi return DH_SUCCESS; } +std::string DistributedInputSourceTransport::JointDhIds(const std::vector &dhids) +{ + if (dhids.size() <= 0) { + return ""; + } + auto dotFold = [](std::string a, std::string b) {return std::move(a) + '.' + std::move(b);}; + return std::accumulate(std::next(dhids.begin()), dhids.end(), dhids[0], dotFold); +} + std::string DistributedInputSourceTransport::FindDeviceBySession(int32_t sessionId) { std::unique_lock sessionLock(operationMutex_);