ConfigModule.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #pragma once
  2. #include <string>
  3. #include <iostream>
  4. #include <fstream>
  5. #include "AIStatus.h"
  6. #include "nlohmann/json.hpp"
  7. class ConfigModule
  8. {
  9. public:
  10. int init(const std::string &filePath);
  11. int getPipelineUpdateResource(const int &pipelineId, const bool isEnable, std::vector<int> &needCreateRsource, std::vector<int> &needDeleteResource);
  12. int getAllPipelineIdNameStatus(std::vector<std::tuple<int, std::string, bool>> &uidPipilineIdNameStatusMap) const;
  13. int setPipelineUpdateConfig(const int &pipelineId, bool isEnable);
  14. int getPipelineModelConfig(const int &pipelineId, const int &modeUid, const std::string &key, float &value) const;
  15. int setPipelineModelConfig(const int &pipelineId, const int &modeUid, const std::string &key, const float &value);
  16. /**
  17. * @brief 初始化资源的二维整数向量。
  18. *
  19. * 该二维向量存储 pipeline 存储初始化资源的顺序。外层向量表示不同 pipeline 的初始化资源的顺序,内层向量该pipeline每个 uid 对应资源初始化顺序。
  20. *
  21. * 示例 :
  22. * - pipeline = [[1,2],[1,3]] 则存入的init_resource_数据为 [[1,2],[3]]
  23. */
  24. std::vector<std::vector<int>> initResourceOrder;
  25. /**
  26. * @brief 推理资源的元组向量。
  27. *
  28. * 该向量存储 pipeline 推理资源的顺序。每个元组包含一个 pipeline的uid 和 其对应推理资源的uid。
  29. *
  30. *
  31. * 示例 :
  32. * - infer_resource_ = [[91,[1,2]],[92,[1,3]]],该向量表示要运行两个pipeline 第一个的uid是91,用的资源是1->2,以此类推
  33. */
  34. std::vector<std::tuple<int, std::vector<int>>> uidInferResourceMap;
  35. /**
  36. * @brief UID 对应资源类型的无序映射。
  37. *
  38. * 该无序映射用于存储每个 UID 对应的资源类型,其中 UID 是整数,资源类型是是pre_process或model。
  39. *
  40. * 示例 :
  41. * - UID 1 对应资源类型 "pre_process"
  42. * - UID 2 对应资源类型 "model"
  43. */
  44. // std::unordered_map<int, std::string> resource_type_;
  45. std::unordered_map<int, std::string> uidResourceTypeMap;
  46. /**
  47. * @brief 存储配置数据的 JSON 对象。
  48. *
  49. * 该 JSON 对象用于存储配置数据,使用 nlohmann::json 类型。
  50. *
  51. */
  52. nlohmann::json configData;
  53. private:
  54. /**
  55. * @brief 管道 UID 到名称的无序映射。
  56. *
  57. * 该无序映射用于存储管道 UID 到名称的映射关系,其中 UID 是整数,名称是字符串。
  58. *
  59. * 示例 :
  60. * - 管道 UID 为 1 对应名称 "pet_detect"
  61. * - 管道 UID 为 2 对应名称 "fire_detect"
  62. */
  63. std::unordered_map<int, std::string> uidPipilineNameMap;
  64. /**
  65. * @brief 存储配置文件路径的字符串。
  66. *
  67. * 该字符串用于存储配置文件的路径。
  68. *
  69. * 示例 :
  70. * - "/path/to/config/file.json"
  71. */
  72. std::string configFilePath;
  73. /**
  74. * @brief 存储管道信息的元组向量。
  75. *
  76. * 该向量包含每个管道的信息,每个元组包含以下字段 :
  77. * - ID :整数,管道的唯一标识符。
  78. * - Name :字符串,管道的名称。
  79. * - Steps :整数向量,表示管道的步骤信息。
  80. * - Enabled :布尔值,表示管道是否启用。
  81. *
  82. * 示例 :
  83. * - (91, "fire_detect", [1, 2, 3], true)
  84. * - (92, "pet_detect", [4, 5], false)
  85. */
  86. std::vector<std::tuple<int, std::string, std::vector<int>, bool>> uidPipilineInfo;
  87. /**
  88. * @brief 更新配置文件。
  89. *
  90. * 该函数用于更新配置文件内容。
  91. *
  92. * @return 返回更新操作的状态码,如果成功返回0,否则返回错误码。
  93. * - AIStatus::ErrorCode::JSON_O_UPDATE: 打开配置文件失败。
  94. */
  95. int updateCfgFile();
  96. int updateAICFG();
  97. };