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 SENSORS_DATA_PROCESSER_H 17 #define SENSORS_DATA_PROCESSER_H 18 19 #include "fifo_cache_data.h" 20 #include "flush_info_record.h" 21 #include "sensor_hdi_connection.h" 22 23 namespace OHOS { 24 namespace Sensors { 25 class SensorDataProcesser : public RefBase { 26 public: 27 explicit SensorDataProcesser(const std::unordered_map<int32_t, Sensor> &sensorMap); 28 virtual ~SensorDataProcesser(); 29 int32_t ProcessEvents(sptr<ReportDataCallback> dataCallback); 30 int32_t SendEvents(sptr<SensorBasicDataChannel> &channel, SensorData &data); 31 static int DataThread(sptr<SensorDataProcesser> dataProcesser, sptr<ReportDataCallback> dataCallback); 32 int32_t CacheSensorEvent(const SensorData &data, sptr<SensorBasicDataChannel> &channel); 33 34 private: 35 DISALLOW_COPY_AND_MOVE(SensorDataProcesser); 36 void ReportData(sptr<SensorBasicDataChannel> &channel, SensorData &data); 37 bool ReportNotContinuousData(std::unordered_map<int32_t, SensorData> &cacheBuf, 38 sptr<SensorBasicDataChannel> &channel, SensorData &data); 39 void SendNoneFifoCacheData(std::unordered_map<int32_t, SensorData> &cacheBuf, 40 sptr<SensorBasicDataChannel> &channel, SensorData &data, uint64_t periodCount); 41 void SendFifoCacheData(std::unordered_map<int32_t, SensorData> &cacheBuf, 42 sptr<SensorBasicDataChannel> &channel, SensorData &data, uint64_t periodCount, 43 uint64_t fifoCount); 44 void SendRawData(std::unordered_map<int32_t, SensorData> &cacheBuf, sptr<SensorBasicDataChannel> channel, 45 std::vector<SensorData> events); 46 void EventFilter(CircularEventBuf &eventsBuf); 47 ClientInfo &clientInfo_ = ClientInfo::GetInstance(); 48 FlushInfoRecord &flushInfo_ = FlushInfoRecord::GetInstance(); 49 std::mutex dataCountMutex_; 50 std::unordered_map<int32_t, std::vector<sptr<FifoCacheData>>> dataCountMap_; 51 std::mutex sensorMutex_; 52 std::unordered_map<int32_t, Sensor> sensorMap_; 53 }; 54 } // namespace Sensors 55 } // namespace OHOS 56 #endif // endif SENSORS_DATA_PROCESSER_H 57