Environment.cpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (c) 2013-2017 Josh Blum
  2. // 2020 Nicholas Corgan
  3. // SPDX-License-Identifier: BSL-1.0
  4. #include <Pothos/Proxy/Exception.hpp>
  5. #include <Pothos/Proxy/Environment.hpp>
  6. #include <Pothos/Callable.hpp>
  7. #include <Pothos/Plugin.hpp>
  8. #include <Pothos/System/HostInfo.hpp>
  9. #include <Poco/Format.h>
  10. Pothos::ProxyEnvironment::Sptr Pothos::ProxyEnvironment::make(const std::string &name, const ProxyEnvironmentArgs &args)
  11. {
  12. Sptr environment;
  13. try
  14. {
  15. const auto plugin = Pothos::PluginRegistry::get(Pothos::PluginPath("/proxy/environment").join(name));
  16. const auto &callable = plugin.getObject().extract<Pothos::Callable>();
  17. environment = callable.call(args);
  18. }
  19. catch(const Exception &ex)
  20. {
  21. throw Pothos::ProxyEnvironmentFactoryError("Pothos::ProxyEnvironment::make("+name+")", ex);
  22. }
  23. return environment;
  24. }
  25. Pothos::ProxyEnvironment::~ProxyEnvironment(void)
  26. {
  27. return;
  28. }
  29. std::string Pothos::ProxyEnvironment::getNodeId(void) const
  30. {
  31. return System::HostInfo::get().nodeId;
  32. }
  33. std::string Pothos::ProxyEnvironment::getUniquePid(void) const
  34. {
  35. return getLocalUniquePid();
  36. }
  37. std::string Pothos::ProxyEnvironment::getLocalUniquePid(void)
  38. {
  39. const auto info = Pothos::System::HostInfo::get();
  40. return info.nodeName + "/" + info.nodeId + "/" + info.pid;
  41. }
  42. std::string Pothos::ProxyEnvironment::getPeeringAddress(void)
  43. {
  44. //not a real address for the local environment
  45. return "local";
  46. }
  47. #include <Pothos/Managed.hpp>
  48. static auto managedProxyEnvironment = Pothos::ManagedClass()
  49. .registerClass<Pothos::ProxyEnvironment>()
  50. .registerStaticMethod(POTHOS_FCN_TUPLE(Pothos::ProxyEnvironment, make))
  51. .registerMethod(POTHOS_FCN_TUPLE(Pothos::ProxyEnvironment, getName))
  52. .registerMethod(POTHOS_FCN_TUPLE(Pothos::ProxyEnvironment, findProxy))
  53. .registerMethod(POTHOS_FCN_TUPLE(Pothos::ProxyEnvironment, getNodeId))
  54. .registerMethod(POTHOS_FCN_TUPLE(Pothos::ProxyEnvironment, getUniquePid))
  55. .registerMethod(POTHOS_FCN_TUPLE(Pothos::ProxyEnvironment, getLocalUniquePid))
  56. .registerMethod(POTHOS_FCN_TUPLE(Pothos::ProxyEnvironment, getPeeringAddress))
  57. .commit("Pothos/ProxyEnvironment");
  58. static inline std::string proxyEnvironmentToString(const Pothos::ProxyEnvironment& env)
  59. {
  60. return Poco::format("Pothos::ProxyEnvironment (%s, %s)", env.getName(), env.getNodeId());
  61. }
  62. #include <Pothos/Object.hpp>
  63. pothos_static_block(registerPothosProxyEnvironmentToString)
  64. {
  65. Pothos::registerToStringFunc<Pothos::ProxyEnvironment>(
  66. "Pothos/ProxyEnvironment",
  67. &proxyEnvironmentToString,
  68. true /*wrapPointerTypes*/);
  69. }