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 <vector> 15 #include <set> 16 17 #include "generator.h" 18 19 namespace OHOS { 20 namespace Hardware { 21 struct HostInfo { 22 std::string hostCaps; 23 std::string hostUID; 24 std::string hostGID; 25 std::string hostCritical; 26 std::vector<std::string> initConfig; 27 std::vector<std::pair<std::string, std::string>> mallocOpt; 28 uint32_t hostPriority; 29 int32_t processPriority; 30 int32_t threadPriority; 31 uint32_t hostId; 32 uint32_t sandBox; 33 bool dynamicLoad; 34 }; 35 36 enum EXPECT_TYPE { 37 EXPECT_HOST_NAME, 38 EXPECT_HOST_PRIORITY, 39 EXPECT_HOST_CAPS, 40 EXPECT_DEVICE_PROLOAD, 41 EXPECT_TYPE_BUTT, 42 }; 43 44 class StartupCfgGen : public Generator { 45 public: 46 explicit StartupCfgGen(const std::shared_ptr<Ast> &ast); 47 48 ~StartupCfgGen() override = default; 49 50 bool Output() override; 51 52 private: 53 bool Initialize(); 54 55 static void InitHostInfo(HostInfo &hostData); 56 57 bool TemplateNodeSeparate(); 58 59 bool GetHostInfo(); 60 61 void HostInfoOutput(const std::string &name, bool end); 62 63 void HeaderTopOutput(); 64 65 void HeaderBottomOutput(); 66 67 void HostInfosOutput(); 68 69 void EmitDynamicLoad(const std::string &name, std::set<std::string> &configedKeywords); 70 71 void EmitPathInfo(const std::string &name, std::set<std::string> &configedKeywords); 72 73 void EmitIdInfo(const std::string &name, std::set<std::string> &configedKeywords); 74 75 void EmitHostCapsInfo(const std::string &name, std::set<std::string> &configedKeywords); 76 77 void EmitHostCriticalInfo(const std::string &name, std::set<std::string> &configedKeywords); 78 79 void EmitSandBoxInfo(const std::string &name, std::set<std::string> &configedKeywords); 80 81 void EmitSeconInfo(const std::string &name, std::set<std::string> &configedKeywords); 82 83 void EmitInitConfigInfo(const std::string &name); 84 85 static void GetConfigArray(const std::shared_ptr<AstObject> &term, std::string &config); 86 87 static void GetConfigVector(const std::shared_ptr<AstObject> &term, std::vector<std::string> &config); 88 89 static void GetConfigIntArray(const std::shared_ptr<AstObject> &term, std::string &config); 90 91 static void GetHostLoadMode(const std::shared_ptr<AstObject> &hostInfo, HostInfo &hostData); 92 93 static void GetHostGID(const std::shared_ptr<AstObject> &term, std::string &config, const std::string &name); 94 95 static void GetProcessPriority(const std::shared_ptr<AstObject> &term, HostInfo &hostData); 96 97 static void GetMallocOpt(const std::shared_ptr<AstObject> &hostInfo, 98 std::vector<std::pair<std::string, std::string>> &config); 99 100 std::ofstream ofs_; 101 std::string outFileName_; 102 std::map<std::string, HostInfo> hostInfoMap_; 103 }; 104 } // namespace Hardware 105 } // namespace OHOS 106 #endif // HC_STARTUP_CFG_GEN_H 107