ModulePaths.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2013-2017 Josh Blum
  2. // SPDX-License-Identifier: BSL-1.0
  3. #include <Pothos/Plugin/Module.hpp>
  4. #include <Pothos/Plugin/Plugin.hpp>
  5. #include <Pothos/Util/SpinLockRW.hpp>
  6. #include <Poco/HashMap.h>
  7. #include <mutex>
  8. static Pothos::Util::SpinLockRW &getModulePathsMutex(void)
  9. {
  10. static Pothos::Util::SpinLockRW lock;
  11. return lock;
  12. }
  13. typedef Poco::HashMap<std::string, std::vector<std::string>> ModulePathsMap;
  14. static ModulePathsMap &getModulePathsMap(void)
  15. {
  16. static ModulePathsMap map;
  17. return map;
  18. }
  19. std::vector<std::string> getPluginPaths(const Pothos::PluginModule &module)
  20. {
  21. Pothos::Util::SpinLockRW::SharedLock lock(getModulePathsMutex());
  22. return getModulePathsMap()[module.getFilePath()];
  23. }
  24. void updatePluginAssociation(const std::string &action, const Pothos::Plugin &plugin)
  25. {
  26. std::lock_guard<Pothos::Util::SpinLockRW> lock(getModulePathsMutex());
  27. auto &v = getModulePathsMap()[plugin.getModule().getFilePath()];
  28. const auto &path = plugin.getPath().toString();
  29. if (action == "add")
  30. {
  31. v.push_back(path);
  32. }
  33. if (action == "remove")
  34. {
  35. auto it = std::find(v.begin(), v.end(), path);
  36. if (it != v.end()) v.erase(it);
  37. }
  38. }