diff --git a/common/include/input_hub.cpp b/common/include/input_hub.cpp index 41bbac7f5ef58ee386b633c80a213c52b3c0abef..afa54a58f5d2858f004ad65a65873ad321ec4255 100644 --- a/common/include/input_hub.cpp +++ b/common/include/input_hub.cpp @@ -449,7 +449,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath) std::unique_lock my_lock(operationMutex_); DHLOGI("Opening device: %s", devicePath.c_str()); int fd = OpenInputDeviceFdByPath(devicePath); - if (fd == -1) { + if (fd == UN_INIT_FD_VALUE) { DHLOGE("The fd open failed, devicePath %s.", devicePath.c_str()); return ERR_DH_INPUT_HUB_OPEN_DEVICEPATH_FAIL; } @@ -476,7 +476,7 @@ int32_t InputHub::OpenInputDeviceLocked(const std::string& devicePath) int32_t InputHub::QueryInputDeviceInfo(int fd, InputDevice& identifier) { - char buffer[256] = {0}; + char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; // Get device name. if (ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) { DHLOGE( @@ -1279,7 +1279,7 @@ void InputHub::Device::Close() { if (fd >= 0) { ::close(fd); - fd = -1; + fd = UN_INIT_FD_VALUE; } } diff --git a/services/source/inputinject/include/distributed_input_inject.h b/services/source/inputinject/include/distributed_input_inject.h index 68d556e5f8d20d200d02b575737eb47c15d180c0..bf286005df48b0307df4ae4a96808b828093ed82 100644 --- a/services/source/inputinject/include/distributed_input_inject.h +++ b/services/source/inputinject/include/distributed_input_inject.h @@ -33,7 +33,6 @@ public: static DistributedInputInject &GetInstance(); int32_t RegisterDistributedHardware(const std::string& devId, const std::string& dhId, const std::string& parameters); - int32_t UnregisterDistributedHardware(const std::string& devId, const std::string& dhId); int32_t RegisterDistributedEvent(RawEvent* buffer, size_t bufferSize); int32_t StructTransJson(const InputDevice& pBuf, std::string& strDescriptor); @@ -45,22 +44,18 @@ public: const uint32_t sourcePhyWidth, const uint32_t sourcePhyHeight); int32_t RemoveVirtualTouchScreenNode(const std::string& dhId); int32_t GetVirtualTouchScreenFd(); - int32_t RegisterInputNodeListener(sptr listener); int32_t UnregisterInputNodeListener(sptr listener); - int32_t GetDhIdsByInputType(const std::string &devId, const uint32_t &inputTypes, std::vector &dhIds); + void NotifyNodeMgrScanVirNode(const std::string &dhId); void InputDeviceEventInject(const std::shared_ptr &rawEvent); + void SyncNodeOfflineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId); void SyncNodeOnlineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId, const std::string &sinkNodeDesc); - void SyncNodeOfflineInfo(const std::string &srcDevId, const std::string &sinkDevId, const std::string &sinkNodeId); - void GetVirtualKeyboardPathsByDhIds(const std::vector &dhIds, std::vector &shareDhidsPaths, std::vector &shareDhIds); - void NotifyNodeMgrScanVirNode(const std::string &dhId); - private: DistributedInputInject(); ~DistributedInputInject(); diff --git a/services/source/inputinject/src/distributed_input_node_manager.cpp b/services/source/inputinject/src/distributed_input_node_manager.cpp index 041d4de69505fa3a45ae9be7251675796d3609c3..2c4c7aa30f51210d9915e22cc43de3cb6234807b 100644 --- a/services/source/inputinject/src/distributed_input_node_manager.cpp +++ b/services/source/inputinject/src/distributed_input_node_manager.cpp @@ -193,7 +193,7 @@ void DistributedInputNodeManager::NotifyNodeMgrScanVirNode(const std::string &dh bool DistributedInputNodeManager::IsVirtualDev(int fd) { - char buffer[256] = {0}; + char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; std::string deviceName; if (ioctl(fd, EVIOCGNAME(sizeof(buffer) - 1), &buffer) < 1) { DHLOGE("Could not get device name for %s.", ConvertErrNo().c_str()); @@ -212,7 +212,7 @@ bool DistributedInputNodeManager::IsVirtualDev(int fd) bool DistributedInputNodeManager::GetDevDhIdByFd(int fd, std::string& dhId, std::string& physicalPath) { - char buffer[256] = {0}; + char buffer[INPUT_EVENT_BUFFER_SIZE] = {0}; if (ioctl(fd, EVIOCGPHYS(sizeof(buffer) - 1), &buffer) < 1) { DHLOGE("Could not get device physicalPath for %s.", ConvertErrNo().c_str()); return false; @@ -251,7 +251,7 @@ void DistributedInputNodeManager::OpenInputDevice(const std::string& devicePath, std::string curDhId; std::string physicalPath; int fd = OpenInputDeviceFdByPath(devicePath); - if (fd == -1) { + if (fd == UN_INIT_FD_VALUE) { DHLOGE("The fd open failed, devicePath %s.", devicePath.c_str()); return; } diff --git a/services/state/src/dinput_state.cpp b/services/state/src/dinput_state.cpp index 1ecdbfac4e03cccd5fdd1a60de7feb28b82dbd67..7dc529026981a0cfa46fd87471a43f961388da3b 100644 --- a/services/state/src/dinput_state.cpp +++ b/services/state/src/dinput_state.cpp @@ -22,10 +22,10 @@ #include #include +#include "constants_dinput.h" #include "dinput_errcode.h" #include "dinput_log.h" #include "dinput_utils_tool.h" -#include "constants_dinput.h" #include "distributed_input_collector.h" #include "distributed_input_inject.h" #include "distributed_input_sink_transport.h" @@ -143,10 +143,10 @@ void DInputState::SpecEventInject(const int32_t &sessionId, std::vector keyboardNodeDhIds; DistributedInputCollector::GetInstance().GetShareKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds); DistributedInputInject::GetInstance().GetVirtualKeyboardPathsByDhIds(dhids, keyboardNodePaths, keyboardNodeDhIds); - ssize_t len = keyboardNodePaths.size(); - for (ssize_t i = 0; i < len; ++i) { + size_t len = keyboardNodePaths.size(); + for (size_t i = 0; i < len; ++i) { std::vector keyboardPressedKeys; - int fd = -1; + int fd = UN_INIT_FD_VALUE; CheckKeyboardState(keyboardNodeDhIds[i], keyboardNodePaths[i], keyboardPressedKeys, fd); for (auto &code : keyboardPressedKeys) { struct input_event event = { diff --git a/utils/src/dinput_utils_tool.cpp b/utils/src/dinput_utils_tool.cpp index bb6db414a52ffa45caaf4127e85e92767a3dcc7f..659e93db84e947a2187227472f6966d173f6595c 100644 --- a/utils/src/dinput_utils_tool.cpp +++ b/utils/src/dinput_utils_tool.cpp @@ -300,7 +300,7 @@ void CloseFd(int& fd) return; } close(fd); - fd = -1; + fd = UN_INIT_FD_VALUE; } int BitIsSet(const unsigned long *array, int bit)