75 {
76 std::string dynamic_model_conf_json_path;
79 AERROR <<
"Failed to load Dynamic Model: " << dm_dir_name
80 << ". conf file is not exists!";
81 return false;
82 }
83 DynamicModelConf dynamic_model_conf;
85 &dynamic_model_conf)) {
86 AERROR <<
"Unable to parse Dynamic model conf from file "
87 << dynamic_model_conf_json_path;
88 return false;
89 }
90 std::string dynamic_model_name = dynamic_model_conf.dynamic_model_name();
91
92 if (!dynamic_model_conf.has_library_name() ||
93 !dynamic_model_conf.has_dynamic_model_name() ||
94 !dynamic_model_conf.has_depend_model_package()) {
95 AERROR <<
"Missing required field!";
96 return false;
97 }
98
101 AERROR <<
"This dynamic model: " << dynamic_model_name
102 << " is already registered!";
103 return false;
104 }
105 std::string dm_library_name = dynamic_model_conf.library_name();
106 std::string depend_model_package = dynamic_model_conf.depend_model_package();
107 std::replace(depend_model_package.begin(), depend_model_package.end(), '-', '_');
108
109 std::string dynamic_model_package_library_path;
111 FLAGS_dynamic_model_package_library_path, "APOLLO_LIB_PATH",
112 &dynamic_model_package_library_path)) {
113 AERROR <<
"Failed to get dynamic model package library path: "
114 << FLAGS_dynamic_model_package_library_path;
115 return false;
116 }
117 dynamic_model_package_library_path +=
118 depend_model_package + "/" + dm_library_name;
120 AINFO <<
"dm_library_name: " << dm_library_name;
121 AINFO <<
"dynamic_model_package_library_path: " << dynamic_model_package_library_path;
122
123 try {
124
125 shared_library =
128 reinterpret_cast<create_t *
>(shared_library->GetSymbol(
"create"));
129 SimControlBase *dynamic_model_ptr =
130 create_dynamic_model(dm_dir_name, home_path_);
131 if (!dynamic_model_ptr) {
132 return false;
133 }
136 dynamic_model_name;
138 dynamic_model_ptr;
141 dynamic_model_conf.depend_model_package();
145 } else {
147 }
148 } catch (const LibraryLoadException &e) {
149 AERROR <<
"LibraryLoadException: " << e.what();
150 return false;
151 } catch (const LibraryAlreadyLoadedException &e) {
152 AERROR <<
"LibraryAlreadyLoadedException: " << e.what();
153 return false;
154 } catch (const SymbolNotFoundException &e) {
155 AERROR <<
"SymbolNotFoundException: " << e.what();
156 return false;
157 }
158 return true;
159}
void GetDynamicModelPath(const std::string &dynamic_model_name, std::string *path, bool get_conf_json=true)
bool PathExists(const std::string &path)
Check if the path exists.
bool GetFilePathWithEnv(const std::string &path, const std::string &env_var, std::string *file_path)
get file path, judgement priority:
bool GetProtoFromJsonFile(const std::string &file_name, google::protobuf::Message *message)
Parses the content of the json file specified by the file_name as ascii representation of protobufs,...
unordered_map< string, int > s_dm_lib_count_
std::shared_ptr< SharedLibrary > SharedLibraryPtr
SimControlBase * create_t(std::string dynamic_name, std::string home_path)
Get SimControl class