• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<SensorDescription, 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     void UpdateSensorMap(const std::unordered_map<SensorDescription, Sensor> &sensorMap);
34 
35 private:
36     DISALLOW_COPY_AND_MOVE(SensorDataProcesser);
37     void ReportData(sptr<SensorBasicDataChannel> &channel, SensorData &data);
38     bool ReportNotContinuousData(std::unordered_map<SensorDescription, SensorData> &cacheBuf,
39                                  sptr<SensorBasicDataChannel> &channel, SensorData &data);
40     void SendNoneFifoCacheData(std::unordered_map<SensorDescription, SensorData> &cacheBuf,
41                                sptr<SensorBasicDataChannel> &channel, SensorData &data, uint64_t periodCount);
42     void SendFifoCacheData(std::unordered_map<SensorDescription, SensorData> &cacheBuf,
43                            sptr<SensorBasicDataChannel> &channel, SensorData &data, uint64_t periodCount,
44                            uint64_t fifoCount);
45     void SendRawData(std::unordered_map<SensorDescription, SensorData> &cacheBuf, sptr<SensorBasicDataChannel> channel,
46                      std::vector<SensorData> events);
47     void EventFilter(CircularEventBuf &eventsBuf);
48     void UpdataFifoDataChannel(sptr<SensorBasicDataChannel> &channel, std::vector<sptr<FifoCacheData>> &dataCount);
49     ClientInfo &clientInfo_ = ClientInfo::GetInstance();
50     FlushInfoRecord &flushInfo_ = FlushInfoRecord::GetInstance();
51     std::mutex dataCountMutex_;
52     std::unordered_map<SensorDescription, std::vector<sptr<FifoCacheData>>> dataCountMap_;
53     std::mutex sensorMutex_;
54     std::unordered_map<SensorDescription, Sensor> sensorMap_;
55 };
56 } // namespace Sensors
57 } // namespace OHOS
58 #endif // endif SENSORS_DATA_PROCESSER_H
59