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_ROSEN_DISPLAY_DUMPER_H
17 #define OHOS_ROSEN_DISPLAY_DUMPER_H
18 
19 #include "dm_common.h"
20 #include "abstract_display_controller.h"
21 #include "abstract_screen_controller.h"
22 
23 namespace OHOS {
24 namespace Rosen {
25 enum DumpType : uint32_t {
26     DUMP_ALL_SCREEN = 0,
27     DUMP_ALL_DISPLAY,
28     DUMP_SCREEN,
29     DUMP_DISPLAY,
30     DUMP_NONE = 100,
31 };
32 class DisplayDumper : public RefBase {
33 public:
34     DisplayDumper(const sptr<AbstractDisplayController>& abstractDisplayController,
35         const sptr<AbstractScreenController>& abstractScreenController, std::recursive_mutex& mutex);
36     DMError Dump(int fd, const std::vector<std::u16string>& args) const;
37 
38 private:
39     void ShowHelpInfo(std::string& dumpInfo) const;
40     void ShowIllegalArgsInfo(std::string& dumpInfo, DMError errCode) const;
41 
42     DMError DumpInfo(const std::vector<std::string>& args, std::string& dumpInfo) const;
43     DMError DumpAllScreenInfo(std::string& dumpInfo) const;
44     DMError DumpScreenInfo(const sptr<AbstractScreenGroup>& screenGroup, std::string& dumpInfo) const;
45     DMError DumpSpecifiedScreenInfo(ScreenId screenId, std::string& dumpInfo) const;
46     DMError DumpAllDisplayInfo(std::string& dumpInfo) const;
47     DMError DumpSpecifiedDisplayInfo(DisplayId displayId, std::string& dumpInfo) const;
48 
49     bool IsValidDigitString(const std::string& idStr) const;
50     std::string TransferTypeToString(ScreenType type) const;
51     void GetScreenInfo(const sptr<AbstractScreen>& screen, std::ostringstream& oss) const;
52     void GetDisplayInfo(const sptr<AbstractDisplay>& display, std::ostringstream& oss) const;
53 
54     const sptr<AbstractDisplayController> abstractDisplayController_;
55     const sptr<AbstractScreenController> abstractScreenController_;
56     std::recursive_mutex& mutex_;
57 };
58 }
59 }
60 #endif // OHOS_ROSEN_DISPLAY_DUMPER_H