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 "mmi_log.h"
19
20 #undef MMI_LOG_TAG
21 #define MMI_LOG_TAG "HdfDeviceEventDispatch"
22
23 using namespace OHOS::HiviewDFX;
24 namespace OHOS {
25 namespace MMI {
26 std::unique_ptr<VirtualTouchScreen> g_pTouchScreen = nullptr;
27 InjectThread HdfDeviceEventDispatch::injectThread_;
28
HdfDeviceEventDispatch(const uint32_t maxX,const uint32_t maxY)29 HdfDeviceEventDispatch::HdfDeviceEventDispatch(const uint32_t maxX, const uint32_t maxY)
30 {
31 g_pTouchScreen = std::make_unique<VirtualTouchScreen>(maxX, maxY);
32 g_pTouchScreen->SetUp();
33 }
34
EventPkgCallback(const std::vector<EventPackage> & pkgs,uint32_t devIndex)35 int32_t HdfDeviceEventDispatch::EventPkgCallback(const std::vector<EventPackage> &pkgs, uint32_t devIndex)
36 {
37 if (pkgs.empty()) {
38 MMI_HILOGE("The pkgs is empty");
39 return HDF_FAILURE;
40 }
41
42 for (const auto &item : pkgs) {
43 if ((item.type == 0) && (item.code == 0) && (item.value == 0)) {
44 InjectInputEvent injectInputSync = { injectThread_.TOUCH_SCREEN_DEVICE_ID, 0, SYN_MT_REPORT, 0 };
45 injectThread_.WaitFunc(injectInputSync);
46 }
47 InjectInputEvent injectInputEvent = {
48 injectThread_.TOUCH_SCREEN_DEVICE_ID,
49 item.type,
50 item.code,
51 item.value
52 };
53 injectThread_.WaitFunc(injectInputEvent);
54 }
55 return HDF_SUCCESS;
56 }
57
HotPlugCallback(const HotPlugEvent & event)58 int32_t HdfDeviceEventDispatch::HotPlugCallback(const HotPlugEvent &event)
59 {
60 return HDF_SUCCESS;
61 }
62 } // namespace MMI
63 } // namespace OHOS