1/*
2 * Copyright (c) 2021-2023 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 OHOS_HDI_SENSOR_V2_0_ISENSORINTERFACE_H
17#define OHOS_HDI_SENSOR_V2_0_ISENSORINTERFACE_H
18
19#include <stdint.h>
20#include <vector>
21#include <hdf_base.h>
22#include <hdi_base.h>
23#include "sensor/v2_0/isensor_callback.h"
24#include "sensor/v2_0/sensor_types.h"
25
26#ifndef HDI_BUFF_MAX_SIZE
27#define HDI_BUFF_MAX_SIZE (1024 * 200)
28#endif
29
30#ifndef HDI_CHECK_VALUE_RETURN
31#define HDI_CHECK_VALUE_RETURN(lv, compare, rv, ret) do { \
32    if ((lv) compare (rv)) { \
33        return ret; \
34    } \
35} while (false)
36#endif
37
38#ifndef HDI_CHECK_VALUE_RET_GOTO
39#define HDI_CHECK_VALUE_RET_GOTO(lv, compare, rv, ret, value, table) do { \
40    if ((lv) compare (rv)) { \
41        ret = value; \
42        goto table; \
43    } \
44} while (false)
45#endif
46
47namespace OHOS {
48namespace HDI {
49namespace Sensor {
50namespace V2_0 {
51using namespace OHOS;
52using namespace OHOS::HDI;
53
54enum {
55    CMD_SENSOR_INTERFACE_GET_VERSION = 0,
56    CMD_SENSOR_INTERFACE_GET_ALL_SENSOR_INFO = 1,
57    CMD_SENSOR_INTERFACE_ENABLE = 2,
58    CMD_SENSOR_INTERFACE_DISABLE = 3,
59    CMD_SENSOR_INTERFACE_SET_BATCH = 4,
60    CMD_SENSOR_INTERFACE_SET_MODE = 5,
61    CMD_SENSOR_INTERFACE_SET_OPTION = 6,
62    CMD_SENSOR_INTERFACE_REGISTER = 7,
63    CMD_SENSOR_INTERFACE_UNREGISTER = 8,
64    CMD_SENSOR_INTERFACE_READ_DATA = 9,
65    CMD_SENSOR_INTERFACE_SET_SDC_SENSOR = 10,
66    CMD_SENSOR_INTERFACE_GET_SDC_SENSOR_INFO = 11,
67};
68
69class ISensorInterface : public HdiBase {
70public:
71    DECLARE_HDI_DESCRIPTOR(u"ohos.hdi.sensor.v2_0.ISensorInterface");
72
73    virtual ~ISensorInterface() = default;
74
75    static sptr<OHOS::HDI::Sensor::V2_0::ISensorInterface> Get(bool isStub = false);
76    static sptr<OHOS::HDI::Sensor::V2_0::ISensorInterface> Get(const std::string &serviceName, bool isStub = false);
77
78    virtual int32_t GetAllSensorInfo(std::vector<OHOS::HDI::Sensor::V2_0::HdfSensorInformation>& info) = 0;
79
80    virtual int32_t Enable(int32_t sensorId) = 0;
81
82    virtual int32_t Disable(int32_t sensorId) = 0;
83
84    virtual int32_t SetBatch(int32_t sensorId, int64_t samplingInterval, int64_t reportInterval) = 0;
85
86    virtual int32_t SetMode(int32_t sensorId, int32_t mode) = 0;
87
88    virtual int32_t SetOption(int32_t sensorId, uint32_t option) = 0;
89
90    virtual int32_t Register(int32_t groupId, const sptr<OHOS::HDI::Sensor::V2_0::ISensorCallback>& callbackObj) = 0;
91
92    virtual int32_t Unregister(int32_t groupId, const sptr<OHOS::HDI::Sensor::V2_0::ISensorCallback>& callbackObj) = 0;
93
94    virtual int32_t ReadData(int32_t sensorId, std::vector<OHOS::HDI::Sensor::V2_0::HdfSensorEvents>& event) = 0;
95
96    virtual int32_t SetSdcSensor(int32_t sensorId, bool enabled, int32_t rateLevel) = 0;
97
98    virtual int32_t GetSdcSensorInfo(std::vector<OHOS::HDI::Sensor::V2_0::SdcSensorInfo>& sdcSensorInfo) = 0;
99
100    virtual int32_t GetVersion(uint32_t& majorVer, uint32_t& minorVer)
101    {
102        majorVer = 2;
103        minorVer = 0;
104        return HDF_SUCCESS;
105    }
106
107    virtual bool IsProxy()
108    {
109        return false;
110    }
111
112    virtual const std::u16string GetDesc()
113    {
114        return metaDescriptor_;
115    }
116};
117} // V2_0
118} // Sensor
119} // HDI
120} // OHOS
121
122#endif // OHOS_HDI_SENSOR_V2_0_ISENSORINTERFACE_H
123
124