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 int32_t processPriority; 25 int32_t threadPriority; 26 uint32_t hostId; 27 uint32_t sandBox; 28 bool dynamicLoad; 29 }; 30 31 enum EXPECT_TYPE { 32 EXPECT_HOST_NAME, 33 EXPECT_HOST_PRIORITY, 34 EXPECT_HOST_CAPS, 35 EXPECT_DEVICE_PROLOAD, 36 EXPECT_TYPE_BUTT, 37 }; 38 39 class StartupCfgGen : public Generator { 40 public: 41 explicit StartupCfgGen(const std::shared_ptr<Ast> &ast); 42 43 ~StartupCfgGen() override = default; 44 45 bool Output() override; 46 47 private: 48 bool Initialize(); 49 50 static void InitHostInfo(HostInfo &hostData); 51 52 bool TemplateNodeSeparate(); 53 54 bool GetHostInfo(); 55 56 void HostInfoOutput(const std::string &name, bool end); 57 58 void HeaderTopOutput(); 59 60 void HeaderBottomOutput(); 61 62 void HostInfosOutput(); 63 64 static void GetConfigArray(const std::shared_ptr<AstObject> &term, std::string &config); 65 66 static void GetConfigIntArray(const std::shared_ptr<AstObject> &term, std::string &config); 67 68 static void GetHostLoadMode(const std::shared_ptr<AstObject> &hostInfo, HostInfo &hostData); 69 70 static void GetHostGID(const std::shared_ptr<AstObject> &term, std::string &config, const std::string &name); 71 72 static void GetProcessPriority(const std::shared_ptr<AstObject> &term, HostInfo &hostData); 73 74 std::ofstream ofs_; 75 std::string outFileName_; 76 std::map<std::string, HostInfo> hostInfoMap_; 77 }; 78 } // namespace Hardware 79 } // namespace OHOS 80 #endif // HC_STARTUP_CFG_GEN_H 81