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