Module.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. ///
  2. /// \file Plugin/Module.hpp
  3. ///
  4. /// A PluginModule interacts with loadable library modules and the plugin registry.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2013-2018 Josh Blum
  8. /// SPDX-License-Identifier: BSL-1.0
  9. ///
  10. #pragma once
  11. #include <Pothos/Config.hpp>
  12. #include <memory>
  13. #include <vector>
  14. #include <string>
  15. namespace Pothos {
  16. class Plugin;
  17. /*!
  18. * PluginModule represents a loaded shared library in the filesystem.
  19. */
  20. class POTHOS_API PluginModule
  21. {
  22. public:
  23. //! A reference to a permanent empty module
  24. static const PluginModule &null(void);
  25. /*!
  26. * Create a null PluginModule.
  27. */
  28. PluginModule(void);
  29. /*!
  30. * Create a PluginModule from a file path.
  31. * \throw PluginPluginModuleError if the path does not exist
  32. * \throw PluginPluginModuleError if the load fails
  33. * \param path the path to a loadable module on the file system
  34. */
  35. PluginModule(const std::string &path);
  36. //! Plugin module destructor.
  37. ~PluginModule(void);
  38. /*!
  39. * Test load this library module within a separate process
  40. * to avoid loading something destructive within this process.
  41. * If the test load succeeds, the module will be loaded locally.
  42. * \throw PluginPluginModuleError if the load fails
  43. * \param path the path to a loadable module on the file system
  44. * \return the PluginModule loaded at the given file path
  45. */
  46. static PluginModule safeLoad(const std::string &path);
  47. /*!
  48. * Get a file path for this module.
  49. * \return the file path for the shared library
  50. */
  51. std::string getFilePath(void) const;
  52. /*!
  53. * Get the paths that this module loaded into the plugin registry.
  54. * Each path is a string that represents a path in the registry.
  55. */
  56. const std::vector<std::string> &getPluginPaths(void) const;
  57. /*!
  58. * Does the module hold a loaded library?
  59. * \return true if the module is non-empty
  60. */
  61. explicit operator bool(void) const;
  62. /*!
  63. * Get a version string for the specified module.
  64. * Modules may optionally provide version strings.
  65. * \return a version string or empty if no version provided
  66. */
  67. std::string getVersion(void) const;
  68. private:
  69. struct Impl;
  70. std::shared_ptr<Impl> _impl;
  71. friend Plugin;
  72. };
  73. //! \cond
  74. //! Internal call to register version with a module during load
  75. class POTHOS_API ModuleVersion
  76. {
  77. public:
  78. ModuleVersion(const std::string &version);
  79. };
  80. //! \endcond
  81. } //namespace Pothos