1 /*
2  * Copyright (c) 2022 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 OHOS_DISTRIBUTED_CAMERA_SOURCE_HIDUMPER_H
17 #define OHOS_DISTRIBUTED_CAMERA_SOURCE_HIDUMPER_H
18 
19 #include <map>
20 #include <string>
21 #include <vector>
22 
23 #include "single_instance.h"
24 
25 namespace OHOS {
26 namespace DistributedHardware {
27 class DCameraSourceDev;
28 enum class HidumpFlag {
29     UNKNOWN = 0,
30     GET_HELP,
31     GET_REGISTERED_INFO,
32     GET_CURRENTSTATE_INFO,
33     GET_VERSION_INFO,
34     START_DUMP,
35     STOP_DUMP,
36 };
37 
38 typedef enum {
39     DCAMERA_STATE_INIT_DUMP = 0,
40     DCAMERA_STATE_REGIST_DUMP = 1,
41     DCAMERA_STATE_OPENED_DUMP = 2,
42     DCAMERA_STATE_CONFIG_STREAM_DUMP = 3,
43     DCAMERA_STATE_CAPTURE_DUMP = 4,
44 } DCameraState;
45 
46 struct CameraDumpInfo {
47     std::string version;
48     int32_t regNumber;
49     std::map<std::string, int32_t> curState;
50 };
51 
52 class DcameraSourceHidumper {
53 DECLARE_SINGLE_INSTANCE_BASE(DcameraSourceHidumper);
54 
55 public:
56     bool Dump(const std::vector<std::string>& args, std::string& result);
57 
58 private:
59     explicit DcameraSourceHidumper() = default;
60     ~DcameraSourceHidumper() = default;
61     void ShowHelp(std::string& result);
62     int32_t ShowIllegalInfomation(std::string& result);
63     int32_t ProcessDump(const std::string& args, std::string& result);
64     void SetSourceDumpInfo(CameraDumpInfo& camDumpInfo_);
65 
66     int32_t GetRegisteredInfo(std::string& result);
67     int32_t GetCurrentStateInfo(std::string& result);
68     int32_t GetVersionInfo(std::string& result);
69 
70 private:
71     CameraDumpInfo camDumpInfo_;
72     const int32_t DUMP_MAX_SIZE = 10 * 1024;
73 };
74 } // namespace DistributedHardware
75 } // namespace OHOS
76 #endif // OHOS_DISTRIBUTED_CAMERA_SOURCE_HIDUMPER_H