• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef SENSOR_ADAPTER_H
17 #define SENSOR_ADAPTER_H
18 
19 #include <memory>
20 #include <string>
21 
22 
23 namespace OHOS::NWeb {
24 
25 enum {
26     SENSOR_ERROR = -1,
27     SENSOR_SUCCESS = 0,
28     SENSOR_PERMISSION_DENIED = 201, // Use this error code when permission is denied.
29     SENSOR_PARAMETER_ERROR = 401, // Use this error code when the input parameter type or range does not match.
30     SENSOR_SERVICE_EXCEPTION = 14500101, // Use this error code when the service is exception.
31     SENSOR_NO_SUPPORT = 14500102, // Use this error code when the sensor is not supported by the device.
32     SENSOR_NON_SYSTEM_API = 202 // Permission check failed. A non-system application uses the system API.
33 };
34 
35 enum {
36     SENSOR_DATA_REPORT_ON_CHANGE = 0,
37     SENSOR_DATA_REPORT_CONTINUOUS = 1
38 };
39 
40 class SensorCallbackAdapter {
41 public:
42     virtual ~SensorCallbackAdapter() = default;
43 
44     virtual void UpdateOhosSensorData(double timestamp,
45         double value1, double value2, double value3, double value4) = 0;
46 };
47 
48 class SensorAdapter {
49 public:
50     SensorAdapter() = default;
51     virtual ~SensorAdapter() = default;
52 
53     virtual int32_t IsOhosSensorSupported(int32_t sensorTypeId) = 0;
54     virtual int32_t GetOhosSensorReportingMode(int32_t sensorTypeId) = 0;
55     virtual double GetOhosSensorDefaultSupportedFrequency(int32_t sensorTypeId) = 0;
56     virtual double GetOhosSensorMinSupportedFrequency(int32_t sensorTypeId) = 0;
57     virtual double GetOhosSensorMaxSupportedFrequency(int32_t sensorTypeId) = 0;
58     virtual int32_t SubscribeOhosSensor(int32_t sensorTypeId, int64_t samplingInterval) = 0;
59     virtual int32_t RegistOhosSensorCallback(int32_t sensorTypeId,
60         std::shared_ptr<SensorCallbackAdapter> callbackAdapter) = 0;
61     virtual int32_t UnsubscribeOhosSensor(int32_t sensorTypeId) = 0;
62 };
63 
64 }
65 
66 #endif // SENSOR_ADAPTER_H