You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

plugin_loader.h 2.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. #include <map>
  19. #include <string>
  20. #include <utility>
  21. #include "minddata/dataset/plugin/include/shared_include.h"
  22. #include "minddata/dataset/util/status.h"
  23. #include "mindspore/core/utils/log_adapter.h"
  24. namespace mindspore {
  25. namespace dataset {
  26. // This class manages all MindData's plugins. It serves as the singleton that owns all plugins and bridge the gap
  27. // between C++ RAII and C style functions
  28. class PluginLoader {
  29. public:
  30. /// \brief Singleton getter,
  31. /// \return pointer to PluginLoader
  32. static PluginLoader *GetInstance() noexcept;
  33. PluginLoader() = default;
  34. /// \brief destructor, will call unload internally to unload all plugins managed by PluginLoader
  35. ~PluginLoader();
  36. /// \brief load an shared object (.so file) via dlopen() and return the ptr to the loaded file (singleton_plugin).
  37. /// \param[in] filename the full path to .so file
  38. /// \param[out] singleton_plugin pointer to the loaded file
  39. /// \return status code
  40. Status LoadPlugin(const std::string &filename, plugin::PluginManagerBase **singleton_plugin);
  41. private:
  42. /// \brief Unload so file, internally will call dlclose() and delete its handle.
  43. /// \param[in] filename, the full path to .so file
  44. /// \return status code
  45. Status UnloadPlugin(const std::string &filename);
  46. std::map<std::string, std::pair<plugin::PluginManagerBase *, void *>>
  47. plugins_; // key: path, val: plugin, dlopen handle
  48. };
  49. } // namespace dataset
  50. } // namespace mindspore
  51. #endif // MINDSPORE_CCSRC_MINDDATA_DATASET_PLUGIN_PLUGIN_LOADER_H_