1bae4d13cSopenharmony_ci/* 2bae4d13cSopenharmony_ci * Copyright (c) 2021 Huawei Device Co., Ltd. 3bae4d13cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4bae4d13cSopenharmony_ci * you may not use this file except in compliance with the License. 5bae4d13cSopenharmony_ci * You may obtain a copy of the License at 6bae4d13cSopenharmony_ci * 7bae4d13cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8bae4d13cSopenharmony_ci * 9bae4d13cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10bae4d13cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11bae4d13cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12bae4d13cSopenharmony_ci * See the License for the specific language governing permissions and 13bae4d13cSopenharmony_ci * limitations under the License. 14bae4d13cSopenharmony_ci */ 15bae4d13cSopenharmony_ci 16bae4d13cSopenharmony_ci#ifndef SENSOR_MANAGER_H 17bae4d13cSopenharmony_ci#define SENSOR_MANAGER_H 18bae4d13cSopenharmony_ci 19bae4d13cSopenharmony_ci#include <mutex> 20bae4d13cSopenharmony_ci#include <thread> 21bae4d13cSopenharmony_ci#include <unordered_map> 22bae4d13cSopenharmony_ci 23bae4d13cSopenharmony_ci#include "client_info.h" 24bae4d13cSopenharmony_ci#include "flush_info_record.h" 25bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 26bae4d13cSopenharmony_ci#include "sensor_data_processer.h" 27bae4d13cSopenharmony_ci#include "sensor_hdi_connection.h" 28bae4d13cSopenharmony_ci#else 29bae4d13cSopenharmony_ci#include "sensor.h" 30bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 31bae4d13cSopenharmony_ci 32bae4d13cSopenharmony_cinamespace OHOS { 33bae4d13cSopenharmony_cinamespace Sensors { 34bae4d13cSopenharmony_ciusing namespace Security::AccessToken; 35bae4d13cSopenharmony_ciclass SensorManager : public Singleton<SensorManager> { 36bae4d13cSopenharmony_cipublic: 37bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 38bae4d13cSopenharmony_ci void InitSensorMap(const std::unordered_map<int32_t, Sensor> &sensorMap, sptr<SensorDataProcesser> dataProcesser, 39bae4d13cSopenharmony_ci sptr<ReportDataCallback> dataCallback); 40bae4d13cSopenharmony_ci bool SetBestSensorParams(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); 41bae4d13cSopenharmony_ci bool ResetBestSensorParams(int32_t sensorId); 42bae4d13cSopenharmony_ci void StartDataReportThread(); 43bae4d13cSopenharmony_ci#else 44bae4d13cSopenharmony_ci void InitSensorMap(const std::unordered_map<int32_t, Sensor> &sensorMap); 45bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 46bae4d13cSopenharmony_ci bool SaveSubscriber(int32_t sensorId, uint32_t pid, int64_t samplingPeriodNs, int64_t maxReportDelayNs); 47bae4d13cSopenharmony_ci SensorBasicInfo GetSensorInfo(int32_t sensorId, int64_t samplingPeriodNs, int64_t maxReportDelayNs); 48bae4d13cSopenharmony_ci bool IsOtherClientUsingSensor(int32_t sensorId, int32_t clientPid); 49bae4d13cSopenharmony_ci ErrCode AfterDisableSensor(int32_t sensorId); 50bae4d13cSopenharmony_ci void GetPackageName(AccessTokenID tokenId, std::string &packageName); 51bae4d13cSopenharmony_ci 52bae4d13cSopenharmony_ciprivate: 53bae4d13cSopenharmony_ci#ifdef HDF_DRIVERS_INTERFACE_SENSOR 54bae4d13cSopenharmony_ci SensorHdiConnection &sensorHdiConnection_ = SensorHdiConnection::GetInstance(); 55bae4d13cSopenharmony_ci std::thread dataThread_; 56bae4d13cSopenharmony_ci sptr<SensorDataProcesser> sensorDataProcesser_ = nullptr; 57bae4d13cSopenharmony_ci sptr<ReportDataCallback> reportDataCallback_ = nullptr; 58bae4d13cSopenharmony_ci#endif // HDF_DRIVERS_INTERFACE_SENSOR 59bae4d13cSopenharmony_ci ClientInfo &clientInfo_ = ClientInfo::GetInstance(); 60bae4d13cSopenharmony_ci std::unordered_map<int32_t, Sensor> sensorMap_; 61bae4d13cSopenharmony_ci std::mutex sensorMapMutex_; 62bae4d13cSopenharmony_ci}; 63bae4d13cSopenharmony_ci} // namespace Sensors 64bae4d13cSopenharmony_ci} // namespace OHOS 65bae4d13cSopenharmony_ci#endif // SENSOR_MANAGER_H 66