37namespace plugin_manager {
42 std::string* library_path) {
43 tinyxml2::XMLDocument doc;
44 if (doc.LoadFile(file_path.c_str()) != tinyxml2::XML_SUCCESS) {
45 AWARN <<
"fail to process file " << file_path;
48 const tinyxml2::XMLElement* root = doc.RootElement();
51 *library_path = root->Attribute(
"path");
59 const std::string& plugin_description_file_path) {
60 AINFO <<
"loading plugin from description[" << plugin_description_file_path
64 std::make_shared<apollo::cyber::plugin_manager::PluginDescription>();
65 if (!description->ParseFromDescriptionFile(plugin_description_file_path)) {
69 if (plugin_description_map_.find(description->name_) !=
70 plugin_description_map_.end()) {
71 AWARN <<
"plugin [" << description->name_ <<
"] already loaded";
75 if (!
LoadLibrary(description->actual_library_path_)) {
76 AWARN <<
"plugin description[" << plugin_description_file_path <<
"] name["
77 << description->name_ <<
"] load failed, library["
78 << description->actual_library_path_ <<
"] invalid";
82 plugin_loaded_map_[description->name_] =
true;
83 plugin_description_map_[description->name_] = description;
84 for (
auto& class_name_pair : description->class_name_base_class_name_map_) {
85 plugin_class_plugin_name_map_[class_name_pair] = description->name_;
87 AINFO <<
"plugin description[" << plugin_description_file_path <<
"] name["
88 << description->name_ <<
"] load success";
99 std::vector<std::string>* path_list) {
102 base_path,
"cyber_plugin_index", DT_DIR,
true, path_list);
107 const std::string& plugin_index_path) {
108 std::vector<std::string> plugin_index_list;
112 for (
auto plugin_index : plugin_index_list) {
114 AINFO <<
"plugin index[" << plugin_index <<
"] name[" << plugin_name
116 if (plugin_description_map_.find(plugin_name) !=
117 plugin_description_map_.end()) {
118 AWARN <<
"plugin [" << plugin_name <<
"] already loaded";
122 auto description = std::make_shared<PluginDescription>(plugin_name);
123 if (!description->ParseFromIndexFile(plugin_index)) {
137 plugin_loaded_map_[description->name_] =
false;
138 plugin_description_map_[description->name_] = description;
139 for (
auto& class_name_pair : description->class_name_base_class_name_map_) {
140 plugin_class_plugin_name_map_[class_name_pair] = description->name_;
142 AINFO <<
"plugin index[" << plugin_index <<
"] name[" << description->name_
143 <<
"] lazy load success";
151 AWARN <<
"search plugin index path under bazel-bin enabled, it may take "
152 "longer time to load plugins";
154 const std::string apollo_root =
157 const std::string bazel_bin_path = apollo_root +
"/bazel-bin";
158 std::vector<std::string> user_plugin_index_path_list;
159 AINFO <<
"scanning plugin index path under " << bazel_bin_path;
162 for (
auto dir : user_plugin_index_path_list) {
163 AINFO <<
"loading user plugins from path[" << dir <<
"]";
168 std::string plugin_index_path =
170 if (plugin_index_path.empty()) {
172 const std::string apollo_distribution_home =
174 const std::string plugin_index_path =
175 apollo_distribution_home +
"/share/cyber_plugin_index";
177 AINFO <<
"loading plugins from APOLLO_PLUGIN_INDEX_PATH[" << plugin_index_path
182 index = plugin_index_path.find(
':', begin);
183 auto p = plugin_index_path.substr(begin, index - begin);
185 AINFO <<
"loading plugins from plugin index path[" << p <<
"]";
188 AWARN <<
"plugin index path[" << p <<
"] not exists";
191 }
while (index != std::string::npos);
196 if (!class_loader_manager_.
LoadLibrary(library_path)) {
197 AWARN <<
"plugin library[" << library_path <<
"] load failed";
bool LoadLibrary(const std::string &library_path)
static PluginManager * Instance()
get singleton instance of PluginManager
bool LoadInstalledPlugins()
load plugins from installed path
bool LoadPlugin(const std::string &plugin_description_file_path)
load plugin clases from file
bool LoadLibrary(const std::string &library_path)
load library of plugin
bool FindPluginIndexAndLoad(const std::string &plugin_index_path)
find plugin index file and load plugins
bool ProcessPluginDescriptionFile(const std::string &file_path, std::string *library_path)
parse plugin description file and load the library TODO(liangjinping): parse description to struct
size_t FindPathByPattern(const std::string &base_path, const std::string &patt, const unsigned char d_type, const bool recursive, std::vector< std::string > *result_list)
Find path with pattern
std::string GetFileName(const std::string &path, const bool remove_extension)
std::string GetEnv(const std::string &var_name, const std::string &default_value="")
bool DirectoryExists(const std::string &directory_path)
Check if the directory specified by directory_path exists and is indeed a directory.
bool FindPlunginIndexPath(const std::string &base_path, std::vector< std::string > *path_list)
find cyber_plugin_index directory