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