From 0bf34ed29855a4148cca4cf34f7e43ef8a7b6705 Mon Sep 17 00:00:00 2001 From: mayunteng Date: Mon, 9 Jan 2023 07:00:18 +0000 Subject: [PATCH] HDF Joint debugging across process services Signed-off-by: mayunteng Change-Id: I8408bedd94fc7cfcbc64d9cfadf4ab20c383c329 --- BUILD.gn | 3 +- uinput/hdf_device_event_dispatch.cpp | 31 +++++++++++--------- uinput/hdf_device_event_dispatch.h | 11 ++++--- uinput/hdf_device_event_manager.cpp | 44 +++++++++++++++------------- uinput/hdf_device_event_manager.h | 10 +++---- 5 files changed, 55 insertions(+), 44 deletions(-) diff --git a/BUILD.gn b/BUILD.gn index bc0508b2ea..8d493067ad 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -40,8 +40,9 @@ ohos_executable("uinput_inject") { external_deps = [ "c_utils:utils", - "drivers_interface_input:hdi_input", + "drivers_interface_input:libinput_proxy_1.0", "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_single", ] part_name = "input" diff --git a/uinput/hdf_device_event_dispatch.cpp b/uinput/hdf_device_event_dispatch.cpp index fab41a9ce7..86ca4994d0 100644 --- a/uinput/hdf_device_event_dispatch.cpp +++ b/uinput/hdf_device_event_dispatch.cpp @@ -37,29 +37,32 @@ HdfDeviceEventDispatch::HdfDeviceEventDispatch(const uint32_t maxX, const uint32 HdfDeviceEventDispatch::~HdfDeviceEventDispatch() {} -void HdfDeviceEventDispatch::GetEventCallbackDispatch( - const InputEventPackage **pkgs, uint32_t count, uint32_t devIndex) +int32_t HdfDeviceEventDispatch::EventPkgCallback(const std::vector &pkgs, uint32_t devIndex) { - if (pkgs == nullptr) { - MMI_HILOGE("The pkgs is nullptr"); - return; + if (pkgs.empty()) { + MMI_HILOGE("The pkgs is empty"); + return HDF_FAILURE; } - for (uint32_t i = 0; i < count; i++) { - if (pkgs[i] == nullptr) { - continue; - } - if ((pkgs[i]->type == 0) && (pkgs[i]->code == 0) && (pkgs[i]->value == 0)) { + + for (const auto &item : pkgs) { + if ((item.type == 0) && (item.code == 0) && (item.value == 0)) { InjectInputEvent injectInputSync = { injectThread_.TOUCH_SCREEN_DEVICE_ID, 0, SYN_MT_REPORT, 0 }; injectThread_.WaitFunc(injectInputSync); } InjectInputEvent injectInputEvent = { injectThread_.TOUCH_SCREEN_DEVICE_ID, - pkgs[i]->type, - pkgs[i]->code, - pkgs[i]->value + item.type, + item.code, + item.value }; injectThread_.WaitFunc(injectInputEvent); } + return HDF_SUCCESS; +} + +int32_t HdfDeviceEventDispatch::HotPlugCallback(const HotPlugEvent &event) +{ + return HDF_SUCCESS; } } // namespace MMI -} // namespace OHOS +} // namespace OHOS \ No newline at end of file diff --git a/uinput/hdf_device_event_dispatch.h b/uinput/hdf_device_event_dispatch.h index ac4cc32b0a..b53225e334 100644 --- a/uinput/hdf_device_event_dispatch.h +++ b/uinput/hdf_device_event_dispatch.h @@ -19,21 +19,24 @@ #include #include "inject_thread.h" -#include "input_type.h" #include "nocopyable.h" +#include "v1_0/iinput_interfaces.h" namespace OHOS { namespace MMI { -class HdfDeviceEventDispatch { +using namespace OHOS::HDI::Input::V1_0; +class HdfDeviceEventDispatch : public IInputCallback { public: - static void GetEventCallbackDispatch(const InputEventPackage **pkgs, uint32_t count, uint32_t devIndex); HdfDeviceEventDispatch(const uint32_t maxX, const uint32_t maxY); DISALLOW_COPY_AND_MOVE(HdfDeviceEventDispatch); virtual ~HdfDeviceEventDispatch(); + int32_t EventPkgCallback(const std::vector &pkgs, uint32_t devIndex) override; + int32_t HotPlugCallback(const HotPlugEvent &event) override; + private: static InjectThread injectThread_; }; } // namespace MMI } // namespace OHOS -#endif // HDF_DEVICE_EVENT_DISPATCH_H +#endif // HDF_DEVICE_EVENT_DISPATCH_H \ No newline at end of file diff --git a/uinput/hdf_device_event_manager.cpp b/uinput/hdf_device_event_manager.cpp index b3d16f15d2..2bbd1eb82a 100644 --- a/uinput/hdf_device_event_manager.cpp +++ b/uinput/hdf_device_event_manager.cpp @@ -25,6 +25,8 @@ namespace OHOS { namespace MMI { namespace { constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "HdfDeviceEventManager" }; +constexpr int32_t SLEEP_TIME = 50000; +constexpr int32_t CALL_NUMBER = 70; } // namespace HdfDeviceEventManager::HdfDeviceEventManager() {} @@ -33,29 +35,31 @@ HdfDeviceEventManager::~HdfDeviceEventManager() {} void HdfDeviceEventManager::ConnectHDFInit() { - int32_t ret = GetInputInterface(&inputInterface_); - if (ret != 0) { - MMI_HILOGE("Initialize failed"); - return; - } - - if (inputInterface_ == nullptr || inputInterface_->iInputManager == nullptr) { - MMI_HILOGE("The inputInterface_ or iInputManager is nullptr"); - return; - } + int32_t count = 0; + do { + inputInterface_ = IInputInterfaces::Get(); + usleep(SLEEP_TIME); + if (++count > CALL_NUMBER) { + MMI_HILOGE("The inputInterface_ is nullptr"); + return; + } + } while (inputInterface_ == nullptr); thread_ = std::thread(&InjectThread::InjectFunc, injectThread_); - ret = inputInterface_->iInputManager->OpenInputDevice(TOUCH_DEV_ID); - if ((ret == INPUT_SUCCESS) && (inputInterface_->iInputReporter != nullptr)) { - ret = inputInterface_->iInputManager->GetInputDevice(TOUCH_DEV_ID, &iDevInfo_); - if (ret != INPUT_SUCCESS) { - MMI_HILOGE("GetInputDevice error"); + int32_t ret = inputInterface_->OpenInputDevice(TOUCH_DEV_ID); + if (ret == HDF_SUCCESS) { + ret = inputInterface_->GetInputDevice(TOUCH_DEV_ID, iDevInfo_); + if (ret != HDF_SUCCESS) { + MMI_HILOGE("Get input device failed"); + return; + } + callback_ = new (std::nothrow) HdfDeviceEventDispatch(iDevInfo_.attrSet.axisInfo[ABS_MT_POSITION_X].max, + iDevInfo_.attrSet.axisInfo[ABS_MT_POSITION_Y].max); + if (callback_ == nullptr) { + MMI_HILOGE("The callback_ is nullptr"); return; } - std::unique_ptr hdf = std::make_unique(\ - iDevInfo_->attrSet.axisInfo[ABS_MT_POSITION_X].max, iDevInfo_->attrSet.axisInfo[ABS_MT_POSITION_Y].max); - callback_.EventPkgCallback = hdf->GetEventCallbackDispatch; - ret = inputInterface_->iInputReporter->RegisterReportCallback(TOUCH_DEV_ID, &callback_); + ret = inputInterface_->RegisterReportCallback(TOUCH_DEV_ID, callback_); MMI_HILOGD("RegisterReportCallback ret:%{public}d", ret); } } @@ -72,4 +76,4 @@ int32_t main() usleep(usleepTime); } return 0; -} +} \ No newline at end of file diff --git a/uinput/hdf_device_event_manager.h b/uinput/hdf_device_event_manager.h index 4be80dc40f..207fc324e8 100644 --- a/uinput/hdf_device_event_manager.h +++ b/uinput/hdf_device_event_manager.h @@ -20,11 +20,11 @@ #include #include "inject_thread.h" -#include "input_manager.h" -#include "input_type.h" +#include "v1_0/iinput_interfaces.h" namespace OHOS { namespace MMI { +using namespace OHOS::HDI::Input::V1_0; class HdfDeviceEventManager { public: HdfDeviceEventManager(); @@ -34,9 +34,9 @@ public: std::thread thread_; private: - InputDeviceInfo *iDevInfo_ { nullptr }; - IInputInterface *inputInterface_ { nullptr }; - InputEventCb callback_ {}; + DeviceInfo iDevInfo_; + sptr inputInterface_ { nullptr }; + sptr callback_ { nullptr }; const uint32_t TOUCH_DEV_ID { 1 }; }; } // namespace MMI -- Gitee