From f1168767e11ba19e9ce193e52631bbf121624dcd Mon Sep 17 00:00:00 2001 From: li-tiangang4 Date: Thu, 18 Apr 2024 16:29:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B8=85=E7=90=86=E7=9C=8B=E6=9D=BF=E5=91=8A?= =?UTF-8?q?=E8=AD=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: li-tiangang4 --- common/include/input_hub.cpp | 11 +++++------ interfaces/ipc/include/distributed_input_client.h | 4 ++-- interfaces/ipc/src/distributed_input_client.cpp | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index d07e90f..13a766f 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -42,6 +42,7 @@ namespace DistributedInput { namespace { const uint32_t SLEEP_TIME_US = 100 * 1000; const std::string MOUSE_NODE_KEY = "mouse"; +const uint32_t SPACELENGTH = 1024; } InputHub::InputHub(bool isPluginMonitor) : epollFd_(-1), iNotifyFd_(-1), inputWd_(-1), @@ -303,9 +304,6 @@ void InputHub::RecordDeviceChangeStates(Device *device, struct input_event readB size_t InputHub::CollectEvent(RawEvent *buffer, size_t &capacity, Device *device, struct input_event readBuffer[], const size_t count) { - if (capacity < 1) { - return 0; - } std::vector needFilted(capacity, false); bool isTouchEvent = false; if ((device->classes & INPUT_DEVICE_CLASS_TOUCH_MT) || (device->classes & INPUT_DEVICE_CLASS_TOUCH)) { @@ -330,6 +328,9 @@ size_t InputHub::CollectEvent(RawEvent *buffer, size_t &capacity, Device *device RecordEventLog(event); event += 1; capacity -= 1; + if (capacity == 0) { + break; + } } return event - buffer; } @@ -951,9 +952,7 @@ int32_t InputHub::QueryLocalTouchScreenInfo(int fd, std::unique_ptr &dev std::string InputHub::StringPrintf(const char *format, ...) const { - static const int spaceLength = 1024; - char space[spaceLength] = {0}; - + char space[SPACELENGTH] = {0}; va_list ap; va_start(ap, format); std::string result; diff --git a/interfaces/ipc/include/distributed_input_client.h b/interfaces/ipc/include/distributed_input_client.h index 4ab2627..3a694a2 100644 --- a/interfaces/ipc/include/distributed_input_client.h +++ b/interfaces/ipc/include/distributed_input_client.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 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 @@ -44,6 +44,7 @@ namespace DistributedHardware { namespace DistributedInput { class DistributedInputClient { public: + DistributedInputClient(); ~DistributedInputClient(){}; static DistributedInputClient &GetInstance(); @@ -169,7 +170,6 @@ public: }; private: - DistributedInputClient(); bool IsJsonData(std::string strData) const; void AddWhiteListInfos(const std::string &deviceId, const std::string &strJson) const; void DelWhiteListInfos(const std::string &deviceId) const; diff --git a/interfaces/ipc/src/distributed_input_client.cpp b/interfaces/ipc/src/distributed_input_client.cpp index 36948f4..83b2125 100644 --- a/interfaces/ipc/src/distributed_input_client.cpp +++ b/interfaces/ipc/src/distributed_input_client.cpp @@ -33,7 +33,7 @@ namespace OHOS { namespace DistributedHardware { namespace DistributedInput { -std::shared_ptr DistributedInputClient::instance(new DistributedInputClient()); +std::shared_ptr DistributedInputClient::instance = std::make_shared(); DistributedInputClient::DistributedInputClient() : isAddWhiteListCbReg(false), isDelWhiteListCbReg(false), isNodeMonitorCbReg(false), isSimulationEventCbReg(false), isSharingDhIdsReg(false), isGetSinkScreenInfosCbReg(false) {