PluginManager.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*******************************************************************************
  2. * Copyright 2009-2016 Jörg Müller
  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. #pragma once
  17. /**
  18. * @file PluginManager.h
  19. * @ingroup plugin
  20. * The PluginManager class.
  21. */
  22. #include "Audaspace.h"
  23. #include <unordered_map>
  24. #include <string>
  25. AUD_NAMESPACE_BEGIN
  26. /**
  27. * This manager provides utilities for plugin loading.
  28. */
  29. class AUD_API PluginManager
  30. {
  31. private:
  32. static std::unordered_map<std::string, void*> m_plugins;
  33. // delete copy constructor and operator=
  34. PluginManager(const PluginManager&) = delete;
  35. PluginManager& operator=(const PluginManager&) = delete;
  36. PluginManager() = delete;
  37. public:
  38. /**
  39. * Opens a shared library.
  40. * @param path The path to the file.
  41. * @return A handle to the library or nullptr if opening failed.
  42. */
  43. static void* openLibrary(const std::string& path);
  44. /**
  45. * Looks up a symbol from an opened library.
  46. * @param handle The handle to the opened library.
  47. * @param name The name of the symbol to look up.
  48. * @return The symbol or nullptr if the symbol was not found.
  49. */
  50. static void* lookupLibrary(void* handle, const std::string& name);
  51. /**
  52. * Closes an opened shared library.
  53. * @param handle The handle to the library to be closed.
  54. */
  55. static void closeLibrary(void* handle);
  56. /**
  57. * Loads a plugin from a file.
  58. * @param path The path to the file.
  59. * @return Whether the file could successfully be loaded.
  60. */
  61. static bool loadPlugin(const std::string& path);
  62. /**
  63. * Loads all plugins found in a folder.
  64. * @param path The path to the folder containing the plugins.
  65. */
  66. static void loadPlugins(const std::string& path = "");
  67. };
  68. AUD_NAMESPACE_END