PluginManager.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /******************************************************************************
  2. Copyright (C) 2025 by FiniteSingularity <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #pragma once
  15. #include <obs-module.h>
  16. #include <filesystem>
  17. #include <string>
  18. #include <vector>
  19. namespace OBS {
  20. struct ModuleInfo {
  21. std::string display_name;
  22. std::string module_name;
  23. std::string id;
  24. std::string version;
  25. bool enabled;
  26. bool enabledAtLaunch;
  27. std::vector<std::string> sources;
  28. std::vector<std::string> outputs;
  29. std::vector<std::string> encoders;
  30. std::vector<std::string> services;
  31. std::vector<std::string> sourcesLoaded;
  32. std::vector<std::string> outputsLoaded;
  33. std::vector<std::string> encodersLoaded;
  34. std::vector<std::string> servicesLoaded;
  35. };
  36. class PluginManager {
  37. private:
  38. std::vector<ModuleInfo> modules_ = {};
  39. std::vector<std::string> disabledSources_ = {};
  40. std::vector<std::string> disabledOutputs_ = {};
  41. std::vector<std::string> disabledServices_ = {};
  42. std::vector<std::string> disabledEncoders_ = {};
  43. std::filesystem::path getConfigFilePath_();
  44. void loadModules_();
  45. void saveModules_();
  46. void disableModules_();
  47. void addModuleTypes_();
  48. void linkUnloadedModules_();
  49. public:
  50. void preLoad();
  51. void postLoad();
  52. void open();
  53. friend void addModuleToPluginManagerImpl(void *param, obs_module_t *newModule);
  54. };
  55. void addModuleToPluginManagerImpl(void *param, obs_module_t *newModule);
  56. }; // namespace OBS
  57. // Anonymous namespace function to add module to plugin manager
  58. // via libobs's module enumeration.
  59. namespace {
  60. inline void addModuleToPluginManager(void *param, obs_module_t *newModule)
  61. {
  62. OBS::addModuleToPluginManagerImpl(param, newModule);
  63. }
  64. } // namespace