1 /*
2  * Copyright (c) 2024-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 #include "camera_info_dumper.h"
17 
18 #include <cstdint>
19 #include <unistd.h>
20 
21 namespace OHOS {
22 namespace CameraStandard {
Title(const char * msg)23 void CameraInfoDumper::Title(const char* msg)
24 {
25     for (int32_t i = 0; i < depth_; i++) {
26         dumperString_.append("    ");
27     };
28     for (int32_t i = 0; i < depth_; i++) {
29         dumperString_.append("#");
30     };
31     dumperString_.append("# ");
32     dumperString_.append(msg);
33     dumperString_.append("\n");
34 }
Title(const std::string msg)35 void CameraInfoDumper::Title(const std::string msg)
36 {
37     Title(msg.c_str());
38 }
Msg(const char * msg)39 void CameraInfoDumper::Msg(const char* msg)
40 {
41     for (int32_t i = 0; i < depth_; i++) {
42         dumperString_.append("    ");
43     };
44     for (int32_t i = 0; i < depth_; i++) {
45         dumperString_.append(" ");
46     };
47     dumperString_.append("  ");
48     dumperString_.append(msg);
49     dumperString_.append("\n");
50 }
51 
Msg(const std::string msg)52 void CameraInfoDumper::Msg(const std::string msg)
53 {
54     Msg(msg.c_str());
55 }
56 
Tip(const char * msg)57 void CameraInfoDumper::Tip(const char* msg)
58 {
59     dumperString_.append(msg);
60     dumperString_.append("\n");
61 }
62 
Tip(const std::string msg)63 void CameraInfoDumper::Tip(const std::string msg)
64 {
65     Tip(msg.c_str());
66 }
67 
Push()68 void CameraInfoDumper::Push()
69 {
70     depth_++;
71 }
72 
Pop()73 void CameraInfoDumper::Pop()
74 {
75     depth_--;
76     if (depth_ < 0) {
77         depth_ = 0;
78     }
79 }
80 
Print()81 void CameraInfoDumper::Print()
82 {
83     if (dumperString_.empty()) {
84         return;
85     }
86     (void)write(outFd_, dumperString_.c_str(), dumperString_.size());
87 }
88 } // namespace CameraStandard
89 } // namespace OHOS
90