• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 HDI_SENSOR_IF_SERVICE_H
17 #define HDI_SENSOR_IF_SERVICE_H
18 
19 #include <map>
20 #include "v3_0/isensor_interface.h"
21 #include "sensor_callback_vdi.h"
22 #include "sensor_client_info.h"
23 #include "sensor_clients_manager.h"
24 #include "v1_0/isensor_interface_vdi.h"
25 
26 namespace OHOS {
27 namespace HDI {
28 namespace Sensor {
29 namespace V3_0 {
30 using namespace OHOS::HDI::Sensor;
31 using namespace OHOS::HDI::Sensor::V1_1;
32 
33 using GroupIdCallBackMap = std::unordered_map<int32_t, std::vector<sptr<IRemoteObject>>>;
34 
35 class SensorIfService : public V3_0::ISensorInterface {
36 //V3_0 interface
37     public:
38     SensorIfService();
39     ~SensorIfService();
40     int32_t Init(void);
41     int32_t GetAllSensorInfo(std::vector<V3_0::HdfSensorInformation> &info) override;
42     int32_t Enable(const OHOS::HDI::Sensor::V3_0::DeviceSensorInfo& deviceSensorInfo) override;
43     int32_t Disable(const OHOS::HDI::Sensor::V3_0::DeviceSensorInfo& deviceSensorInfo) override;
44     int32_t DisableSensor(const SensorHandle sensorHandle, uint32_t serviceId);
45     int32_t SetBatch(const OHOS::HDI::Sensor::V3_0::DeviceSensorInfo& deviceSensorInfo, int64_t samplingInterval,
46                      int64_t reportInterval) override;
47     int32_t SetBatchSenior(int32_t serviceId, const SensorHandle sensorHandle, int32_t mode, int64_t samplingInterval,
48                            int64_t reportInterval);
49     void AdjustSensorConfig(const SensorHandle &sensorHandle, SensorInterval &sensorInterval,
50                             SensorInterval &saSensorInterval, SensorInterval &sdcSensorInterval);
51     int32_t SetBatchConfig(const SensorHandle &sensorHandle, int64_t samplingInterval, int64_t reportInterval);
52     void UpdateSensorModeConfig(const SensorHandle &sensorHandle, int32_t mode, SensorInterval &saSensorInterval,
53                                 SensorInterval &sdcSensorInterval);
54     int32_t SetMode(const OHOS::HDI::Sensor::V3_0::DeviceSensorInfo& deviceSensorInfo, int32_t mode) override;
55     int32_t SetOption(const OHOS::HDI::Sensor::V3_0::DeviceSensorInfo& deviceSensorInfo, uint32_t option) override;
56     int32_t Register(int32_t groupId, const sptr<V3_0::ISensorCallback> &callbackObj) override;
57     int32_t Unregister(int32_t groupId, const sptr<V3_0::ISensorCallback> &callbackObj) override;
58     int32_t ReadData(const OHOS::HDI::Sensor::V3_0::DeviceSensorInfo& deviceSensorInfo,
59                      std::vector<V3_0::HdfSensorEvents> &event) override;
60     int32_t SetSdcSensor(const OHOS::HDI::Sensor::V3_0::DeviceSensorInfo& deviceSensorInfo, bool enabled,
61                          int32_t rateLevel) override;
62     int64_t CalculateSamplingInterval(int32_t rateLevel);
63     int32_t EnableSdcSensor(uint32_t serviceId, const SensorHandle& sensorHandle,
64                                              int64_t samplingInterval, int64_t reportInterval);
65     int32_t DisableSdcSensor(uint32_t serviceId, const SensorHandle& sensorHandle,
66                                               int64_t samplingInterval, int64_t reportInterval);
67     int32_t GetSdcSensorInfo(std::vector<V3_0::SdcSensorInfo> &sdcSensorInfo) override;
68     int32_t RegisterAsync(int32_t groupId, const sptr<V3_0::ISensorCallback> &callbackObj) override;
69     int32_t UnregisterAsync(int32_t groupId, const sptr<V3_0::ISensorCallback> &callbackObj) override;
70     int32_t GetDeviceSensorInfo(int32_t deviceId,
71                                 std::vector<OHOS::HDI::Sensor::V3_0::HdfSensorInformation>& info) override;
72     int32_t RegSensorPlugCallBack(const sptr<OHOS::HDI::Sensor::V3_0::ISensorPlugCallback>& callbackObj) override;
73     int32_t UnRegSensorPlugCallBack(const sptr<OHOS::HDI::Sensor::V3_0::ISensorPlugCallback>& callbackObj) override;
74     int32_t GetSensorVdiImpl();
75     void OnRemoteDied(const wptr<IRemoteObject> &object);
76     std::mutex sensorServiceMutex_;
77 private:
78     int32_t AddSensorDeathRecipient(const sptr<IRemoteObject> &iRemoteObject);
79     int32_t RemoveSensorDeathRecipient(const sptr<IRemoteObject> &iRemoteObject);
80     void  RemoveDeathNotice(int32_t groupId);
81     int32_t AddCallbackMap(int32_t groupId, const sptr<IRemoteObject> &iRemoteObject);
82     int32_t RemoveCallbackMap(int32_t groupId, int serviceId, const sptr<IRemoteObject> &iRemoteObject);
83     bool ValidateCallbackMap(int32_t groupId, const sptr<IRemoteObject> &iRemoteObject);
84     bool RemoveCallbackFromMap(int32_t groupId, const sptr<IRemoteObject> &iRemoteObject);
85     void DisableUnusedSensors(int serviceId);
86     void DisableSensorHandle(const SensorHandle &sensorHandle);
87     sptr<SensorCallbackVdi> GetSensorCb(int32_t groupId, const sptr<V3_0::ISensorCallback> &callbackObj, bool cbFlag);
88     void VoteEnable(const SensorHandle sensorHandle, uint32_t serviceId, bool& enabled);
89     void VoteInterval(const SensorHandle sensorHandle, uint32_t serviceId, int64_t &samplingInterval, bool &enabled);
90     void RegisteDumpHost();
91     OHOS::HDI::Sensor::V1_1::ISensorInterfaceVdi *sensorVdiImplV1_1_ = nullptr;
92     struct HdfVdiObject *vdi_ = nullptr;
93     GroupIdCallBackMap callbackMap = {};
94     sptr<SensorCallbackVdi> traditionalCb = nullptr;
95     sptr<SensorCallbackVdi> medicalCb = nullptr;
96     std::vector<V3_0::HdfSensorInformation> hdfSensorInformations;
97     int32_t SetDelay(const SensorHandle sensorHandle, int64_t &samplingInterval, int64_t &reportInterval);
98 };
99 } // V3_0
100 } // Sensor
101 } // HDI
102 } // OHOS
103 
104 #endif // HDI_SENSOR_IF_SERVICE_H
105