From 8271d9cf8a8abe8853f216806b73e9fd47749571 Mon Sep 17 00:00:00 2001 From: xxxx Date: Mon, 30 May 2022 09:12:32 +0800 Subject: [PATCH] Description:annoy string and fix code style Match-id-b35226016f866ae3aae1dba6b3a328f717b64e50 --- common/include/input_hub.cpp | 31 +++---- common/include/white_list_util.cpp | 65 ++------------ common/include/white_list_util.h | 2 - .../src/distributed_input_handler.cpp | 2 +- .../include/distributed_input_kit.h | 2 +- .../unittest/distributed_input_inner_test.cpp | 8 +- .../unittest/distributed_input_inner_test.h | 8 +- .../add_white_list_infos_call_back_proxy.h | 2 +- .../del_white_list_infos_call_back_proxy.h | 2 +- .../include/distributed_input_sink_proxy.h | 2 +- .../include/distributed_input_source_proxy.h | 2 +- .../include/prepare_d_input_call_back_proxy.h | 2 +- .../register_d_input_call_back_proxy.h | 2 +- .../include/start_d_input_call_back_proxy.h | 2 +- .../start_d_input_server_call_back_proxy.h | 2 +- .../include/stop_d_input_call_back_proxy.h | 2 +- .../unprepare_d_input_call_back_proxy.h | 2 +- .../unregister_d_input_call_back_proxy.h | 2 +- .../ipc/src/distributed_input_client.cpp | 25 +++--- .../src/distributed_input_collector.cpp | 2 +- .../src/distributed_input_sink_manager.cpp | 18 ++-- .../src/distributed_input_sink_switch.cpp | 22 ++--- .../src/distributed_input_sink_transport.cpp | 45 +++++----- .../src/distributed_input_inject.cpp | 10 +-- .../src/distributed_input_node_manager.cpp | 8 +- .../source/inputinject/src/virtual_device.cpp | 4 +- .../src/distributed_input_source_manager.cpp | 60 ++++++------- .../distributed_input_sourcemanager_test.cpp | 46 +++++----- .../distributed_input_sourcemanager_test.h | 18 ++-- .../distributed_input_source_transport.cpp | 85 ++++++++++--------- 30 files changed, 215 insertions(+), 268 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 0fcb5c0..546cc97 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -95,7 +95,7 @@ int32_t InputHub::Release() size_t InputHub::CollectInputEvents(RawEvent* buffer, size_t bufferSize) { size_t count; - for (; ;) { + for (;;) { if (needToScanDevices_) { needToScanDevices_ = false; ScanInputDevices(DEVICE_PATH); @@ -104,11 +104,11 @@ size_t InputHub::CollectInputEvents(RawEvent* buffer, size_t bufferSize) std::unique_lock deviceLock(visitMutex_); std::unique_ptr device = std::move(*openingDevices_.rbegin()); openingDevices_.pop_back(); - DHLOGI("Reporting device opened: id=%d, name=%s\n", - device->id, device->path.c_str()); + DHLOGI("Reporting device opened: id=%s, name=%s\n", + GetAnonyInt32(device->id).c_str(), device->path.c_str()); auto [dev_it, inserted] = devices_.insert_or_assign(device->id, std::move(device)); if (!inserted) { - DHLOGI("Device id %d exists, replaced. \n", device->id); + DHLOGI("Device id %s exists, replaced. \n", GetAnonyInt32(device->id).c_str()); } } deviceChanged_ = false; @@ -232,14 +232,15 @@ void InputHub::DeviceIsExists(InputDeviceEvent* event, size_t capacity) std::unique_lock deviceLock(visitMutex_); std::unique_ptr device = std::move(*openingDevices_.rbegin()); openingDevices_.pop_back(); - DHLOGI("Reporting device opened: id=%d, name=%s\n", device->id, device->path.c_str()); + DHLOGI("Reporting device opened: id=%s, name=%s\n", + GetAnonyInt32(device->id).c_str(), device->path.c_str()); event->type = DeviceType::DEVICE_ADDED; event->deviceInfo = device->identifier; event += 1; auto [dev_it, inserted] = devices_.insert_or_assign(device->id, std::move(device)); if (!inserted) { - DHLOGI("Device id %d exists, replaced. \n", device->id); + DHLOGI("Device id %s exists, replaced. \n", GetAnonyInt32(device->id).c_str()); } if (--capacity == 0) { @@ -254,11 +255,12 @@ size_t InputHub::CollectInputHandler(InputDeviceEvent* buffer, size_t bufferSize { InputDeviceEvent* event = buffer; size_t capacity = bufferSize; - for (; ;) { + for (;;) { // Report any devices that had last been added/removed. for (auto it = closingDevices_.begin(); it != closingDevices_.end();) { std::unique_ptr device = std::move(*it); - DHLOGI("Reporting device closed: id=%d, name=%s\n", device->id, device->path.c_str()); + DHLOGI("Reporting device closed: id=%s, name=%s\n", + GetAnonyInt32(device->id).c_str(), device->path.c_str()); event->type = DeviceType::DEVICE_REMOVED; event->deviceInfo = device->identifier; event += 1; @@ -494,10 +496,6 @@ int32_t InputHub::MakeInputDevice(int fd, InputDevice& identifier) buffer[sizeof(buffer) - 1] = '\0'; identifier.uniqueId = buffer; } - DHLOGI(" driver: v%d.%d.%d\n", - driverVersion >> MOVE_POSITION_SIXTEEN, - (driverVersion >> DRIVER_VERSION_MOVE) & DRIVER_VERSION_MAX, - driverVersion & DRIVER_VERSION_MAX); return DH_SUCCESS; } @@ -651,8 +649,8 @@ void InputHub::AddDeviceLocked(std::unique_ptr device) void InputHub::CloseDeviceLocked(Device& device) { DHLOGI( - "Removed device: path=%s name=%s id=%d fd=%d classes=0x%x", - device.path.c_str(), device.identifier.name.c_str(), device.id, + "Removed device: path=%s name=%s id=%s fd=%d classes=0x%x", + device.path.c_str(), device.identifier.name.c_str(), GetAnonyInt32(device.id).c_str(), device.fd, device.classes); UnregisterDeviceFromEpollLocked(device); @@ -668,7 +666,7 @@ int32_t InputHub::UnregisterDeviceFromEpollLocked(const Device& device) const int32_t result = UnregisterFdFromEpoll(device.fd); if (result != DH_SUCCESS) { DHLOGE( - "Could not remove input device fd from epoll for device %d", device.id); + "Could not remove input device fd from epoll for device %s", GetAnonyInt32(device.id).c_str()); return result; } } @@ -861,8 +859,7 @@ int32_t InputHub::Device::Enable() chmod(path.c_str(), S_IWRITE | S_IREAD); fd = open(path.c_str(), O_RDWR | O_CLOEXEC | O_NONBLOCK); if (fd < 0) { - DHLOGE( - "could not open %s, %s\n", path.c_str(), strerror(errno)); + DHLOGE("could not open %s, %s\n", path.c_str(), strerror(errno)); return ERR_DH_INPUT_HUB_DEVICE_ENABLE_FAIL; } enabled = true; diff --git a/common/include/white_list_util.cpp b/common/include/white_list_util.cpp index fde5f6a..cf9f51a 100644 --- a/common/include/white_list_util.cpp +++ b/common/include/white_list_util.cpp @@ -19,6 +19,7 @@ #include #include +#include "anonymous_string.h" #include "distributed_hardware_log.h" #include "dinput_errcode.h" @@ -48,7 +49,7 @@ WhiteListUtil &WhiteListUtil::GetInstance(void) int32_t WhiteListUtil::Init(const std::string &deviceId) { - DHLOGI("%s called, deviceId=%s", __func__, deviceId.c_str()); + DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str()); ClearWhiteList(); if (deviceId.empty()) { @@ -107,8 +108,7 @@ int32_t WhiteListUtil::Init(const std::string &deviceId) std::lock_guard lock(mutex_); mapDeviceWhiteList_[deviceId] = vecWhiteList; - DHLOGI("%s called success, deviceId=%s", __func__, deviceId.c_str()); - PrintWhiteList(); + DHLOGI("success, deviceId=%s", GetAnonyString(deviceId).c_str()); return DH_SUCCESS; } @@ -151,19 +151,16 @@ void WhiteListUtil::ReadLineDataStepOne(std::string &column, TYPE_KEY_CODE_VEC & int32_t WhiteListUtil::SyncWhiteList(const std::string &deviceId, const TYPE_WHITE_LIST_VEC &vecWhiteList) { - DHLOGI("%s called, deviceId=%s", - __func__, deviceId.c_str()); + DHLOGI("deviceId=%s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(mutex_); mapDeviceWhiteList_[deviceId] = vecWhiteList; - PrintWhiteList(); return DH_SUCCESS; } int32_t WhiteListUtil::ClearWhiteList(const std::string &deviceId) { - DHLOGI("%s called, deviceId=%s", - __func__, deviceId.c_str()); + DHLOGI("deviceId=%s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(mutex_); mapDeviceWhiteList_.erase(deviceId); @@ -179,20 +176,17 @@ int32_t WhiteListUtil::ClearWhiteList(void) int32_t WhiteListUtil::GetWhiteList(const std::string &deviceId, TYPE_WHITE_LIST_VEC &vecWhiteList) { - DHLOGI("%s called, deviceId=%s", - __func__, deviceId.c_str()); + DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(mutex_); TYPE_DEVICE_WHITE_LIST_MAP::iterator iter = mapDeviceWhiteList_.find(deviceId); if (iter != mapDeviceWhiteList_.end()) { vecWhiteList = iter->second; - DHLOGI("%s called success, deviceId=%s", - __func__, deviceId.c_str()); + DHLOGI("GetWhiteList success, deviceId=%s", GetAnonyString(deviceId).c_str()); return DH_SUCCESS; } - DHLOGE("%s called failure, deviceId=%s", - __func__, deviceId.c_str()); + DHLOGI("GetWhiteList fail, deviceId=%s", GetAnonyString(deviceId).c_str()); return ERR_DH_INPUT_WHILTELIST_GET_WHILTELIST_FAIL; } @@ -211,9 +205,7 @@ bool WhiteListUtil::CheckSubVecData(const TYPE_COMBINATION_KEY_VEC::iterator &it bool WhiteListUtil::IsNeedFilterOut(const std::string &deviceId, const BusinessEvent &event) { - DHLOGI("%s called!", __func__); - - PrintWhiteList(); + DHLOGI("start, deviceId=%s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(mutex_); if (mapDeviceWhiteList_.empty()) { @@ -227,10 +219,6 @@ bool WhiteListUtil::IsNeedFilterOut(const std::string &deviceId, const BusinessE return false; } - DHLOGI( - "%s called, deviceId=%s, keyCode=%d, keyAction=%d", - __func__, deviceId.c_str(), event.keyCode, event.keyAction); - TYPE_KEY_CODE_VEC vecKeyCode = event.pressedKeys; vecKeyCode.push_back(event.keyCode); vecKeyCode.push_back(event.keyAction); @@ -266,41 +254,6 @@ bool WhiteListUtil::IsNeedFilterOut(const std::string &deviceId, const BusinessE DHLOGI("%s called, bIsMatching=%d", __func__, bIsMatching); return bIsMatching; } - -void WhiteListUtil::SubPrintWhiteList(const TYPE_WHITE_LIST_VEC &vecWhiteList) const -{ - for (int32_t iIndex = 0; iIndex < vecWhiteList.size(); ++iIndex) { - TYPE_COMBINATION_KEY_VEC vecCombinationKey = vecWhiteList[iIndex]; - for (int32_t jIndex = 0; jIndex < vecCombinationKey.size(); ++jIndex) { - TYPE_KEY_CODE_VEC vecKeyCode = vecCombinationKey[jIndex]; - for (int32_t kIndex = 0; kIndex < vecKeyCode.size(); ++kIndex) { - DHLOGI( - "PrintWhiteList [%d][%d][%d]=[%d]", - iIndex, jIndex, kIndex, vecKeyCode[kIndex]); - } - } - } -} - -void WhiteListUtil::PrintWhiteList(void) -{ - if (mapDeviceWhiteList_.empty()) { - DHLOGI("%s called, mapDeviceWhiteList_ is empty!", __func__); - return; - } - - DHLOGI("%s begin!", __func__); - for (TYPE_DEVICE_WHITE_LIST_MAP::iterator iter = mapDeviceWhiteList_.begin(); - iter != mapDeviceWhiteList_.end(); - ++iter) { - DHLOGI("deviceId=%s", iter->first.c_str()); - TYPE_WHITE_LIST_VEC vecWhiteList = iter->second; - SubPrintWhiteList(vecWhiteList); - DHLOGI("%s next!", __func__); - } - DHLOGI("%s end!", __func__); - return; -} } // namespace DistributedInput } // namespace DistributedHardware } // namespace OHOS diff --git a/common/include/white_list_util.h b/common/include/white_list_util.h index c6ebc73..bb942d8 100644 --- a/common/include/white_list_util.h +++ b/common/include/white_list_util.h @@ -42,8 +42,6 @@ private: ~WhiteListUtil(); WhiteListUtil(const WhiteListUtil &other) = delete; const WhiteListUtil &operator=(const WhiteListUtil &other) = delete; - void PrintWhiteList(void); - void SubPrintWhiteList(const TYPE_WHITE_LIST_VEC &vecWhiteList) const; 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, diff --git a/inputdevicehandler/src/distributed_input_handler.cpp b/inputdevicehandler/src/distributed_input_handler.cpp index 5338a9c..421c771 100644 --- a/inputdevicehandler/src/distributed_input_handler.cpp +++ b/inputdevicehandler/src/distributed_input_handler.cpp @@ -129,7 +129,7 @@ int32_t DistributedInputHandler::GetDeviceInfo(std::string& deviceId) } deviceId = localNode->networkId; - DHLOGI("device id is %s", deviceId.c_str()); + DHLOGI("device id is %s", GetAnonyString(deviceId).c_str()); return DH_SUCCESS; } diff --git a/interfaces/inner_kits/include/distributed_input_kit.h b/interfaces/inner_kits/include/distributed_input_kit.h index 45c9761..bfa867c 100644 --- a/interfaces/inner_kits/include/distributed_input_kit.h +++ b/interfaces/inner_kits/include/distributed_input_kit.h @@ -27,7 +27,7 @@ #include "i_stop_d_input_call_back.h" #include "i_unregister_d_input_call_back.h" #include "i_prepare_d_input_call_back.h" -#include "i_unprepare_d_input_call_back.h +#include "i_unprepare_d_input_call_back.h" namespace OHOS { namespace DistributedHardware { diff --git a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp index 83c1244..4611c61 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.cpp @@ -41,28 +41,28 @@ void DistributedInputInnerTest::TearDownTestCase() void DistributedInputInnerTest::TestPrepareDInputCallback::OnResult( - const std::string& deviceId, const int32_t& status) + const std::string& deviceId, const int32_t& status) const { return; } void DistributedInputInnerTest::TestUnprepareDInputCallback::OnResult( - const std::string& deviceId, const int32_t& status) + const std::string& deviceId, const int32_t& status) const { return; } void DistributedInputInnerTest::TestStartDInputCallback::OnResult( - const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) + const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const { return; } void DistributedInputInnerTest::TestStopDInputCallback::OnResult( - const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) + const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const { return; diff --git a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h index 04283ec..2bbb583 100644 --- a/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h +++ b/interfaces/inner_kits/test/unittest/distributed_input_inner_test.h @@ -52,7 +52,7 @@ public: public: TestPrepareDInputCallback() = default; virtual ~TestPrepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status); + void OnResult(const std::string& deviceId, const int32_t& status) const; }; class TestUnprepareDInputCallback : public @@ -60,7 +60,7 @@ public: public: TestUnprepareDInputCallback() = default; virtual ~TestUnprepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status); + void OnResult(const std::string& deviceId, const int32_t& status) const; }; class TestStartDInputCallback : public @@ -68,7 +68,7 @@ public: public: TestStartDInputCallback() = default; virtual ~TestStartDInputCallback() = default; - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); + void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const; }; class TestStopDInputCallback : public @@ -76,7 +76,7 @@ public: public: TestStopDInputCallback() = default; virtual ~TestStopDInputCallback() = default; - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); + void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const; }; }; } // namespace DistributedInput diff --git a/interfaces/ipc/include/add_white_list_infos_call_back_proxy.h b/interfaces/ipc/include/add_white_list_infos_call_back_proxy.h index 3a98d44..8f2cdfe 100644 --- a/interfaces/ipc/include/add_white_list_infos_call_back_proxy.h +++ b/interfaces/ipc/include/add_white_list_infos_call_back_proxy.h @@ -34,7 +34,7 @@ public: virtual void OnResult(const std::string& deviceId, const std::string& strJson) override; private: - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedHardware } // namespace DistributedInput diff --git a/interfaces/ipc/include/del_white_list_infos_call_back_proxy.h b/interfaces/ipc/include/del_white_list_infos_call_back_proxy.h index c7474a8..f62f4c1 100644 --- a/interfaces/ipc/include/del_white_list_infos_call_back_proxy.h +++ b/interfaces/ipc/include/del_white_list_infos_call_back_proxy.h @@ -34,7 +34,7 @@ public: virtual void OnResult(const std::string& deviceId) override; private: - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedHardware } // namespace DistributedInput diff --git a/interfaces/ipc/include/distributed_input_sink_proxy.h b/interfaces/ipc/include/distributed_input_sink_proxy.h index 38b568e..f35b764 100644 --- a/interfaces/ipc/include/distributed_input_sink_proxy.h +++ b/interfaces/ipc/include/distributed_input_sink_proxy.h @@ -42,7 +42,7 @@ public: private: bool SendRequest(IDistributedSinkInput::MessageCode code, MessageParcel &data, MessageParcel &reply); - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/include/distributed_input_source_proxy.h b/interfaces/ipc/include/distributed_input_source_proxy.h index b51e739..d7c110b 100644 --- a/interfaces/ipc/include/distributed_input_source_proxy.h +++ b/interfaces/ipc/include/distributed_input_source_proxy.h @@ -60,7 +60,7 @@ public: private: bool SendRequest(const IDistributedSourceInput::MessageCode code, MessageParcel &data, MessageParcel &reply); - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedInput } // namespace DistributedHardware diff --git a/interfaces/ipc/include/prepare_d_input_call_back_proxy.h b/interfaces/ipc/include/prepare_d_input_call_back_proxy.h index c75ff4c..4ea404d 100644 --- a/interfaces/ipc/include/prepare_d_input_call_back_proxy.h +++ b/interfaces/ipc/include/prepare_d_input_call_back_proxy.h @@ -34,7 +34,7 @@ public: virtual void OnResult(const std::string& deviceId, const int32_t& status) override; private: - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedHardware } // namespace DistributedInput diff --git a/interfaces/ipc/include/register_d_input_call_back_proxy.h b/interfaces/ipc/include/register_d_input_call_back_proxy.h index d5abb1e..ff25656 100644 --- a/interfaces/ipc/include/register_d_input_call_back_proxy.h +++ b/interfaces/ipc/include/register_d_input_call_back_proxy.h @@ -34,7 +34,7 @@ public: virtual void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status) override; private: - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedHardware } // namespace DistributedInput diff --git a/interfaces/ipc/include/start_d_input_call_back_proxy.h b/interfaces/ipc/include/start_d_input_call_back_proxy.h index 39c5697..a4d5595 100644 --- a/interfaces/ipc/include/start_d_input_call_back_proxy.h +++ b/interfaces/ipc/include/start_d_input_call_back_proxy.h @@ -34,7 +34,7 @@ public: virtual void OnResult(const std::string& devId, const uint32_t& inputTypes, const int32_t& status) override; private: - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedHardware } // namespace DistributedInput diff --git a/interfaces/ipc/include/start_d_input_server_call_back_proxy.h b/interfaces/ipc/include/start_d_input_server_call_back_proxy.h index bbffd0c..7939702 100644 --- a/interfaces/ipc/include/start_d_input_server_call_back_proxy.h +++ b/interfaces/ipc/include/start_d_input_server_call_back_proxy.h @@ -34,7 +34,7 @@ public: virtual void OnResult(const int32_t& status, const uint32_t& inputTypes) override; private: - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedHardware } // namespace DistributedInput diff --git a/interfaces/ipc/include/stop_d_input_call_back_proxy.h b/interfaces/ipc/include/stop_d_input_call_back_proxy.h index 355755e..e59288c 100644 --- a/interfaces/ipc/include/stop_d_input_call_back_proxy.h +++ b/interfaces/ipc/include/stop_d_input_call_back_proxy.h @@ -34,7 +34,7 @@ public: virtual void OnResult(const std::string& devId, const uint32_t& inputTypes, const int32_t& status) override; private: - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedHardware } // namespace DistributedInput diff --git a/interfaces/ipc/include/unprepare_d_input_call_back_proxy.h b/interfaces/ipc/include/unprepare_d_input_call_back_proxy.h index b512280..3dfbc0b 100644 --- a/interfaces/ipc/include/unprepare_d_input_call_back_proxy.h +++ b/interfaces/ipc/include/unprepare_d_input_call_back_proxy.h @@ -34,7 +34,7 @@ public: virtual void OnResult(const std::string& deviceId, const int32_t& status) override; private: - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedHardware } // namespace DistributedInput diff --git a/interfaces/ipc/include/unregister_d_input_call_back_proxy.h b/interfaces/ipc/include/unregister_d_input_call_back_proxy.h index 3fd6180..be14a2c 100644 --- a/interfaces/ipc/include/unregister_d_input_call_back_proxy.h +++ b/interfaces/ipc/include/unregister_d_input_call_back_proxy.h @@ -34,7 +34,7 @@ public: virtual void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status) override; private: - static inline BrokerDelegator g_delegator; + static inline BrokerDelegator delegator_; }; } // namespace DistributedHardware } // namespace DistributedInput diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 1d63387..40b3f8e 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -48,7 +48,6 @@ void DistributedInputClient::RegisterDInputCb::OnResult( return; } } - DHLOGI("dinputtest 13"); } void DistributedInputClient::UnregisterDInputCb::OnResult( @@ -83,14 +82,9 @@ void DistributedInputClient::StartDInputServerCb::OnResult(const int32_t& status void DistributedInputClient::AddWhiteListInfosCb::OnResult(const std::string &deviceId, const std::string &strJson) { - DHLOGI("AddWhiteListInfosCb deviceId :%s. \n", deviceId.c_str()); - - if (strJson.empty()) { - DHLOGI("AddWhiteListInfosCb whitelist is empty.\n", deviceId.c_str()); - return; + if (!strJson.empty()) { + DistributedInputClient::GetInstance().AddWhiteListInfos(deviceId, strJson); } - - DistributedInputClient::GetInstance().AddWhiteListInfos(deviceId, strJson); } void DistributedInputClient::DelWhiteListInfosCb::OnResult(const std::string& deviceId) @@ -150,7 +144,7 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& d const std::string& parameters, const std::shared_ptr& callback) { DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s", - __func__, devId.c_str(), devId.c_str(), parameters.c_str()); + __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), parameters.c_str()); if (!GetDInputSourceProxy()) { DHLOGE("RegisterDistributedHardware client fail"); @@ -180,7 +174,8 @@ int32_t DistributedInputClient::RegisterDistributedHardware(const std::string& d int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::shared_ptr& callback) { - DHLOGI("%s called, deviceId: %s, dhId: %s", __func__, devId.c_str(), devId.c_str()); + DHLOGI("%s called, deviceId: %s, dhId: %s", + __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); if (!GetDInputSourceProxy()) { DHLOGE("UnregisterDistributedHardware client fail"); @@ -210,7 +205,7 @@ int32_t DistributedInputClient::UnregisterDistributedHardware(const std::string& int32_t DistributedInputClient::PrepareRemoteInput( const std::string& deviceId, sptr callback) { - DHLOGI("%s called, deviceId: %s", __func__, deviceId.c_str()); + DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str()); if (!GetDInputSourceProxy()) { DHLOGE("PrepareRemoteInput client fail"); @@ -228,7 +223,7 @@ int32_t DistributedInputClient::PrepareRemoteInput( int32_t DistributedInputClient::UnprepareRemoteInput( const std::string& deviceId, sptr callback) { - DHLOGI("%s called, deviceId: %s", __func__, deviceId.c_str()); + DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str()); if (!GetDInputSourceProxy()) { DHLOGE("PrepareRemoteInput client fail"); @@ -246,7 +241,7 @@ int32_t DistributedInputClient::UnprepareRemoteInput( int32_t DistributedInputClient::StartRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) { - DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, deviceId.c_str(), inputTypes); + DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); if (!GetDInputSourceProxy()) { DHLOGE("StartRemoteInput client fail"); @@ -265,7 +260,7 @@ int32_t DistributedInputClient::StartRemoteInput( int32_t DistributedInputClient::StopRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) { - DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, deviceId.c_str(), inputTypes); + DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); if (!GetDInputSourceProxy()) { DHLOGE("StopRemoteInput client fail"); @@ -283,7 +278,7 @@ int32_t DistributedInputClient::StopRemoteInput( bool DistributedInputClient::IsNeedFilterOut(const std::string& deviceId, const BusinessEvent& event) { - DHLOGI("%s called, deviceId: %s", __func__, deviceId.c_str()); + DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str()); if (serverType == DInputServerType::NULL_SERVER_TYPE) { DHLOGE("No sa start using."); return true; diff --git a/services/sink/inputcollector/src/distributed_input_collector.cpp b/services/sink/inputcollector/src/distributed_input_collector.cpp index 62e4668..cdf37c9 100644 --- a/services/sink/inputcollector/src/distributed_input_collector.cpp +++ b/services/sink/inputcollector/src/distributed_input_collector.cpp @@ -110,7 +110,7 @@ void DistributedInputCollector::StartCollectEventsThread() // The RawEvent obtained by the controlled end calls transport and is // sent to the main control end. - std::shared_ptr jsonArrayMsg = std::make_shared(); + std::unique_ptr jsonArrayMsg = std::make_unique(); for (int ind = 0; ind < count; ind++) { nlohmann::json tmpJson; tmpJson[INPUT_KEY_WHEN] = mEventBuffer[ind].when; diff --git a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp index bb29d1b..1f0c714 100644 --- a/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp +++ b/services/sink/sinkmanager/src/distributed_input_sink_manager.cpp @@ -57,7 +57,7 @@ DistributedInputSinkManager::DInputSinkListener::~DInputSinkListener() void DistributedInputSinkManager::DInputSinkListener::onPrepareRemoteInput( const int32_t& sessionId, const std::string &deviceId) { - DHLOGI("onPrepareRemoteInput called, sessionId: %d", sessionId); + DHLOGI("onPrepareRemoteInput called, sessionId: %s", GetAnonyInt32(sessionId).c_str()); nlohmann::json jsonStr; jsonStr[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONPREPARE; @@ -108,7 +108,7 @@ void DistributedInputSinkManager::DInputSinkListener::onPrepareRemoteInput( void DistributedInputSinkManager::DInputSinkListener::onUnprepareRemoteInput(const int32_t& sessionId) { - DHLOGI("onUnprepareRemoteInput called, sessionId: %d", sessionId); + DHLOGI("onUnprepareRemoteInput called, sessionId: %s", GetAnonyInt32(sessionId).c_str()); onStopRemoteInput(sessionId, INPUT_TYPE_ALL); DistributedInputSinkSwitch::GetInstance().RemoveSession(sessionId); @@ -123,8 +123,8 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput( const int32_t& sessionId, const uint32_t& inputTypes) { int32_t curSessionId = DistributedInputSinkSwitch::GetInstance().GetSwitchOpenedSession(); - DHLOGI("onStartRemoteInput called, curSessionId:%d, new sessionId: %d", - curSessionId, sessionId); + DHLOGI("onStartRemoteInput called, curSessionId:%s, new sessionId: %s", + GetAnonyInt32(curSessionId).c_str(), GetAnonyInt32(sessionId).c_str()); // set new session int32_t startRes = DistributedInputSinkSwitch::GetInstance().StartSwitch(sessionId); @@ -145,7 +145,8 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput( if (curSessionId == ERR_DH_INPUT_SERVER_SINK_GET_OPEN_SESSION_FAIL) { DHLOGI("onStartRemoteInput called, this is the only session."); } else if (result) { - DHLOGI("onStartRemoteInput called, notify curSessionId:%d Interrupted.", curSessionId); + DHLOGI("onStartRemoteInput called, notify curSessionId:%s Interrupted.", + GetAnonyInt32(curSessionId).c_str()); nlohmann::json jsonStrStp; jsonStrStp[DINPUT_SOFTBUS_KEY_CMD_TYPE] = TRANS_SINK_MSG_ONSTOP; jsonStrStp[DINPUT_SOFTBUS_KEY_INPUT_TYPE] = inputTypes; @@ -176,7 +177,8 @@ void DistributedInputSinkManager::DInputSinkListener::onStartRemoteInput( void DistributedInputSinkManager::DInputSinkListener::onStopRemoteInput( const int32_t& sessionId, const uint32_t& inputTypes) { - DHLOGI("onStopRemoteInput called, sessionId: %d, inputTypes: %d", sessionId, inputTypes); + DHLOGI("onStopRemoteInput called, sessionId: %s, inputTypes: %d", + GetAnonyInt32(sessionId).c_str(), inputTypes); sinkManagerObj_->SetInputTypes(sinkManagerObj_->GetInputTypes() - (sinkManagerObj_->GetInputTypes() & inputTypes)); @@ -286,10 +288,8 @@ int32_t DistributedInputSinkManager::Release() DistributedInputSinkSwitch::GetInstance().StopAllSwitch(); // 2.close all session DistributedInputSinkTransport::GetInstance().CloseAllSession(); - // 3.stop event collect - // DistributedInputCollector::GetInstance().; - // 4.notify callback servertype + // 3.notify callback servertype SetStartTransFlag(DInputServerType::NULL_SERVER_TYPE); IStartDInputServerCallback *startServerCB = GetStartDInputServerCback(); if (startServerCB == nullptr) { diff --git a/services/sink/transport/src/distributed_input_sink_switch.cpp b/services/sink/transport/src/distributed_input_sink_switch.cpp index 67f9b49..5043dc4 100644 --- a/services/sink/transport/src/distributed_input_sink_switch.cpp +++ b/services/sink/transport/src/distributed_input_sink_switch.cpp @@ -65,10 +65,10 @@ int32_t DistributedInputSinkSwitch::StartSwitch(int32_t sessionId) } if (findOld) { - DHLOGI("StartSwitch sessionId:%d is find.", sessionId); + DHLOGI("StartSwitch sessionId:%s is find.", GetAnonyInt32(sessionId).c_str()); return DH_SUCCESS; } else { - DHLOGE("StartSwitch sessionId:%d fail, not found.", sessionId); + DHLOGE("StartSwitch sessionId:%s fail, not found.", GetAnonyInt32(sessionId).c_str()); return ERR_DH_INPUT_SERVER_SINK_START_SWITCH_FAIL; } } @@ -78,7 +78,7 @@ void DistributedInputSinkSwitch::StopSwitch(int32_t sessionId) { std::unique_lock switchLock(operationMutex_); if (switchVector_.empty()) { - DHLOGE("StopSwitch sessionId:%d fail,switchVector_ is null.", sessionId); + DHLOGE("StopSwitch sessionId:%s fail,switchVector_ is null.", GetAnonyInt32(sessionId).c_str()); } else { bool findOld = false; for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { @@ -90,9 +90,9 @@ void DistributedInputSinkSwitch::StopSwitch(int32_t sessionId) } if (findOld) { - DHLOGI("StopSwitch sessionId:%d is success.", sessionId); + DHLOGI("StopSwitch sessionId:%s is success.", GetAnonyInt32(sessionId).c_str()); } else { - DHLOGE("StopSwitch sessionId:%d fail,not find it.", sessionId); + DHLOGE("StopSwitch sessionId:%s fail,not find it.", GetAnonyInt32(sessionId).c_str()); } } } @@ -116,7 +116,7 @@ void DistributedInputSinkSwitch::AddSession(int32_t sessionId) if (switchVector_.empty()) { SwitchStateData tmp(sessionId, false); switchVector_.push_back(tmp); - DHLOGI("AddSession sessionId:%d add first.", sessionId); + DHLOGI("AddSession sessionId:%s add first.", GetAnonyInt32(sessionId).c_str()); } else { bool findOld = false; for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end(); it++) { @@ -128,11 +128,11 @@ void DistributedInputSinkSwitch::AddSession(int32_t sessionId) } if (findOld) { - DHLOGI("AddSession sessionId:%d is find.", sessionId); + DHLOGI("AddSession sessionId:%s is find.", GetAnonyInt32(sessionId).c_str()); } else { SwitchStateData tmp(sessionId, false); switchVector_.push_back(tmp); - DHLOGI("AddSession sessionId:%d add new.", sessionId); + DHLOGI("AddSession sessionId:%s add new.", GetAnonyInt32(sessionId).c_str()); } } } @@ -141,7 +141,7 @@ void DistributedInputSinkSwitch::RemoveSession(int32_t sessionId) { std::unique_lock switchLock(operationMutex_); if (switchVector_.empty()) { - DHLOGE("RemoveSession sessionId:%d fail,switch_vector is null.", sessionId); + DHLOGE("RemoveSession sessionId:%s fail,switch_vector is null.", GetAnonyInt32(sessionId).c_str()); } else { bool findOld = false; for (std::vector::iterator it = switchVector_.begin(); it < switchVector_.end();) { @@ -154,9 +154,9 @@ void DistributedInputSinkSwitch::RemoveSession(int32_t sessionId) } } if (findOld) { - DHLOGI("RemoveSession sessionId:%d is success.", sessionId); + DHLOGI("RemoveSession sessionId:%s is success.", GetAnonyInt32(sessionId).c_str()); } else { - DHLOGE("RemoveSession sessionId:%d fail,not find it.", sessionId); + DHLOGE("RemoveSession sessionId:%s fail,not find it.", GetAnonyInt32(sessionId).c_str()); } } } diff --git a/services/sink/transport/src/distributed_input_sink_transport.cpp b/services/sink/transport/src/distributed_input_sink_transport.cpp index b099239..a3fb619 100644 --- a/services/sink/transport/src/distributed_input_sink_transport.cpp +++ b/services/sink/transport/src/distributed_input_sink_transport.cpp @@ -71,7 +71,7 @@ static void MessageReceived(int32_t sessionId, const void *data, uint32_t dataLe (void)sessionId; (void)data; (void)dataLen; - DHLOGI("sessionId:%d, dataLen:%d", sessionId, dataLen); + DHLOGI("sessionId:%s, dataLen:%d", GetAnonyInt32(sessionId).c_str(), dataLen); } static void StreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, @@ -81,7 +81,7 @@ static void StreamReceived(int32_t sessionId, const StreamData *data, const Stre (void)data; (void)ext; (void)param; - DHLOGI("sessionId:%d", sessionId); + DHLOGI("sessionId:%s", GetAnonyInt32(sessionId).c_str()); } DistributedInputSinkTransport &DistributedInputSinkTransport::GetInstance() { @@ -151,7 +151,7 @@ int32_t DistributedInputSinkTransport::Init() return ERR_DH_INPUT_SERVER_SINK_TRANSPORT_INIT_FAIL; } std::string networkId = localNode->networkId; - DHLOGI("Init device networkId is %s", networkId.c_str()); + DHLOGI("Init device networkId is %s", GetAnonyString(networkId).c_str()); mySessionName_ = SESSION_NAME_SINK + networkId.substr(0, INTERCEPT_STRING_LENGTH); int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener); @@ -178,7 +178,7 @@ int32_t DistributedInputSinkTransport::RespPrepareRemoteInput( const int32_t sessionId, std::string &smsg) { if (sessionId > 0) { - DHLOGI("RespPrepareRemoteInput session:%d, smsg:%s.", sessionId, smsg.c_str()); + DHLOGI("RespPrepareRemoteInput session:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str()); int32_t ret = SendMessage(sessionId, smsg); if (ret != DH_SUCCESS) { DHLOGE("RespPrepareRemoteInput error, SendMessage fail."); @@ -195,7 +195,7 @@ int32_t DistributedInputSinkTransport::RespUnprepareRemoteInput( const int32_t sessionId, std::string &smsg) { if (sessionId > 0) { - DHLOGI("RespUnprepareRemoteInput sessionId:%d, smsg:%s.", sessionId, smsg.c_str()); + DHLOGI("RespUnprepareRemoteInput sessionId:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str()); int32_t ret = SendMessage(sessionId, smsg); if (ret != DH_SUCCESS) { DHLOGE("RespUnprepareRemoteInput error, SendMessage fail."); @@ -212,7 +212,8 @@ int32_t DistributedInputSinkTransport::RespStartRemoteInput( const int32_t sessionId, std::string &smsg) { if (sessionId > 0) { - DHLOGI("RespStartRemoteInput sessionId:%d, result:%d, smsg:%s.", sessionId, smsg.c_str()); + DHLOGI("RespStartRemoteInput sessionId:%s, result:%d, smsg:%s.", + GetAnonyInt32(sessionId).c_str(), smsg.c_str()); int32_t ret = SendMessage(sessionId, smsg); if (ret != DH_SUCCESS) { DHLOGE("RespStartRemoteInput error, SendMessage fail."); @@ -229,7 +230,7 @@ int32_t DistributedInputSinkTransport::RespStopRemoteInput( const int32_t sessionId, std::string &smsg) { if (sessionId > 0) { - DHLOGI("RespStopRemoteInput sessionId:%d, smsg:%s.", sessionId, smsg.c_str()); + DHLOGI("RespStopRemoteInput sessionId:%s, smsg:%s.", GetAnonyInt32(sessionId).c_str(), smsg.c_str()); int32_t ret = SendMessage(sessionId, smsg); if (ret != DH_SUCCESS) { DHLOGE("RespStopRemoteInput error, SendMessage fail."); @@ -269,7 +270,7 @@ int32_t DistributedInputSinkTransport::SendMessage(int32_t sessionId, std::strin int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_t result) { if (result != DH_SUCCESS) { - DHLOGE("session open failed, sessionId %d", sessionId); + DHLOGE("session open failed, sessionId %s", GetAnonyInt32(sessionId).c_str()); if (sessionIdSet_.count(sessionId) > 0) { sessionIdSet_.erase(sessionId); } @@ -278,34 +279,34 @@ int32_t DistributedInputSinkTransport::OnSessionOpened(int32_t sessionId, int32_ // return 1 is client int32_t sessionSide = GetSessionSide(sessionId); - DHLOGI("session open succeed, sessionId %d, sessionSide %d", sessionId, sessionSide); + DHLOGI("session open succeed, sessionId %s, sessionSide %d", GetAnonyInt32(sessionId).c_str(), sessionSide); char mySessionName[SESSION_NAME_SIZE_MAX] = ""; char peerSessionName[SESSION_NAME_SIZE_MAX] = ""; char peerDevId[DEVICE_ID_SIZE_MAX] = ""; int ret = GetMySessionName(sessionId, mySessionName, sizeof(mySessionName)); if (ret != DH_SUCCESS) { - DHLOGI("get my session name failed, session id is %d.", sessionId); + DHLOGI("get my session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); } // get other device session name ret = GetPeerSessionName(sessionId, peerSessionName, sizeof(peerSessionName)); if (ret != DH_SUCCESS) { - DHLOGI("get my peer session name failed, session id is %d.", sessionId); + DHLOGI("get my peer session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); } ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId)); if (ret != DH_SUCCESS) { - DHLOGI("get my peer device id failed, session id is %d.", sessionId); + DHLOGI("get my peer device id failed, session id is %s", GetAnonyInt32(sessionId).c_str()); } - DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s.", - mySessionName, peerSessionName, peerDevId); + DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s", + mySessionName, peerSessionName, GetAnonyString(peerDevId).c_str()); return DH_SUCCESS; } void DistributedInputSinkTransport::OnSessionClosed(int32_t sessionId) { - DHLOGI("OnSessionClosed, sessionId:%d", sessionId); + DHLOGI("OnSessionClosed, sessionId:%s", GetAnonyInt32(sessionId).c_str()); if (sessionIdSet_.count(sessionId) > 0) { sessionIdSet_.erase(sessionId); } @@ -315,7 +316,7 @@ void DistributedInputSinkTransport::OnSessionClosed(int32_t sessionId) void DistributedInputSinkTransport::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) { - DHLOGI("OnBytesReceived, sessionId:%d, dataLen:%d", sessionId, dataLen); + DHLOGI("OnBytesReceived, sessionId:%s, dataLen:%d", GetAnonyInt32(sessionId).c_str(), dataLen); if (sessionId < 0 || data == nullptr || dataLen <= 0) { DHLOGE("OnBytesReceived param check failed"); return; @@ -351,7 +352,7 @@ void DistributedInputSinkTransport::NotifyPrepareRemoteInput(int32_t sessionId, } std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_PREPARE deviceId:%s.", - deviceId.c_str()); + GetAnonyString(deviceId).c_str()); callback_->onPrepareRemoteInput(sessionId, deviceId); } @@ -363,7 +364,7 @@ void DistributedInputSinkTransport::NotifyUnprepareRemoteInput(int32_t sessionId } std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; DHLOGI("OnBytesReceived cmdType TRANS_SOURCE_MSG_UNPREPARE deviceId:%s.", - deviceId.c_str()); + GetAnonyString(deviceId).c_str()); callback_->onUnprepareRemoteInput(sessionId); } @@ -376,7 +377,7 @@ void DistributedInputSinkTransport::NotifyStartRemoteInput(int32_t sessionId, co std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; DHLOGI("OnBytesRecei,ved cmdType is TRANS_SOURCE_MSG_START deviceId:%s inputTypes:%d .", - deviceId.c_str(), inputTypes); + GetAnonyString(deviceId).c_str(), inputTypes); callback_->onStartRemoteInput(sessionId, inputTypes); } @@ -388,7 +389,7 @@ void DistributedInputSinkTransport::NotifyStopRemoteInput(int32_t sessionId, con } std::string deviceId = recMsg[DINPUT_SOFTBUS_KEY_DEVICE_ID]; uint32_t inputTypes = recMsg[DINPUT_SOFTBUS_KEY_INPUT_TYPE]; - DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP deviceId:%s.", deviceId.c_str()); + DHLOGI("OnBytesReceived cmdType is TRANS_SOURCE_MSG_STOP deviceId:%s.", GetAnonyString(deviceId).c_str()); callback_->onStopRemoteInput(sessionId, inputTypes); } @@ -442,10 +443,10 @@ void DistributedInputSinkTransport::HandleSessionData(int32_t sessionId, const s void DistributedInputSinkTransport::CloseAllSession() { std::vector vecSession = DistributedInputSinkSwitch::GetInstance().GetAllSessionId(); - DHLOGI("CloseAllSession session vector size is %d.", vecSession.size()); + DHLOGI("CloseAllSession session vector size is %d", vecSession.size()); for (int32_t kIndex = 0; kIndex < vecSession.size(); ++kIndex) { CloseSession(vecSession[kIndex]); - DHLOGI("CloseAllSession [%d] sessionid is %d.", kIndex, vecSession[kIndex]); + DHLOGI("CloseAllSession [%d] sessionid is %s", kIndex, GetAnonyInt32(vecSession[kIndex]).c_str()); } // clear session data diff --git a/services/source/inputinject/src/distributed_input_inject.cpp b/services/source/inputinject/src/distributed_input_inject.cpp index 0b175af..744360a 100644 --- a/services/source/inputinject/src/distributed_input_inject.cpp +++ b/services/source/inputinject/src/distributed_input_inject.cpp @@ -45,10 +45,8 @@ DistributedInputInject &DistributedInputInject::GetInstance() int32_t DistributedInputInject::RegisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& parameters) { - DHLOGI("%s called", __func__); - DHLOGI("deviveId:%s", devId.c_str()); - DHLOGI("hardwareId:%s", dhId.c_str()); - DHLOGI("describe:%s", parameters.c_str()); + DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s", + __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), parameters.c_str()); if (inputNodeManager_ == nullptr) { DHLOGE("the DistributedInputNodeManager is null\n"); @@ -63,8 +61,8 @@ int32_t DistributedInputInject::RegisterDistributedHardware(const std::string& d int32_t DistributedInputInject::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId) { - DHLOGI("%s called deviveId:%s hardwareId:%s\n", - __func__, devId.c_str(), dhId.c_str()); + DHLOGI("%s called, deviceId: %s, dhId: %s", + __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); if (inputNodeManager_ == nullptr) { DHLOGE("the DistributedInputNodeManager is null\n"); return ERR_DH_INPUT_SERVER_SOURCE_INJECT_NODE_MANAGER_IS_NULL; diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 8e529e9..52fb031 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -113,19 +113,19 @@ void DistributedInputNodeManager::AddDeviceLocked(const std::string& dhId, std:: { auto [dev_it, inserted] = devices_.insert_or_assign(dhId, std::move(device)); if (!inserted) { - DHLOGI("Device id %s exists, replaced. \n", dhId.c_str()); + DHLOGI("Device id %s exists, replaced. \n", GetAnonyString(dhId).c_str()); } } int32_t DistributedInputNodeManager::CloseDeviceLocked(const std::string &dhId) { - DHLOGI("%s called, dhId=%s", __func__, dhId.c_str()); + DHLOGI("%s called, dhId=%s", __func__, GetAnonyString(dhId).c_str()); std::map>::iterator iter = devices_.find(dhId); if (iter != devices_.end()) { devices_.erase(iter); return DH_SUCCESS; } - DHLOGE("%s called failure, dhId=%s", __func__, dhId.c_str()); + DHLOGE("%s called failure, dhId=%s", __func__, GetAnonyString(dhId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_CLOSE_DEVICE_FAIL; } @@ -203,7 +203,7 @@ void DistributedInputNodeManager::ProcessInjectEvent(const std::shared_ptrvalue }; DHLOGI("InjectEvent dhId: %s, eventType: %d, eventCode: %d, eventValue: %d, when: " PRId64"", - dhId.c_str(), event.type, event.code, event.value, rawEvent->when); + GetAnonyString(dhId).c_str(), event.type, event.code, event.value, rawEvent->when); VirtualDevice* device = nullptr; if (getDevice(dhId, device) < 0) { DHLOGE("could not find the device"); diff --git a/services/source/inputinject/src/virtual_device.cpp b/services/source/inputinject/src/virtual_device.cpp index a55444b..76d15fe 100644 --- a/services/source/inputinject/src/virtual_device.cpp +++ b/services/source/inputinject/src/virtual_device.cpp @@ -139,7 +139,7 @@ bool VirtualDevice::SetUp() if (ioctl(fd_, UI_GET_SYSNAME(sizeof(sysfs_device_name)), sysfs_device_name) < 0) { DHLOGE("Unable to get input device name: %s", __func__); } - DHLOGI("get input device name: %s", sysfs_device_name); + DHLOGI("get input device name: %s", GetAnonyString(sysfs_device_name).c_str()); return true; } @@ -170,7 +170,7 @@ bool VirtualDevice::InjectInputEvent(const input_event& event) void VirtualDevice::SetNetWorkId(const std::string netWorkId) { - DHLOGI("SetNetWorkId %s\n", netWorkId.c_str()); + DHLOGI("SetNetWorkId %s\n", GetAnonyString(netWorkId).c_str()); netWorkId_.append(netWorkId); } } // namespace DistributedInput diff --git a/services/source/sourcemanager/src/distributed_input_source_manager.cpp b/services/source/sourcemanager/src/distributed_input_source_manager.cpp index e0ed0e9..bd248b2 100644 --- a/services/source/sourcemanager/src/distributed_input_source_manager.cpp +++ b/services/source/sourcemanager/src/distributed_input_source_manager.cpp @@ -56,7 +56,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseRegisterDist const std::string deviceId, const std::string dhId, bool result) { DHLOGI("onResponseRegisterDistributedHardware called, deviceId: %s, " - "result: %d.", deviceId.c_str(), result); + "result: %s.", GetAnonyString(deviceId).c_str(), result); if (sourceManagerObj_ == nullptr) { DHLOGE("onResponseRegisterDistributedHardware sourceManagerObj_ is null."); return; @@ -68,7 +68,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseRegisterDist return; } - std::shared_ptr jsonArrayMsg = std::make_shared(); + std::unique_ptr jsonArrayMsg = std::make_unique(); nlohmann::json tmpJson; tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; @@ -84,7 +84,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponsePrepareRemot bool result, const std::string &object) { DHLOGI("onResponsePrepareRemoteInput called, deviceId: %s, result: %d.", - deviceId.c_str(), result); + GetAnonyString(deviceId).c_str(), result); if (sourceManagerObj_ == nullptr) { DHLOGE("onResponsePrepareRemoteInput sourceManagerObj_ is null."); @@ -96,7 +96,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponsePrepareRemot DHLOGE("onResponsePrepareRemoteInput GetCallbackEventHandler is null."); return; } - std::shared_ptr jsonArrayMsg = std::make_shared(); + std::unique_ptr jsonArrayMsg = std::make_unique(); nlohmann::json tmpJson; tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; @@ -112,7 +112,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseUnprepareRem const std::string deviceId, bool result) { DHLOGI("onResponseUnprepareRemoteInput called, deviceId: %s, " - "result: %d.", deviceId.c_str(), result); + "result: %d.", GetAnonyString(deviceId).c_str(), result); if (sourceManagerObj_ == nullptr) { DHLOGE("onResponseUnprepareRemoteInput sourceManagerObj_ is null."); @@ -124,7 +124,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseUnprepareRem DHLOGE("onResponseUnprepareRemoteInput GetCallbackEventHandler is null."); return; } - std::shared_ptr jsonArrayMsg = std::make_shared(); + std::unique_ptr jsonArrayMsg = std::make_unique(); nlohmann::json tmpJson; tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; @@ -139,7 +139,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStartRemoteI const std::string deviceId, const uint32_t inputTypes, bool result) { DHLOGI("onResponseStartRemoteInput called, deviceId: %s, inputTypes: %d, result: %d.", - deviceId.c_str(), inputTypes, result); + GetAnonyString(deviceId).c_str(), inputTypes, result); if (sourceManagerObj_ == nullptr) { DHLOGE("onResponseStartRemoteInput sourceManagerObj_ is null."); @@ -155,7 +155,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStartRemoteI sourceManagerObj_->SetDeviceMapValue(deviceId, DINPUT_SOURCE_SWITCH_ON); } - std::shared_ptr jsonArrayMsg = std::make_shared(); + std::unique_ptr jsonArrayMsg = std::make_unique(); if (jsonArrayMsg == nullptr) { DHLOGE("onResponseStartRemoteInput jsonArrayMsg is null."); return; @@ -175,7 +175,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStopRemoteIn const std::string deviceId, const uint32_t inputTypes, bool result) { DHLOGI("onResponseStopRemoteInput called, deviceId: %s, inputTypes: %d, result: %d.", - deviceId.c_str(), inputTypes, result); + GetAnonyString(deviceId).c_str(), inputTypes, result); if (sourceManagerObj_ == nullptr) { DHLOGE("onResponseStopRemoteInput sourceManagerObj_ is null."); @@ -187,7 +187,7 @@ void DistributedInputSourceManager::DInputSourceListener::onResponseStopRemoteIn ERR_DH_INPUT_SERVER_SOURCE_MANAGERGET_CALLBACK_HANDLER_FAIL); return; } - std::shared_ptr jsonArrayMsg = std::make_shared(); + std::unique_ptr jsonArrayMsg = std::make_unique(); nlohmann::json tmpJson; tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = deviceId; @@ -205,7 +205,7 @@ void DistributedInputSourceManager::DInputSourceListener::onReceivedEventRemoteI nlohmann::json inputData = nlohmann::json::parse(event); int jsonSize = inputData.size(); DHLOGI("onReceivedEventRemoteInput called, deviceId: %s, json size:%d.", - deviceId.c_str(), jsonSize); + GetAnonyString(deviceId).c_str(), jsonSize); RawEvent mEventBuffer[jsonSize]; int idx = 0; @@ -255,7 +255,7 @@ void DistributedInputSourceManager::OnStart() return; } - DHLOGI("DistributedInputSourceManager start success."); + DHLOGI("DistributedInputSourceManager start success."); } bool DistributedInputSourceManager::InitAuto() @@ -303,7 +303,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyRegis } } else { DHLOGW("ProcessEvent DINPUT_SOURCE_MANAGER_RIGISTER_MSG the " - "devId[%s] dhId[%s] is bad data.", deviceId.c_str(), dhId.c_str()); + "devId[%s] dhId[%s] is bad data.", GetAnonyString(deviceId).c_str(), GetAnonyString(dhId).c_str()); } sourceManagerObj_->RunRegisterCallback(deviceId, dhId, @@ -368,7 +368,7 @@ void DistributedInputSourceManager::DInputSourceManagerEventHandler::NotifyStart sourceManagerObj_->SetInputTypesMap( deviceId, sourceManagerObj_->GetInputTypesMap(deviceId) | inputTypes); } - sourceManagerObj_->SetStartTransFlag(result && sourceManagerObj_->GetInputTypesMap(deviceId) > 0 ? + sourceManagerObj_->SetStartTransFlag((result && (sourceManagerObj_->GetInputTypesMap(deviceId) > 0)) ? DInputServerType::SOURCE_SERVER_TYPE : DInputServerType::NULL_SERVER_TYPE); if (sourceManagerObj_->GetStartDInputServerCback() != nullptr) { sourceManagerObj_->GetStartDInputServerCback()->OnResult( @@ -504,7 +504,7 @@ int32_t DistributedInputSourceManager::Release() for (std::vector::iterator iter = inputDevice_.begin(); iter != inputDevice_.end(); ++iter) { std::string devId = iter->devId; std::string dhId = iter->dhId; - DHLOGI("Release() devId[%s] dhId[%s]", devId.c_str(), dhId.c_str()); + DHLOGI("Release() devId[%s] dhId[%s]", GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); int32_t ret = DistributedInputInject::GetInstance().UnregisterDistributedHardware(devId, dhId); if (ret != DH_SUCCESS) { DHLOGW("%s called, remove node fail.", __func__); @@ -521,7 +521,7 @@ int32_t DistributedInputSourceManager::Release() InputTypesMap_.clear(); // 4. isStart callback - std::shared_ptr jsonArrayMsg = std::make_shared(); + std::unique_ptr jsonArrayMsg = std::make_unique(); nlohmann::json tmpJson; tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = static_cast(DInputServerType::NULL_SERVER_TYPE); jsonArrayMsg->push_back(tmpJson); @@ -544,12 +544,12 @@ int32_t DistributedInputSourceManager::RegisterDistributedHardware(const std::st const std::string& parameters, sptr callback) { DHLOGI("%s called, deviceId: %s, dhId: %s, parameters: %s", - __func__, devId.c_str(), dhId.c_str(), parameters.c_str()); + __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str(), parameters.c_str()); if (callback == nullptr) { DHLOGE( "%s called, deviceId: %s callback is null.", - __func__, devId.c_str()); + __func__, GetAnonyString(devId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_REGISTER_FAIL; } @@ -611,7 +611,7 @@ void DistributedInputSourceManager::handleStartServerCallback(const std::string& } } if (isAllDevSwitchOff) { - std::shared_ptr jsonArrayMsg = std::make_shared(); + std::unique_ptr jsonArrayMsg = std::make_unique(); nlohmann::json tmpJson; tmpJson[INPUT_SOURCEMANAGER_KEY_RESULT] = static_cast(DInputServerType::NULL_SERVER_TYPE); jsonArrayMsg->push_back(tmpJson); @@ -648,7 +648,7 @@ int32_t DistributedInputSourceManager::RemoveInputNode(const std::string& devId, int32_t DistributedInputSourceManager::DeleteDevice(const std::string& devId, const std::string& dhId) { - std::shared_ptr jsonArrayMsg = std::make_shared(); + std::unique_ptr jsonArrayMsg = std::make_unique(); nlohmann::json tmpJson; tmpJson[INPUT_SOURCEMANAGER_KEY_DEVID] = devId; tmpJson[INPUT_SOURCEMANAGER_KEY_HWID] = dhId; @@ -668,10 +668,10 @@ int32_t DistributedInputSourceManager::DeleteDevice(const std::string& devId, co int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std::string& devId, const std::string& dhId, sptr callback) { - DHLOGI("%s called, deviceId: %s, dhId: %s", __func__, devId.c_str(), dhId.c_str()); + DHLOGI("%s called, deviceId: %s, dhId: %s", __func__, GetAnonyString(devId).c_str(), GetAnonyString(dhId).c_str()); if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, devId.c_str()); + DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(devId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNREGISTER_FAIL; } @@ -685,7 +685,7 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std:: std::vector::iterator it = std::find(inputDevice_.begin(), inputDevice_.end(), inputDeviceId); if (it == inputDevice_.end()) { - DHLOGE("%s called, deviceId: %s is not exist.", __func__, devId.c_str()); + DHLOGE("%s called, deviceId: %s is not exist.", __func__, GetAnonyString(devId).c_str()); for (std::vector::iterator iter = unregCallbacks_.begin(); iter != unregCallbacks_.end(); iter++) { if (iter->devId == devId && iter->dhId == dhId) { @@ -718,9 +718,9 @@ int32_t DistributedInputSourceManager::UnregisterDistributedHardware(const std:: int32_t DistributedInputSourceManager::PrepareRemoteInput(const std::string& deviceId, sptr callback, sptr addWhiteListCallback) { - DHLOGI("%s called, deviceId: %s", __func__, deviceId.c_str()); + DHLOGI("%s called, deviceId: %s", __func__, GetAnonyString(deviceId).c_str()); if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, deviceId.c_str()); + DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_PREPARE_FAIL; } @@ -763,7 +763,7 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& d DHLOGI("%s called, deviceId: %s", __func__, deviceId.c_str()); if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, deviceId.c_str()); + DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_UNPREPARE_FAIL; } @@ -799,10 +799,10 @@ int32_t DistributedInputSourceManager::UnprepareRemoteInput(const std::string& d int32_t DistributedInputSourceManager::StartRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) { - DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, deviceId.c_str(), inputTypes); + DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, deviceId.c_str()); + DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_START_FAIL; } @@ -840,10 +840,10 @@ int32_t DistributedInputSourceManager::StartRemoteInput( int32_t DistributedInputSourceManager::StopRemoteInput( const std::string& deviceId, const uint32_t& inputTypes, sptr callback) { - DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, deviceId.c_str(), inputTypes); + DHLOGI("%s called, deviceId: %s, inputTypes: %d", __func__, GetAnonyString(deviceId).c_str(), inputTypes); if (callback == nullptr) { - DHLOGE("%s called, deviceId: %s callback is null.", __func__, deviceId.c_str()); + DHLOGE("%s called, deviceId: %s callback is null.", __func__, GetAnonyString(deviceId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_MANAGER_STOP_FAIL; } diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp index 1908694..80939a5 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.cpp @@ -61,66 +61,66 @@ void DistributedInputSourceManagerTest::TearDownTestCase() } void DistributedInputSourceManagerTest::TestRegisterDInputCb::OnResult( - const std::string& devId, const std::string& dhId, const int32_t& status) + const std::string& devId, const std::string& dhId, const int32_t& status) const { return; } void DistributedInputSourceManagerTest::TestUnregisterDInputCb::OnResult( - const std::string& devId, const std::string& dhId, const int32_t& status) + const std::string& devId, const std::string& dhId, const int32_t& status) const { return; } void DistributedInputSourceManagerTest::TestPrepareDInputCallback::OnResult( - const std::string& deviceId, const int32_t& status) + const std::string& deviceId, const int32_t& status) const { return; } void DistributedInputSourceManagerTest::TestUnprepareDInputCallback::OnResult( - const std::string& deviceId, const int32_t& status) + const std::string& deviceId, const int32_t& status) const { return; } void DistributedInputSourceManagerTest::TestStartDInputCallback::OnResult( - const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) + const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const { return; } void DistributedInputSourceManagerTest::TestStopDInputCallback::OnResult( - const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) + const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const { return; } void DistributedInputSourceManagerTest::TestAddWhiteListInfosCb::OnResult( - const std::string &deviceId, const std::string &strJson) + const std::string &deviceId, const std::string &strJson) const { return; } void DistributedInputSourceManagerTest::TestDelWhiteListInfosCb::OnResult( - const std::string& deviceId) + const std::string& deviceId) const { return; } -int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice* pBuf, std::string& strDescriptor) +int32_t DistributedInputSourceManagerTest::StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const { nlohmann::json tmpJson; - tmpJson["name"] = pBuf->name; - tmpJson["location"] = pBuf->location; - tmpJson["uniqueId"] = pBuf->uniqueId; - tmpJson["bus"] = pBuf->bus; - tmpJson["vendor"] = pBuf->vendor; - tmpJson["product"] = pBuf->product; - tmpJson["version"] = pBuf->version; - tmpJson["descriptor"] = pBuf->descriptor; - tmpJson["nonce"] = pBuf->nonce; - tmpJson["classes"] = pBuf->classes; + tmpJson["name"] = pBuf.name; + tmpJson["location"] = pBuf.location; + tmpJson["uniqueId"] = pBuf.uniqueId; + tmpJson["bus"] = pBuf.bus; + tmpJson["vendor"] = pBuf.vendor; + tmpJson["product"] = pBuf.product; + tmpJson["version"] = pBuf.version; + tmpJson["descriptor"] = pBuf.descriptor; + tmpJson["nonce"] = pBuf.nonce; + tmpJson["classes"] = pBuf.classes; std::ostringstream stream; stream << tmpJson.dump(); @@ -152,11 +152,11 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware01, testi std::string devId = "umkyu1b165e1be98151891erbe8r91ev"; std::string dhId = pBuffer.descriptor; std::string parameters; - StructTransJson(&pBuffer, parameters); + StructTransJson(pBuffer, parameters); sptr callback = new TestRegisterDInputCb(); int32_t ret = sourceManager_->RegisterDistributedHardware(devId, dhId, parameters, callback); - + EXPECT_EQ(SUCCESS, ret); } @@ -179,7 +179,7 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware02, testi std::string dhId = pBuffer.descriptor; std::string parameters; std::cout << "RegisterDistributedHardware2"<< std::endl; - StructTransJson(&pBuffer, parameters); + StructTransJson(pBuffer, parameters); std::cout << "RegisterDistributedHardware3"<< std::endl; sptr callback = new TestRegisterDInputCb(); int32_t ret = sourceManager_->RegisterDistributedHardware(devId, dhId, parameters, callback); @@ -206,7 +206,7 @@ HWTEST_F(DistributedInputSourceManagerTest, RegisterDistributedHardware03, testi std::string dhId = pBuffer.descriptor; std::string parameters; std::cout << "RegisterDistributedHardware12"<< std::endl; - StructTransJson(&pBuffer, parameters); + StructTransJson(pBuffer, parameters); std::cout << "RegisterDistributedHardware13"<< std::endl; sptr callback = new TestRegisterDInputCb(); int32_t ret = sourceManager_->RegisterDistributedHardware(devId, dhId, parameters, callback); diff --git a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h index 2611b97..8907868 100644 --- a/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h +++ b/services/source/sourcemanager/test/sourcemanagerunittest/distributed_input_sourcemanager_test.h @@ -49,7 +49,7 @@ public: public: TestPrepareDInputCallback() = default; virtual ~TestPrepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status); + void OnResult(const std::string& deviceId, const int32_t& status) const; }; class TestUnprepareDInputCallback : public @@ -57,7 +57,7 @@ public: public: TestUnprepareDInputCallback() = default; virtual ~TestUnprepareDInputCallback() = default; - void OnResult(const std::string& deviceId, const int32_t& status); + void OnResult(const std::string& deviceId, const int32_t& status) const; }; class TestStartDInputCallback : public @@ -65,7 +65,7 @@ public: public: TestStartDInputCallback() = default; virtual ~TestStartDInputCallback() = default; - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); + void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const; }; class TestStopDInputCallback : public @@ -73,39 +73,39 @@ public: public: TestStopDInputCallback() = default; virtual ~TestStopDInputCallback() = default; - void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status); + void OnResult(const std::string& deviceId, const uint32_t& inputTypes, const int32_t& status) const; }; class TestRegisterDInputCb : public OHOS::DistributedHardware::DistributedInput::RegisterDInputCallbackStub { public: TestRegisterDInputCb() = default; virtual ~TestRegisterDInputCb() = default; - void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status); + void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status) const; }; class TestUnregisterDInputCb : public OHOS::DistributedHardware::DistributedInput::UnregisterDInputCallbackStub { public: TestUnregisterDInputCb() = default; virtual ~TestUnregisterDInputCb() = default; - void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status); + void OnResult(const std::string& devId, const std::string& dhId, const int32_t& status) const; }; class TestAddWhiteListInfosCb : public OHOS::DistributedHardware::DistributedInput::AddWhiteListInfosCallbackStub { public: TestAddWhiteListInfosCb() = default; virtual ~TestAddWhiteListInfosCb() = default; - void OnResult(const std::string &deviceId, const std::string &strJson); + void OnResult(const std::string &deviceId, const std::string &strJson) const; }; class TestDelWhiteListInfosCb : public OHOS::DistributedHardware::DistributedInput::DelWhiteListInfosCallbackStub { public: TestDelWhiteListInfosCb() = default; virtual ~TestDelWhiteListInfosCb() = default; - void OnResult(const std::string &deviceId); + void OnResult(const std::string &deviceId) const; }; private: - int32_t StructTransJson(const InputDevice* pBuf, std::string& strDescriptor); + int32_t StructTransJson(const InputDevice& pBuf, std::string& strDescriptor) const; DistributedInputSourceManager* sourceManager_; }; } // namespace DistributedInput diff --git a/services/source/transport/src/distributed_input_source_transport.cpp b/services/source/transport/src/distributed_input_source_transport.cpp index b9a4607..1e26404 100644 --- a/services/source/transport/src/distributed_input_source_transport.cpp +++ b/services/source/transport/src/distributed_input_source_transport.cpp @@ -72,7 +72,7 @@ static void MessageReceived(int32_t sessionId, const void *data, uint32_t dataLe (void)sessionId; (void)data; (void)dataLen; - DHLOGI("sessionId:%d, dataLen:%d", sessionId, dataLen); + DHLOGI("sessionId:%s, dataLen:%d", GetAnonyInt32(sessionId).c_str(), dataLen); } static void StreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, @@ -82,7 +82,7 @@ static void StreamReceived(int32_t sessionId, const StreamData *data, const Stre (void)data; (void)ext; (void)param; - DHLOGI("sessionId:%d", sessionId); + DHLOGI("sessionId:%s", GetAnonyInt32(sessionId).c_str()); } DistributedInputSourceTransport &DistributedInputSourceTransport::GetInstance() { @@ -108,7 +108,7 @@ int32_t DistributedInputSourceTransport::Init() return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_INIT_FAIL; } std::string networkId = localNode->networkId; - DHLOGI("Init device local networkId is %s", networkId.c_str()); + DHLOGI("Init device local networkId is %s", GetAnonyString(networkId).c_str()); mySessionName_ = SESSION_NAME_SOURCE + networkId.substr(0, INTERCEPT_STRING_LENGTH); int32_t ret = CreateSessionServer(DINPUT_PKG_NAME.c_str(), mySessionName_.c_str(), &iSessionListener); @@ -133,7 +133,7 @@ int32_t DistributedInputSourceTransport::CheckDeviceSessionState(const std::stri { std::unique_lock sessionLock(operationMutex_); if (sessionDevMap_.count(devId) != 0) { - DHLOGI("CheckDeviceSessionState has opened %s", devId.c_str()); + DHLOGI("CheckDeviceSessionState has opened %s", GetAnonyString(devId).c_str()); return DH_SUCCESS; } else { return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_DEVICE_SESSION_STATE; @@ -144,7 +144,7 @@ int32_t DistributedInputSourceTransport::OpenInputSoftbus(const std::string &rem { int32_t ret = CheckDeviceSessionState(remoteDevId); if (ret == DH_SUCCESS) { - DHLOGE("Softbus session has already opened, deviceId: %s", remoteDevId.c_str()); + DHLOGE("Softbus session has already opened, deviceId: %s", GetAnonyString(remoteDevId).c_str()); return DH_SUCCESS; } @@ -154,7 +154,8 @@ int32_t DistributedInputSourceTransport::OpenInputSoftbus(const std::string &rem int sessionId = OpenSession(mySessionName_.c_str(), peerSessionName.c_str(), remoteDevId.c_str(), GROUP_ID.c_str(), &g_sessionAttr); if (sessionId < 0) { - DHLOGE("OpenSession fail, remoteDevId: %s, sessionId: %d", remoteDevId.c_str(), sessionId); + DHLOGE("OpenSession fail, remoteDevId: %s, sessionId: %s", + GetAnonyString(remoteDevId).c_str(), GetAnonyInt32(sessionId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_FAIL; } @@ -164,12 +165,14 @@ int32_t DistributedInputSourceTransport::OpenInputSoftbus(const std::string &rem auto status = openSessionWaitCond_.wait_for(waitLock, std::chrono::seconds(SESSION_WAIT_TIMEOUT_SECOND), [this, remoteDevId] () { return channelStatusMap_[remoteDevId]; }); if (!status) { - DHLOGE("OpenSession timeout, remoteDevId: %s, sessionId: %d", remoteDevId.c_str(), sessionId); + DHLOGE("OpenSession timeout, remoteDevId: %s, sessionId: %s", + GetAnonyString(remoteDevId).c_str(), GetAnonyInt32(sessionId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_OPEN_SESSION_TIMEOUT; } } - DHLOGI("OpenSession success, remoteDevId:%s, sessionId:%d", remoteDevId.c_str(), sessionId); + DHLOGI("OpenSession success, remoteDevId:%s, sessionId:%s", + GetAnonyString(remoteDevId).c_str(), GetAnonyInt32(sessionId).c_str()); { std::unique_lock sessionLock(operationMutex_); sessionDevMap_[remoteDevId] = sessionId; @@ -183,12 +186,12 @@ void DistributedInputSourceTransport::CloseInputSoftbus(const std::string &remot // check this device's all hd is close,this device session close. if (sessionDevMap_.count(remoteDevId) == 0) { - DHLOGI("SessionDevIdMap Not find remoteDevId: %s", remoteDevId.c_str()); + DHLOGI("SessionDevIdMap Not find remoteDevId: %s", GetAnonyString(remoteDevId).c_str()); return; } int32_t sessionId = sessionDevMap_[remoteDevId]; - DHLOGI("RemoteDevId: %s, sessionId: %d", remoteDevId.c_str(), sessionId); + DHLOGI("RemoteDevId: %s, sessionId: %s", GetAnonyString(remoteDevId).c_str(), GetAnonyInt32(sessionId).c_str()); CloseSession(sessionId); sessionDevMap_.erase(remoteDevId); channelStatusMap_.erase(remoteDevId); @@ -218,16 +221,16 @@ int32_t DistributedInputSourceTransport::PrepareRemoteInput(const std::string& d std::string smsg = jsonStr.dump(); int32_t ret = SendMsg(sessionId, smsg); if (ret != DH_SUCCESS) { - DHLOGE("PrepareRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.", - deviceId.c_str(), sessionId, smsg.c_str(), ret); + DHLOGE("PrepareRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL; } - DHLOGI("PrepareRemoteInput devId:%s, sessionId:%d, msg:%s.", - deviceId.c_str(), sessionId, smsg.c_str()); + DHLOGI("PrepareRemoteInput devId:%s, sessionId:%s, msg:%s.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str()); return DH_SUCCESS; } else { DHLOGE("PrepareRemoteInput error, not find this device:%s.", - deviceId.c_str()); + GetAnonyString(deviceId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_PREPARE_FAIL; } } @@ -244,16 +247,16 @@ int32_t DistributedInputSourceTransport::UnprepareRemoteInput(const std::string& std::string smsg = jsonStr.dump(); int32_t ret = SendMsg(sessionId, smsg); if (ret != DH_SUCCESS) { - DHLOGE("UnprepareRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.", - deviceId.c_str(), sessionId, smsg.c_str(), ret); + DHLOGE("UnprepareRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL; } - DHLOGI("UnprepareRemoteInput deviceId:%s, sessionId:%d, smsg:%s.", - deviceId.c_str(), sessionId, smsg.c_str()); + DHLOGI("UnprepareRemoteInput deviceId:%s, sessionId:%s, smsg:%s.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str()); return DH_SUCCESS; } else { DHLOGE("UnprepareRemoteInput error, not find this device:%s.", - deviceId.c_str()); + GetAnonyString(deviceId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_UNPREPARE_FAIL; } } @@ -272,15 +275,16 @@ int32_t DistributedInputSourceTransport::StartRemoteInput( std::string smsg = jsonStr.dump(); int32_t ret = SendMsg(sessionId, smsg); if (ret != DH_SUCCESS) { - DHLOGE("StartRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.", - deviceId.c_str(), sessionId, smsg.c_str(), ret); + DHLOGE("StartRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; } - DHLOGI("StartRemoteInput deviceId:%s, sessionId:%d, smsg:%s.", deviceId.c_str(), sessionId, smsg.c_str()); + DHLOGI("StartRemoteInput deviceId:%s, sessionId:%s, smsg:%s.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str()); return DH_SUCCESS; } else { DHLOGE("StartRemoteInput error, not find this device:%s.", - deviceId.c_str()); + GetAnonyString(deviceId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_START_FAIL; } } @@ -299,14 +303,15 @@ int32_t DistributedInputSourceTransport::StopRemoteInput( std::string smsg = jsonStr.dump(); int32_t ret = SendMsg(sessionId, smsg); if (ret != DH_SUCCESS) { - DHLOGE("StopRemoteInput deviceId:%s, sessionId:%d, smsg:%s, SendMsg error, ret:%d.", - deviceId.c_str(), sessionId, smsg.c_str(), ret); + DHLOGE("StopRemoteInput deviceId:%s, sessionId:%s, smsg:%s, SendMsg error, ret:%d.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str(), ret); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; } - DHLOGI("StopRemoteInput deviceId:%s, sessionId:%d, smsg:%s.", deviceId.c_str(), sessionId, smsg.c_str()); + DHLOGI("StopRemoteInput deviceId:%s, sessionId:%s, smsg:%s.", + GetAnonyString(deviceId).c_str(), GetAnonyInt32(sessionId).c_str(), smsg.c_str()); return DH_SUCCESS; } else { - DHLOGE("StopRemoteInput error, not find this device:%s.", deviceId.c_str()); + DHLOGE("StopRemoteInput error, not find this device:%s.", GetAnonyString(deviceId).c_str()); return ERR_DH_INPUT_SERVER_SOURCE_TRANSPORT_STOP_FAIL; } } @@ -332,8 +337,8 @@ int32_t DistributedInputSourceTransport::OnSessionOpened(int32_t sessionId, int3 { if (result != DH_SUCCESS) { std::string deviceId = FindDeviceBySession(sessionId); - DHLOGE("session open failed, sessionId:%d, result:%d, " - "deviceId:%s", sessionId, result, deviceId.c_str()); + DHLOGE("session open failed, sessionId:%s, result:%d, " + "deviceId:%s", GetAnonyInt32(sessionId).c_str(), result, GetAnonyString(deviceId).c_str()); std::unique_lock sessionLock(operationMutex_); if (sessionDevMap_.count(deviceId) > 0) { sessionDevMap_.erase(deviceId); @@ -343,26 +348,26 @@ int32_t DistributedInputSourceTransport::OnSessionOpened(int32_t sessionId, int3 std::string deviceId = FindDeviceBySession(sessionId); int32_t sessionSide = GetSessionSide(sessionId); - DHLOGI("session open succeed, sessionId:%d, sessionSide:%d(1 is " - "client side), deviceId:%s", sessionId, sessionSide, deviceId.c_str()); + DHLOGI("session open succeed, sessionId:%s, sessionSide:%d(1 is " + "client side), deviceId:%s", GetAnonyInt32(sessionId).c_str(), sessionSide, GetAnonyString(deviceId).c_str()); char mySessionName[SESSION_NAME_SIZE_MAX] = ""; char peerSessionName[SESSION_NAME_SIZE_MAX] = ""; char peerDevId[DEVICE_ID_SIZE_MAX] = ""; int ret = GetMySessionName(sessionId, mySessionName, sizeof(mySessionName)); if (ret != DH_SUCCESS) { - DHLOGI("get my session name failed, session id is %d.", sessionId); + DHLOGI("get my session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); } ret = GetPeerSessionName(sessionId, peerSessionName, sizeof(peerSessionName)); if (ret != DH_SUCCESS) { - DHLOGI("get peer session name failed, session id is %d.", sessionId); + DHLOGI("get peer session name failed, session id is %s", GetAnonyInt32(sessionId).c_str()); } ret = GetPeerDeviceId(sessionId, peerDevId, sizeof(peerDevId)); if (ret != DH_SUCCESS) { - DHLOGI("get peer device id failed, session id is %d.", sessionId); + DHLOGI("get peer device id failed, session id is %s", GetAnonyInt32(sessionId).c_str()); } - DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s.", - mySessionName, peerSessionName, peerDevId); + DHLOGI("mySessionName:%s, peerSessionName:%s, peerDevId:%s", + mySessionName, peerSessionName, GetAnonyString(peerDevId).c_str()); { std::lock_guard notifyLock(operationMutex_); channelStatusMap_[peerDevId] = true; @@ -375,8 +380,8 @@ int32_t DistributedInputSourceTransport::OnSessionOpened(int32_t sessionId, int3 void DistributedInputSourceTransport::OnSessionClosed(int32_t sessionId) { std::string deviceId = FindDeviceBySession(sessionId); - DHLOGI("OnSessionClosed, sessionId:%d, deviceId:%s", - sessionId, deviceId.c_str()); + DHLOGI("OnSessionClosed, sessionId:%s, deviceId:%s", + GetAnonyInt32(sessionId).c_str(), GetAnonyString(deviceId).c_str()); std::unique_lock sessionLock(operationMutex_); if (sessionDevMap_.count(deviceId) > 0) { sessionDevMap_.erase(deviceId); @@ -523,7 +528,7 @@ void DistributedInputSourceTransport::HandleSessionData(int32_t sessionId, const void DistributedInputSourceTransport::OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) { - DHLOGI("OnBytesReceived, sessionId:%d, dataLen:%d", sessionId, dataLen); + DHLOGI("OnBytesReceived, sessionId:%s, dataLen:%d", GetAnonyInt32(sessionId).c_str(), dataLen); if (sessionId < 0 || data == nullptr || dataLen <= 0) { DHLOGE("OnBytesReceived param check failed"); return;