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 OHOS_DISTRIBUTED_SCREEN_HIDUMPER_H
17#define OHOS_DISTRIBUTED_SCREEN_HIDUMPER_H
18
19#include <unistd.h>
20#include <sys/types.h>
21#include <sys/stat.h>
22
23#include <cstdio>
24#include <fstream>
25#include <map>
26#include <string>
27#include <vector>
28
29#include "single_instance.h"
30#include "dscreen_constants.h"
31
32namespace OHOS {
33namespace DistributedHardware {
34enum class HidumpFlag {
35    UNKNOWN = 0,
36    GET_HELP,
37    DUMP_SCREEN_DATA,
38    DUMP_SCREEN_DATA_RESTART,
39    DUMP_SCREEN_DATA_STOP,
40};
41
42class DscreenHidumper {
43    DECLARE_SINGLE_INSTANCE_BASE(DscreenHidumper);
44
45public:
46    bool Dump(const std::vector<std::string> &args, std::string &result);
47    bool GetFlagStatus();
48    void SetFlagFalse();
49    bool GetFileFlag();
50    bool GetReDumpFlag();
51    void SetFileFlagFalse();
52    void SetFileFlagTrue();
53    void SetReDumpFlagFalse();
54    void SetReDumpFlagTrue();
55    bool GetTransReDumpFlag();
56    void SetTransReDumpFlagFalse();
57    void SetTransReDumpFlagTrue();
58    void SaveFile(std::string file, const VideoData &video);
59    DscreenHidumper();
60    ~DscreenHidumper();
61
62private:
63    void ShowHelp(std::string &result);
64    int32_t ShowIllegalInfomation(std::string &result);
65    int32_t ProcessDump(const std::string &args, std::string &result);
66
67    int32_t DumpScreenData(std::string &result);
68    int32_t ReDumpScreenData(std::string &result);
69
70private:
71    static const constexpr char *DSCREEN_LOG_TAG = "DscreenHidumper";
72    bool hidumperFlag_ = false;
73    bool fileFullFlag_ = false;
74    bool reDumpFlag_ = false;
75    bool transReDumpFlag_ = false;
76};
77} // namespace DistributedHardware
78} // namespace OHOS
79#endif // OHOS_DISTRIBUTED_SCREEN_HIDUMPER_H