• 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 "input_device_impl.h"
17 #include "mmi_client.h"
18 #include "multimodal_event_handler.h"
19 
20 namespace OHOS {
21 namespace MMI {
22 namespace {
23 constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, MMI_LOG_DOMAIN, "InputDeviceImpl"}; // namepace
24 }
GetInstance()25 InputDeviceImpl& InputDeviceImpl::GetInstance()
26 {
27     static InputDeviceImpl instance;
28     return instance;
29 }
30 
GetInputDeviceIdsAsync(int32_t userData,std::function<void (int32_t,std::vector<int32_t>)> callback)31 void InputDeviceImpl::GetInputDeviceIdsAsync(int32_t userData,
32     std::function<void(int32_t, std::vector<int32_t>)> callback)
33 {
34     MMI_LOGD("begin");
35     inputDevciceIds_[userData] = callback;
36     MMIEventHdl.GetDeviceIds(userData);
37     MMI_LOGD("end");
38 }
39 
GetInputDeviceAsync(int32_t userData,int32_t deviceId,std::function<void (int32_t,std::shared_ptr<InputDeviceInfo>)> callback)40 void InputDeviceImpl::GetInputDeviceAsync(int32_t userData, int32_t deviceId,
41     std::function<void(int32_t, std::shared_ptr<InputDeviceInfo>)> callback)
42 {
43     MMI_LOGD("begin");
44     inputDevcices_[userData] = callback;
45     MMIEventHdl.GetDevice(userData, deviceId);
46     MMI_LOGD("end");
47 }
48 
OnInputDevice(int32_t userData,int32_t id,std::string name,int32_t deviceType)49 void InputDeviceImpl::OnInputDevice(int32_t userData, int32_t id, std::string name, int32_t deviceType)
50 {
51     MMI_LOGD("begin");
52     auto iter = inputDevcices_.find(userData);
53     if (iter == inputDevcices_.end()) {
54         MMI_LOGE("failed to find the callback function");
55         return;
56     }
57     auto inputDeviceInfo = std::make_shared<InputDeviceInfo>(id, name, deviceType);
58     iter->second(userData, inputDeviceInfo);
59     MMI_LOGD("end");
60 }
61 
OnInputDeviceIds(int32_t userData,std::vector<int32_t> ids)62 void InputDeviceImpl::OnInputDeviceIds(int32_t userData, std::vector<int32_t> ids)
63 {
64     MMI_LOGD("begin");
65     auto iter = inputDevciceIds_.find(userData);
66     if (iter == inputDevciceIds_.end()) {
67         MMI_LOGE("failed to find the callback function");
68         return;
69     }
70     iter->second(userData, ids);
71     MMI_LOGD("end");
72 }
73 } // namespace MMI
74 } // namespace OHOS