1 /*
2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "hdf_device_event_dispatch.h"
17
18 #include <cstdio>
19 #include <cstring>
20 #include <functional>
21 #include "hilog/log.h"
22
23 using namespace OHOS::HiviewDFX;
24 namespace OHOS {
25 namespace MMIS {
26 namespace {
27 constexpr HiLogLabel LABEL = { LOG_CORE, 0xD002800, "HdfDeviceEventDispatch"};
28 }
29 std::unique_ptr<VirtualTouchScreen> g_pTouchScreen = nullptr;
30 InjectThread HdfDeviceEventDispatch::injectThread_;
31
HdfDeviceEventDispatch(const uint32_t maxX,const uint32_t maxY)32 HdfDeviceEventDispatch::HdfDeviceEventDispatch(const uint32_t maxX, const uint32_t maxY)
33 {
34 g_pTouchScreen = std::make_unique<VirtualTouchScreen>(maxX, maxY);
35 g_pTouchScreen->SetUp();
36 }
37
~HdfDeviceEventDispatch()38 HdfDeviceEventDispatch::~HdfDeviceEventDispatch() {}
39
GetEventCallbackDispatch(const EventPackage ** pkgs,uint32_t count,uint32_t devIndex)40 void HdfDeviceEventDispatch::GetEventCallbackDispatch(
41 const EventPackage **pkgs, uint32_t count, uint32_t devIndex)
42 {
43 if (pkgs == nullptr) {
44 HiLog::Error(LABEL, " %{public}s fail! pkgs is nullptr", __func__);
45 return;
46 }
47 for (uint32_t i = 0; i < count; i++) {
48 if (pkgs[i] == nullptr) {
49 continue;
50 }
51 if ((pkgs[i]->type == 0) && (pkgs[i]->code == 0) && (pkgs[i]->value == 0)) {
52 InjectInputEvent injectInputSync = {injectThread_.TOUCH_SCREEN_DEVICE_ID, 0, SYN_MT_REPORT, 0};
53 injectThread_.WaitFunc(injectInputSync);
54 }
55 InjectInputEvent injectInputEvent = {
56 injectThread_.TOUCH_SCREEN_DEVICE_ID,
57 pkgs[i]->type,
58 pkgs[i]->code,
59 pkgs[i]->value
60 };
61 injectThread_.WaitFunc(injectInputEvent);
62 }
63 }
64 } // namespace MMIS
65 } // namespace OHOS
66