1 /*
2 * Copyright (c) 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 "ohos_adapter/bridge/ark_mmi_adapter_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_mmi_device_info_adapter_impl.h"
19 #include "ohos_adapter/bridge/ark_mmi_input_listener_adapter_impl.h"
20 #include "ohos_adapter/bridge/ark_mmi_listener_adapter_impl.h"
21
22 #include "base/bridge/ark_web_bridge_macros.h"
23
24 namespace OHOS::ArkWeb {
25
ArkMMIAdapterWrapper(ArkWebRefPtr<ArkMMIAdapter> ref)26 ArkMMIAdapterWrapper::ArkMMIAdapterWrapper(ArkWebRefPtr<ArkMMIAdapter> ref) : ctocpp_(ref) {}
27
KeyCodeToString(int32_t keyCode)28 char* ArkMMIAdapterWrapper::KeyCodeToString(int32_t keyCode)
29 {
30 return ctocpp_->KeyCodeToString(keyCode);
31 }
32
RegisterMMIInputListener(std::shared_ptr<NWeb::MMIInputListenerAdapter> eventCallback)33 int32_t ArkMMIAdapterWrapper::RegisterMMIInputListener(std::shared_ptr<NWeb::MMIInputListenerAdapter> eventCallback)
34 {
35 if (CHECK_SHARED_PTR_IS_NULL(eventCallback)) {
36 return ctocpp_->RegisterMMIInputListener(nullptr);
37 }
38
39 return ctocpp_->RegisterMMIInputListener(new ArkMMIInputListenerAdapterImpl(eventCallback));
40 }
41
UnregisterMMIInputListener(int32_t monitorId)42 void ArkMMIAdapterWrapper::UnregisterMMIInputListener(int32_t monitorId)
43 {
44 return ctocpp_->UnregisterMMIInputListener(monitorId);
45 }
46
RegisterDevListener(std::string type,std::shared_ptr<NWeb::MMIListenerAdapter> listener)47 int32_t ArkMMIAdapterWrapper::RegisterDevListener(std::string type, std::shared_ptr<NWeb::MMIListenerAdapter> listener)
48 {
49 ArkWebString str = ArkWebStringClassToStruct(type);
50 int32_t result;
51 if (CHECK_SHARED_PTR_IS_NULL(listener)) {
52 result = ctocpp_->RegisterDevListener(str, nullptr);
53 } else {
54 result = ctocpp_->RegisterDevListener(str, new ArkMMIListenerAdapterImpl(listener));
55 }
56 ArkWebStringStructRelease(str);
57 return result;
58 }
59
UnregisterDevListener(std::string type)60 int32_t ArkMMIAdapterWrapper::UnregisterDevListener(std::string type)
61 {
62 ArkWebString str = ArkWebStringClassToStruct(type);
63 int result = ctocpp_->UnregisterDevListener(str);
64 ArkWebStringStructRelease(str);
65 return result;
66 }
67
GetKeyboardType(int32_t deviceId,int32_t & type)68 int32_t ArkMMIAdapterWrapper::GetKeyboardType(int32_t deviceId, int32_t& type)
69 {
70 return ctocpp_->GetKeyboardType(deviceId, type);
71 }
72
GetDeviceIds(std::vector<int32_t> & ids)73 int32_t ArkMMIAdapterWrapper::GetDeviceIds(std::vector<int32_t>& ids)
74 {
75 ArkWebInt32Vector vec;
76 int result = ctocpp_->GetDeviceIds(vec);
77 ids = ArkWebBasicVectorStructToClass<int32_t, ArkWebInt32Vector>(vec);
78 ArkWebBasicVectorStructRelease(vec);
79 return result;
80 }
81
GetDeviceInfo(int32_t deviceId,std::shared_ptr<NWeb::MMIDeviceInfoAdapter> info)82 int32_t ArkMMIAdapterWrapper::GetDeviceInfo(int32_t deviceId, std::shared_ptr<NWeb::MMIDeviceInfoAdapter> info)
83 {
84 if (CHECK_SHARED_PTR_IS_NULL(info)) {
85 return ctocpp_->GetDeviceInfo(deviceId, nullptr);
86 }
87 return ctocpp_->GetDeviceInfo(deviceId, new ArkMMIDeviceInfoAdapterImpl(info));
88 }
89
90 } // namespace OHOS::ArkWeb
91