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