• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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_HDI_CONNECTION_H
17 #define SENSOR_HDI_CONNECTION_H
18 
19 #include<unordered_set>
20 
21 #include "i_sensor_hdi_connection.h"
22 #include "singleton.h"
23 
24 namespace OHOS {
25 namespace Sensors {
26 class SensorHdiConnection : public ISensorHdiConnection, public Singleton<SensorHdiConnection> {
27 public:
28     SensorHdiConnection() = default;
~SensorHdiConnection()29     virtual ~SensorHdiConnection() {}
30     int32_t ConnectHdi() override;
31     int32_t GetSensorList(std::vector<Sensor> &sensorList) override;
32     int32_t GetSensorListByDevice(int32_t deviceId, std::vector<Sensor> &singleDevSensors) override;
33     int32_t EnableSensor(const SensorDescription &sensorDesc) override;
34     int32_t DisableSensor(const SensorDescription &sensorDesc)  override;
35     int32_t SetBatch(const SensorDescription &sensorDesc, int64_t samplingInterval, int64_t reportInterval) override;
36     int32_t SetMode(const SensorDescription &sensorDesc, int32_t mode) override;
37     int32_t RegisterDataReport(ReportDataCb cb, sptr<ReportDataCallback> reportDataCallback) override;
38     int32_t DestroyHdiConnection() override;
39     int32_t RegSensorPlugCallback(DevicePlugCallback cb) override;
40     DevicePlugCallback GetSensorPlugCb() override;
41     bool PlugEraseSensorData(const SensorPlugInfo &info);
42 
43 private:
44     DISALLOW_COPY_AND_MOVE(SensorHdiConnection);
45     std::unique_ptr<ISensorHdiConnection> iSensorHdiConnection_ { nullptr };
46     std::unique_ptr<ISensorHdiConnection> iSensorCompatibleHdiConnection_ { nullptr };
47     std::mutex sensorMutex_;
48     std::vector<Sensor> sensorList_;
49     std::unordered_set<int32_t> sensorSet_;
50     std::unordered_set<int32_t> mockSet_;
51     int32_t ConnectHdiService();
52     int32_t ConnectCompatibleHdi();
53     bool FindAllInSensorSet(const std::unordered_set<int32_t> &sensors);
54     bool FindOneInMockSet(int32_t sensorType);
55     Sensor GenerateColorSensor();
56     Sensor GenerateSarSensor();
57     Sensor GenerateHeadPostureSensor();
58     Sensor GenerateProximitySensor();
59     void UpdateSensorList(std::vector<Sensor> &singleDevSensors);
60     std::atomic_bool hdiConnectionStatus_ = false;
61 };
62 } // namespace Sensors
63 } // namespace OHOS
64 #endif // SENSOR_HDI_CONNECTION_H