• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef HC_STARTUP_CFG_GEN_H
10 #define HC_STARTUP_CFG_GEN_H
11 
12 #include <fstream>
13 #include <map>
14 #include "generator.h"
15 
16 namespace OHOS {
17 namespace Hardware {
18 struct HostInfo {
19     std::string hostCaps;
20     std::string hostUID;
21     std::string hostGID;
22     std::string hostCritical;
23     uint32_t hostPriority;
24     uint32_t hostId;
25     bool dynamicLoad;
26 };
27 
28 enum EXPECT_TYPE {
29     EXPECT_HOST_NAME,
30     EXPECT_HOST_PRIORITY,
31     EXPECT_HOST_CAPS,
32     EXPECT_DEVICE_PROLOAD,
33     EXPECT_TYPE_BUTT,
34 };
35 
36 class StartupCfgGen : public Generator {
37 public:
38     explicit StartupCfgGen(const std::shared_ptr<Ast> &ast);
39 
40     ~StartupCfgGen() override = default;
41 
42     bool Output() override;
43 
44 private:
45     bool Initialize();
46 
47     static void InitHostInfo(HostInfo &hostData);
48 
49     bool TemplateNodeSeparate();
50 
51     bool GetHostInfo();
52 
53     void HostInfoOutput(const std::string &name, bool end);
54 
55     void HeaderTopOutput();
56 
57     void HeaderBottomOutput();
58 
59     void HostInfosOutput();
60 
61     static void GetConfigArray(const std::shared_ptr<AstObject> &term, std::string &config);
62 
63     static void GetConfigIntArray(const std::shared_ptr<AstObject> &term, std::string &config);
64 
65     static void GetHostLoadMode(const std::shared_ptr<AstObject> &hostInfo, HostInfo &hostData);
66 
67     static void GetHostGID(const std::shared_ptr<AstObject> &term, std::string &config, const std::string &name);
68 
69     std::ofstream ofs_;
70     std::string outFileName_;
71     std::map<std::string, HostInfo> hostInfoMap_;
72 };
73 } // namespace Hardware
74 } // namespace OHOS
75 #endif // HC_STARTUP_CFG_GEN_H
76