ScopedBlockInRegistry.hpp 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // Copyright (c) 2021 Nicholas Corgan
  2. // SPDX-License-Identifier: BSL-1.0
  3. #pragma once
  4. #include <Pothos/Callable.hpp>
  5. #include <Pothos/Exception.hpp>
  6. #include <Pothos/Framework.hpp>
  7. #include <Pothos/Plugin.hpp>
  8. #include <Poco/Exception.h>
  9. #include <iostream>
  10. #include <memory>
  11. #include <string>
  12. struct ScopedBlockInRegistry
  13. {
  14. ScopedBlockInRegistry(
  15. const std::string& blockPath,
  16. const Pothos::Callable& callable
  17. ):
  18. blockPath(blockPath),
  19. blockRegistryUPtr(new Pothos::BlockRegistry(blockPath, callable))
  20. {
  21. }
  22. virtual ~ScopedBlockInRegistry()
  23. {
  24. POTHOS_EXCEPTION_TRY
  25. {
  26. const std::string fullBlockPath = "/blocks" + blockPath;
  27. Pothos::PluginRegistry::remove(fullBlockPath);
  28. }
  29. POTHOS_EXCEPTION_CATCH(const Pothos::Exception& ex)
  30. {
  31. std::cerr << ex.what() << std::endl;
  32. }
  33. }
  34. std::string blockPath;
  35. std::unique_ptr<Pothos::BlockRegistry> blockRegistryUPtr;
  36. };