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 sensorId); 37 bool IsContinuousType(int32_t sensorId); 38 void SavePrintUserInfo(const RecordSensorCallback callback); 39 void RemovePrintUserInfo(const RecordSensorCallback callback); 40 void PrintSensorDataLog(const std::string &name, const SensorData &data); 41 42 private: 43 void PrintClientData(const SensorEvent &event); 44 void PrintHdiData(const SensorData &sensorData); 45 int32_t GetDataDimension(int32_t sensorId); 46 struct LogPrintInfo { 47 int32_t count { 0 }; 48 int64_t lastTime { 0 }; 49 }; 50 std::mutex hdiLoginfoMutex_; 51 std::mutex clientLoginfoMutex_; 52 LogPrintInfo info_; 53 std::map<int32_t, LogPrintInfo> hdiLoginfo_ = { 54 {SENSOR_TYPE_ID_ACCELEROMETER, info_}, 55 {SENSOR_TYPE_ID_GYROSCOPE, info_}, 56 {SENSOR_TYPE_ID_POSTURE, info_}, 57 {SENSOR_TYPE_ID_AMBIENT_LIGHT, info_}, 58 {SENSOR_TYPE_ID_AMBIENT_LIGHT1, info_}, 59 {SENSOR_TYPE_ID_MAGNETIC_FIELD, info_}, 60 }; 61 std::map<RecordSensorCallback, LogPrintInfo> clientLoginfo_; 62 }; 63 } // namespace Sensors 64 } // namespace OHOS 65 #endif // PRINT_SENSOR_DATA 66