• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
19 
20 #include "mmi_log.h"
21 #include "virtual_touch_screen.h"
22 
23 using namespace OHOS::HiviewDFX;
24 namespace OHOS {
25 namespace MMI {
26 namespace {
27 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = { LOG_CORE, MMI_LOG_DOMAIN, "HdfDeviceEventDispatch" };
28 } // namespace
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 
EventPkgCallback(const std::vector<EventPackage> & pkgs,uint32_t devIndex)40 int32_t HdfDeviceEventDispatch::EventPkgCallback(const std::vector<EventPackage> &pkgs, uint32_t devIndex)
41 {
42     if (pkgs.empty()) {
43         MMI_HILOGE("The pkgs is empty");
44         return HDF_FAILURE;
45     }
46 
47     for (const auto &item : pkgs) {
48         if ((item.type == 0) && (item.code == 0) && (item.value == 0)) {
49             InjectInputEvent injectInputSync = { injectThread_.TOUCH_SCREEN_DEVICE_ID, 0, SYN_MT_REPORT, 0 };
50             injectThread_.WaitFunc(injectInputSync);
51         }
52         InjectInputEvent injectInputEvent = {
53             injectThread_.TOUCH_SCREEN_DEVICE_ID,
54             item.type,
55             item.code,
56             item.value
57         };
58         injectThread_.WaitFunc(injectInputEvent);
59     }
60     return HDF_SUCCESS;
61 }
62 
HotPlugCallback(const HotPlugEvent & event)63 int32_t HdfDeviceEventDispatch::HotPlugCallback(const HotPlugEvent &event)
64 {
65     return HDF_SUCCESS;
66 }
67 } // namespace MMI
68 } // namespace OHOS