• 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_MANAGER_H
17 #define HDI_SENSOR_MANAGER_H
18 
19 #include <unordered_map>
20 #include <vector>
21 #include <set>
22 #include "v2_0/isensor_interface.h"
23 #include "isensor_interface_vdi.h"
24 #include "sensor_client_info.h"
25 
26 namespace OHOS {
27 namespace HDI {
28 namespace Sensor {
29 namespace V2_0 {
30 
31 
32 class SensorClientsManager {
33 public:
34     ~SensorClientsManager();
35     void ReportDataCbRegister(int groupId, int serviceId, const sptr<ISensorCallback> &callbackObj);
36     void ReportDataCbUnRegister(int groupId, int serviceId, const sptr<ISensorCallback> &callbackObj);
37     void SetSensorBestConfig(int sensorId, int64_t &samplingInterval, int64_t &reportInterval);
38     void SetSdcSensorBestConfig(int sensorId, int64_t &samplingInterval, int64_t &reportInterval);
39     void GetSensorBestConfig(int sensorId, int64_t &samplingInterval, int64_t &reportInterval);
40     void EraseSdcSensorBestConfig(int sensorId);
41     bool IsUpadateSensorState(int sensorId, int serviceId, bool isOpen);
42     bool GetClients(int groupId, std::unordered_map<int32_t, SensorClientInfo> &client);
43     bool IsClientsEmpty(int groupId);
44     std::unordered_map<int32_t, std::set<int32_t>> GetSensorUsed();
45     bool IsNeedOpenSensor(int sensorId, int serviceId);
46     bool IsNeedCloseSensor(int sensorId, int serviceId);
47     bool IsExistSdcSensorEnable(int sensorId);
48     void OpenSensor(int sensorId, int serviceId);
49     void UpdateSensorConfig(int sensorId, int64_t samplingInterval, int64_t reportInterval);
50     void UpdateSdcSensorConfig(int sensorId, int64_t samplingInterval, int64_t reportInterval);
51     int GetServiceId(int groupId, const sptr<ISensorCallback> &callbackObj);
52     static SensorClientsManager* GetInstance();
53     std::mutex clientsMutex_;
54     std::mutex sensorUsedMutex_;
55     std::mutex sensorConfigMutex_;
56     std::mutex sdcSensorConfigMutex_;
57     void SetClientSenSorConfig(int32_t sensorId, int32_t serviceId, int64_t samplingInterval, int64_t &reportInterval);
58     bool IsNotNeedReportData(int32_t serviceId, int32_t sensorId);
59     static bool IsSensorContinues(int32_t sensorId);
60     void UpdateClientPeriodCount(int sensorId, int64_t samplingInterval, int64_t reportInterval);
61 private:
62     SensorClientsManager();
63     static SensorClientsManager *instance;
64     static std::mutex instanceMutex_;
65     std::unordered_map<int32_t, std::unordered_map<int, SensorClientInfo>> clients_;
66     std::unordered_map<int32_t, std::set<int32_t>> sensorUsed_;
67     std::unordered_map<int32_t, struct BestSensorConfig> sensorConfig_;
68     std::unordered_map<int32_t, struct BestSensorConfig> sdcSensorConfig_;
69 };
70 
71 struct BestSensorConfig {
72     int64_t samplingInterval;
73     int64_t reportInterval;
74 };
75 
76 } // V2_0
77 } // Sensor
78 } // HDI
79 } // OHOS
80 
81 #endif // HDI_SENSOR_MANAGER_H