diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index d07e90fe278ff6e8e33d1de84c0dedac8e77d0dc..13a766feaa70802628862be7343c77d954682374 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 4ab262795c737ceb090bca8473fa524aefbf50f3..3a694a26a9f2d9d4c4d8624d02b2b10ff08beddc 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 36948f40c2c1dbe64f6596a75c40bd31765a09f7..83b2125acf335c3a4273fba08369de664e6fa044 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) {