1 /** 2 * Copyright 2021 Huawei Technologies Co., Ltd 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef MINDSPORE_CCSRC_MINDDATA_DATASET_PLUGIN_PLUGIN_LOADER_H_ 17 #define MINDSPORE_CCSRC_MINDDATA_DATASET_PLUGIN_PLUGIN_LOADER_H_ 18 19 #include <map> 20 #include <string> 21 #include <utility> 22 23 #include "minddata/dataset/plugin/include/shared_include.h" 24 #include "minddata/dataset/util/log_adapter.h" 25 #include "minddata/dataset/util/status.h" 26 27 namespace mindspore { 28 namespace dataset { 29 30 // This class manages all MindData's plugins. It serves as the singleton that owns all plugins and bridge the gap 31 // between C++ RAII and C style functions 32 class PluginLoader { 33 public: 34 /// \brief Singleton getter, 35 /// \return pointer to PluginLoader 36 static PluginLoader *GetInstance() noexcept; 37 38 PluginLoader() = default; 39 40 /// \brief destructor, will call unload internally to unload all plugins managed by PluginLoader 41 ~PluginLoader(); 42 43 /// \brief load an shared object (.so file) via dlopen() and return the ptr to the loaded file (singleton_plugin). 44 /// \param[in] filename the full path to .so file 45 /// \param[out] singleton_plugin pointer to the loaded file 46 /// \return status code 47 Status LoadPlugin(const std::string &filename, plugin::PluginManagerBase **singleton_plugin); 48 49 private: 50 /// \brief Unload so file, internally will call dlclose() and delete its handle. 51 /// \param[in] filename, the full path to .so file 52 /// \return status code 53 Status UnloadPlugin(const std::string &filename); 54 55 std::map<std::string, std::pair<plugin::PluginManagerBase *, void *>> 56 plugins_; // key: path, val: plugin, dlopen handle 57 }; 58 59 } // namespace dataset 60 } // namespace mindspore 61 #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_PLUGIN_PLUGIN_LOADER_H_ 62