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_manager.h"
17
18 #include <unistd.h>
19
20 #include "hdf_device_event_dispatch.h"
21 #include "mmi_log.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, "HdfDeviceEventManager" };
28 } // namespace
29
HdfDeviceEventManager()30 HdfDeviceEventManager::HdfDeviceEventManager() {}
31
~HdfDeviceEventManager()32 HdfDeviceEventManager::~HdfDeviceEventManager() {}
33
ConnectHDFInit()34 void HdfDeviceEventManager::ConnectHDFInit()
35 {
36 std::string name = "mmi-hdf";
37 inputInterface_ = IInputInterfaces::Get(true);
38 if (inputInterface_ == nullptr) {
39 MMI_HILOGE("The inputInterface_ is nullptr");
40 return;
41 }
42 thread_ = std::thread(&InjectThread::InjectFunc, injectThread_);
43 pthread_setname_np(thread_.native_handle(), name.c_str());
44 int32_t ret = inputInterface_->OpenInputDevice(TOUCH_DEV_ID);
45 if (ret == HDF_SUCCESS) {
46 ret = inputInterface_->GetInputDevice(TOUCH_DEV_ID, iDevInfo_);
47 if (ret != HDF_SUCCESS) {
48 MMI_HILOGE("Get input device failed");
49 return;
50 }
51 callback_ = new (std::nothrow) HdfDeviceEventDispatch(iDevInfo_.attrSet.axisInfo[ABS_MT_POSITION_X].max,
52 iDevInfo_.attrSet.axisInfo[ABS_MT_POSITION_Y].max);
53 if (callback_ == nullptr) {
54 MMI_HILOGE("The callback_ is nullptr");
55 return;
56 }
57 ret = inputInterface_->RegisterReportCallback(TOUCH_DEV_ID, callback_);
58 MMI_HILOGD("RegisterReportCallback ret:%{public}d", ret);
59 } else {
60 MMI_HILOGE("Open input device failed");
61 }
62 }
63 } // namespace MMI
64 } // namespace OHOS
65
main()66 int32_t main()
67 {
68 int sleepSeconds = 1;
69 sleep(sleepSeconds);
70 OHOS::MMI::HdfDeviceEventManager iHdfDeviceEventManager;
71 iHdfDeviceEventManager.ConnectHDFInit();
72 static std::int32_t usleepTime = 1500000;
73 while (true) {
74 usleep(usleepTime);
75 }
76 return 0;
77 }
78