1 /* 2 * Copyright (c) 2023 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 HDI_CAMERA_DUMP_H 17 #define HDI_CAMERA_DUMP_H 18 19 #include <string> 20 #include <map> 21 #include <thread> 22 #include <mutex> 23 #include <condition_variable> 24 #include "camera_metadata_operator.h" 25 #include "camera_metadata_info.h" 26 #include "devhost_dump_reg.h" 27 #include "hdf_sbuf.h" 28 #include "ibuffer.h" 29 30 namespace OHOS::Camera { 31 enum DumpType { 32 MedataType, 33 BufferType 34 }; 35 36 class CameraDumper { 37 public: 38 ~CameraDumper (); 39 bool DumpBuffer(const std::shared_ptr<IBuffer>& buffer); 40 bool DumpMetadata(const std::shared_ptr<CameraMetadata>& metadata, std::string tag = "camera"); 41 void ShowDumpMenu(struct HdfSBuf *reply); 42 void CameraHostDumpProcess(struct HdfSBuf *data, struct HdfSBuf *reply); GetInstance()43 static CameraDumper& GetInstance() 44 { 45 static CameraDumper instance_; 46 return instance_; 47 } 48 49 private: CameraDumper()50 CameraDumper() {} 51 bool IsDumpOpened(DumpType type); 52 uint64_t GetCurrentLocalTimeStamp(); 53 void UpdateDumpMode(DumpType type, bool isDump, struct HdfSBuf *reply); 54 bool SaveDataToFile(const char *fileName, const void *data, uint32_t size); 55 void CheckDiskInfo(); 56 void ThreadWorkFun(); 57 void StartCheckDiskInfo(); 58 void StopCheckDiskInfo(); 59 60 private: 61 std::mutex dumpStateLock_; 62 std::condition_variable cv_; 63 std::mutex terminateLock_; 64 bool terminate_ = true; 65 std::unique_ptr<std::thread> handleThread_ = nullptr; 66 }; 67 68 int32_t CameraDumpEvent(struct HdfSBuf *data, struct HdfSBuf *reply); 69 70 } // OHOS::Camera 71 72 #endif // HDI_CAMERA_DUMP_H 73