• 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_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     int32_t ret = GetInputInterface(&inputInterface_);
37     if (ret != 0) {
38         MMI_HILOGE("Initialize failed");
39         return;
40     }
41 
42     if (inputInterface_ == nullptr || inputInterface_->iInputManager == nullptr) {
43         MMI_HILOGE("The inputInterface_ or iInputManager is nullptr");
44         return;
45     }
46 
47     thread_ = std::thread(&InjectThread::InjectFunc, injectThread_);
48     ret = inputInterface_->iInputManager->OpenInputDevice(TOUCH_DEV_ID);
49     if ((ret == INPUT_SUCCESS) && (inputInterface_->iInputReporter != nullptr)) {
50         ret = inputInterface_->iInputManager->GetInputDevice(TOUCH_DEV_ID, &iDevInfo_);
51         if (ret != INPUT_SUCCESS) {
52             MMI_HILOGE("GetInputDevice error");
53             return;
54         }
55         std::unique_ptr<HdfDeviceEventDispatch> hdf = std::make_unique<HdfDeviceEventDispatch>(\
56             iDevInfo_->attrSet.axisInfo[ABS_MT_POSITION_X].max, iDevInfo_->attrSet.axisInfo[ABS_MT_POSITION_Y].max);
57         callback_.EventPkgCallback = hdf->GetEventCallbackDispatch;
58         ret = inputInterface_->iInputReporter->RegisterReportCallback(TOUCH_DEV_ID, &callback_);
59         MMI_HILOGD("RegisterReportCallback ret:%{public}d", ret);
60     }
61 }
62 } // namespace MMI
63 } // namespace OHOS
main()64 int32_t main()
65 {
66     int sleepSeconds = 1;
67     sleep(sleepSeconds);
68     OHOS::MMI::HdfDeviceEventManager iHdfDeviceEventManager;
69     iHdfDeviceEventManager.ConnectHDFInit();
70     static std::int32_t usleepTime = 1500000;
71     while (true) {
72         usleep(usleepTime);
73     }
74     return 0;
75 }
76