• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 PRINT_SENSOR_DATA
17 #define PRINT_SENSOR_DATA
18 
19 #include <map>
20 
21 #include "singleton.h"
22 
23 #include "sensor_agent_type.h"
24 #include "sensor_data_event.h"
25 
26 namespace OHOS {
27 namespace Sensors {
28 
29 
30 class PrintSensorData : public Singleton<PrintSensorData> {
31 public:
32     PrintSensorData() = default;
~PrintSensorData()33     virtual ~PrintSensorData() {};
34     void ControlSensorClientPrint(const RecordSensorCallback callback, const SensorEvent &event);
35     void ControlSensorHdiPrint(const SensorData &sensorData);
36     void ResetHdiCounter(int32_t sensorType);
37     bool IsContinuousType(int32_t sensorType);
38     void SavePrintUserInfo(const RecordSensorCallback callback);
39     void RemovePrintUserInfo(const RecordSensorCallback callback);
40     void PrintSensorDataLog(const std::string &name, const SensorData &data);
41     void PrintSensorInfo(SensorInfo *sensorInfos, int32_t sensorInfoCount);
42     void ResetHdiTimes(int32_t sensorType);
43 
44 private:
45     void PrintClientData(const SensorEvent &event);
46     void PrintHdiData(const SensorData &sensorData);
47     int32_t GetDataDimension(int32_t sensorType);
48     void ProcessHdiDFX(const SensorData &sensorData);
49     void ProcessClientDFX(const SensorEvent &event);
50     struct LogPrintInfo {
51         int32_t count { 0 };
52         int64_t lastTime { 0 };
53         int64_t hdiTimesFlag { 0 };
54         int64_t hdiTimes { 0 };
55         int64_t clientTimesFlag { 0 };
56         int64_t clientTimes { 0 };
57     };
58     std::mutex hdiLoginfoMutex_;
59     std::mutex clientLoginfoMutex_;
60     LogPrintInfo info_;
61     std::map<int32_t, LogPrintInfo> hdiLoginfo_ = {
62         {SENSOR_TYPE_ID_ACCELEROMETER, info_},
63         {SENSOR_TYPE_ID_AMBIENT_LIGHT, info_},
64         {SENSOR_TYPE_ID_AMBIENT_LIGHT1, info_},
65         {SENSOR_TYPE_ID_GRAVITY, info_},
66         {SENSOR_TYPE_ID_GYROSCOPE, info_},
67         {SENSOR_TYPE_ID_MAGNETIC_FIELD, info_},
68         {SENSOR_TYPE_ID_ORIENTATION, info_},
69         {SENSOR_TYPE_ID_POSTURE, info_},
70         {SENSOR_TYPE_ID_ROTATION_VECTOR, info_},
71     };
72     std::map<RecordSensorCallback, LogPrintInfo> clientLoginfo_;
73 };
74 } // namespace Sensors
75 } // namespace OHOS
76 #endif // PRINT_SENSOR_DATA
77