1 /*
2 * Copyright (c) 2024 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_sensor_adapter_wrapper.h"
17
18 #include "ohos_adapter/bridge/ark_sensor_callback_adapter_impl.h"
19
20 #include "base/bridge/ark_web_bridge_macros.h"
21
22 namespace OHOS::ArkWeb {
23
ArkSensorAdapterWrapper(ArkWebRefPtr<ArkSensorAdapter> ref)24 ArkSensorAdapterWrapper::ArkSensorAdapterWrapper(ArkWebRefPtr<ArkSensorAdapter> ref)
25 : ctocpp_(ref)
26 {}
27
IsOhosSensorSupported(int32_t sensorTypeId)28 int32_t ArkSensorAdapterWrapper::IsOhosSensorSupported(int32_t sensorTypeId)
29 {
30 return ctocpp_->IsOhosSensorSupported(sensorTypeId);
31 }
32
GetOhosSensorReportingMode(int32_t sensorTypeId)33 int32_t ArkSensorAdapterWrapper::GetOhosSensorReportingMode(int32_t sensorTypeId)
34 {
35 return ctocpp_->GetOhosSensorReportingMode(sensorTypeId);
36 }
37
GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId)38 double ArkSensorAdapterWrapper::GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId)
39 {
40 return ctocpp_->GetOhosSensorDefaultSupportedFrequency(sensorTypeId);
41 }
42
GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId)43 double ArkSensorAdapterWrapper::GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId)
44 {
45 return ctocpp_->GetOhosSensorMinSupportedFrequency(sensorTypeId);
46 }
47
GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId)48 double ArkSensorAdapterWrapper::GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId)
49 {
50 return ctocpp_->GetOhosSensorMaxSupportedFrequency(sensorTypeId);
51 }
52
SubscribeOhosSensor(int32_t sensorTypeId,int64_t samplingInterval)53 int32_t ArkSensorAdapterWrapper::SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval)
54 {
55 return ctocpp_->SubscribeOhosSensor(sensorTypeId, samplingInterval);
56 }
57
UnsubscribeOhosSensor(int32_t sensorTypeId)58 int32_t ArkSensorAdapterWrapper::UnsubscribeOhosSensor(int32_t sensorTypeId)
59 {
60 return ctocpp_->UnsubscribeOhosSensor(sensorTypeId);
61 }
62
RegistOhosSensorCallback(int32_t sensorTypeId,std::shared_ptr<NWeb::SensorCallbackAdapter> callbackAdapter)63 int32_t ArkSensorAdapterWrapper::RegistOhosSensorCallback(int32_t sensorTypeId,
64 std::shared_ptr<NWeb::SensorCallbackAdapter> callbackAdapter)
65 {
66 if (CHECK_SHARED_PTR_IS_NULL(callbackAdapter)) {
67 return ctocpp_->RegistOhosSensorCallback(-1, nullptr);
68 }
69
70 return ctocpp_->RegistOhosSensorCallback(sensorTypeId,
71 new ArkSensorCallbackAdapterImpl(callbackAdapter));
72 }
73 } // namespace OHOS::ArkWeb
74