Pothos::ProxyEnvironment::Sptr EnvironmentEval::makeEnvironment(void) { if (_zoneName == "gui") return Pothos::ProxyEnvironment::make("managed"); const auto hostUri = getHostProcFromConfig(_zoneName, _config).first; //connect to the remote host and spawn a server auto serverEnv = Pothos::RemoteClient(hostUri).makeEnvironment("managed"); auto serverHandle = serverEnv->findProxy("Pothos/RemoteServer")("tcp://"+Pothos::Util::getWildcardAddr(), false/*noclose*/); //construct the uri for the new server auto actualPort = serverHandle.call<std::string>("getActualPort"); Poco::URI newHostUri(hostUri); newHostUri.setPort(std::stoul(actualPort)); //connect the client environment auto client = Pothos::RemoteClient(newHostUri.toString()); client.holdRef(Pothos::Object(serverHandle)); auto env = client.makeEnvironment("managed"); //determine log delivery address //FIXME syslog listener doesn't support IPv6, special precautions taken: const auto logSource = (not _zoneName.isEmpty())? _zoneName.toStdString() : newHostUri.getHost(); const auto syslogListenPort = Pothos::System::Logger::startSyslogListener(); Poco::Net::SocketAddress serverAddr(env->getPeeringAddress(), syslogListenPort); //deal with IPv6 addresses because the syslog server only binds to IPv4 if (serverAddr.family() == Poco::Net::IPAddress::IPv6) { //convert IPv6 mapped ports to IPv4 format when possible if (serverAddr.host().isIPv4Mapped()) { const Poco::Net::IPAddress v4Mapped(static_cast<const char *>(serverAddr.host().addr())+12, 4); serverAddr = Poco::Net::SocketAddress(v4Mapped, std::stoi(syslogListenPort)); } //convert an IPv4 loopback address into an IPv4 loopback address else if (serverAddr.host().isLoopback()) { serverAddr = Poco::Net::SocketAddress("127.0.0.1", syslogListenPort); } //otherwise warn because the forwarding will not work else { poco_warning_f1(Poco::Logger::get("PothosGui.EnvironmentEval.make"), "Log forwarding not supported over IPv6: %s", logSource); return env; } } //setup log delivery from the server process env->findProxy("Pothos/System/Logger").callVoid("startSyslogForwarding", serverAddr.toString()); env->findProxy("Pothos/System/Logger").callVoid("forwardStdIoToLogging", logSource); serverHandle.callVoid("startSyslogForwarding", serverAddr.toString(), logSource); return env; }
/*********************************************************************** * information aquisition **********************************************************************/ static InfoResult getInfo(const std::string &uriStr) { InfoResult info; POTHOS_EXCEPTION_TRY { auto env = Pothos::RemoteClient(uriStr).makeEnvironment("managed"); info.hostInfo = env->findProxy("Pothos/System/HostInfo").call<Pothos::System::HostInfo>("get"); info.numaInfo = env->findProxy("Pothos/System/NumaInfo").call<std::vector<Pothos::System::NumaInfo>>("get"); auto deviceInfo = env->findProxy("Pothos/Util/DeviceInfoUtils").call<std::string>("dumpJson"); Poco::JSON::Parser p; p.parse(deviceInfo); info.deviceInfo = p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>(); } POTHOS_EXCEPTION_CATCH(const Pothos::Exception &ex) { poco_error_f2(Poco::Logger::get("PothosGui.SystemInfoTree"), "Failed to query system info %s - %s", uriStr, ex.displayText()); }
Poco::JSON::Object::Ptr BlockCache::getBlockDescFromPath(const std::string &path) { //look in the cache { Poco::RWLock::ScopedReadLock lock(_mapMutex); auto it = _pathToBlockDesc.find(path); if (it != _pathToBlockDesc.end()) return it->second; } //search all of the nodes for (const auto &uri : _hostExplorerDock->hostUriList()) { try { auto client = Pothos::RemoteClient(uri.toStdString()); auto env = client.makeEnvironment("managed"); auto DocUtils = env->findProxy("Pothos/Util/DocUtils"); return DocUtils.call<Poco::JSON::Object::Ptr>("dumpJsonAt", path); } catch (const Pothos::Exception &) { //pass } } return Poco::JSON::Object::Ptr(); }
/*********************************************************************** * NodeInfo update implementation **********************************************************************/ void NodeInfo::update(void) { auto settings = MainSettings::global(); //determine if the host is online and update access times try { Pothos::RemoteClient client(this->uri.toStdString()); if (this->nodeName.isEmpty()) { auto env = client.makeEnvironment("managed"); auto hostInfo = env->findProxy("Pothos/System/HostInfo").call<Pothos::System::HostInfo>("get"); this->nodeName = QString::fromStdString(hostInfo.nodeName); settings->setValue("HostExplorer/"+this->uri+"/nodeName", this->nodeName); } this->isOnline = true; this->lastAccess = Poco::Timestamp(); settings->setValue("HostExplorer/"+this->uri+"/lastAccess", int(this->lastAccess.epochTime())); } //otherwise, fetch the information from the settings cache catch(const Pothos::RemoteClientError &) { this->isOnline = false; if (this->nodeName.isEmpty()) { this->nodeName = settings->value("HostExplorer/"+this->uri+"/nodeName").toString(); } this->lastAccess = Poco::Timestamp::fromEpochTime(std::time_t(settings->value("HostExplorer/"+this->uri+"/lastAccess").toInt())); } }
void ProxyBlockEval::eval(const std::string &id, const Poco::JSON::Object::Ptr &blockDesc) { auto env = Pothos::ProxyEnvironment::make("managed"); auto registry = env->findProxy("Pothos/BlockRegistry"); auto path = blockDesc->getValue<std::string>("path"); //load up the constructor args std::vector<Pothos::Proxy> ctorArgs; if (blockDesc->isArray("args")) for (auto arg : *blockDesc->getArray("args")) { const auto obj = this->lookupOrEvalAsType(arg); ctorArgs.push_back(env->convertObjectToProxy(obj)); } //create the block try { _proxyBlock = registry.getHandle()->call(path, ctorArgs.data(), ctorArgs.size()); } catch (const Pothos::Exception &ex) { throw Pothos::Exception("ProxyBlockEval factory("+path+")", ex); } _proxyBlock.callVoid("setName", id); //make the calls if (blockDesc->isArray("calls")) for (auto call : *blockDesc->getArray("calls")) { this->handleCall(call.extract<Poco::JSON::Object::Ptr>()); } }
void BlockEval::eval(const std::string &id, const Poco::JSON::Object::Ptr &blockDesc) { auto env = Pothos::ProxyEnvironment::make("managed"); auto registry = env->findProxy("Pothos/BlockRegistry"); auto path = blockDesc->getValue<std::string>("path"); //load up the constructor args std::vector<Pothos::Proxy> ctorArgs; for (auto arg : *blockDesc->getArray("args")) { const auto propKey = arg.extract<std::string>(); const auto obj = _properties[propKey]; ctorArgs.push_back(env->convertObjectToProxy(obj)); } //create the block try { _proxyBlock = registry.getHandle()->call(path, ctorArgs.data(), ctorArgs.size()); } catch (const Pothos::Exception &ex) { throw Pothos::Exception("BlockEval factory("+path+")", ex); } _proxyBlock.callVoid("setName", id); //inspect before making any calls -- calls may fails _portDesc = this->inspectPorts(); //make the calls for (auto call : *blockDesc->getArray("calls")) { const auto callObj = call.extract<Poco::JSON::Object::Ptr>(); const auto callName = callObj->get("name").extract<std::string>(); std::vector<Pothos::Proxy> callArgs; for (auto arg : *callObj->getArray("args")) { const auto propKey = arg.extract<std::string>(); const auto obj = _properties[propKey]; callArgs.push_back(env->convertObjectToProxy(obj)); } try { _proxyBlock.getHandle()->call(callName, callArgs.data(), callArgs.size()); } catch (const Pothos::Exception &ex) { throw Pothos::Exception("BlockEval call("+callName+")", ex); } } //inspect after making calls -- ports may have changed _portDesc = this->inspectPorts(); }
static double filterToneGetRMS( const double sampRate, const double waveFreq, const size_t decim, const size_t interp ) { auto env = Pothos::ProxyEnvironment::make("managed"); auto registry = env->findProxy("Pothos/BlockRegistry"); auto waveSource = registry.callProxy("/blocks/waveform_source", "complex128"); waveSource.callVoid("setWaveform", "SINE"); waveSource.callVoid("setFrequency", waveFreq); waveSource.callVoid("setSampleRate", sampRate); auto finiteRelease = registry.callProxy("/blocks/finite_release"); finiteRelease.callVoid("setTotalElements", 4096); auto filter = registry.callProxy("/blocks/fir_filter", "complex128", "COMPLEX"); filter.callVoid("setDecimation", decim); filter.callVoid("setInterpolation", interp); auto designer = registry.callProxy("/blocks/fir_designer"); designer.callVoid("setSampleRate", (sampRate*interp)/decim); designer.callVoid("setFilterType", "COMPLEX_BAND_PASS"); designer.callVoid("setFrequencyLower", waveFreq-0.1*sampRate); designer.callVoid("setFrequencyUpper", waveFreq+0.1*sampRate); designer.callVoid("setNumTaps", 100); auto probe = registry.callProxy("/blocks/stream_probe", "complex128"); probe.callVoid("setMode", "RMS"); //propagate the taps { Pothos::Topology topology; topology.connect(designer, "tapsChanged", filter, "setTaps"); topology.commit(); POTHOS_TEST_TRUE(topology.waitInactive()); } //run the topology { Pothos::Topology topology; topology.connect(waveSource, 0, finiteRelease, 0); topology.connect(finiteRelease, 0, filter, 0); topology.connect(filter, 0, probe, 0); topology.commit(); POTHOS_TEST_TRUE(topology.waitInactive()); } return probe.call<double>("value"); }
/*********************************************************************** * information aquisition **********************************************************************/ static Pothos::PluginRegistryInfoDump getRegistryDump(const std::string &uriStr) { try { auto env = Pothos::RemoteClient(uriStr).makeEnvironment("managed"); return env->findProxy("Pothos/PluginRegistry").call("dump"); } catch (const Pothos::Exception &ex) { static auto &logger = Poco::Logger::get("PothosFlow.PluginRegistryTree"); logger.error("Failed to dump registry %s - %s", uriStr, ex.displayText()); } return Pothos::PluginRegistryInfoDump(); }
/*********************************************************************** * Query JSON docs from node **********************************************************************/ static Poco::JSON::Array::Ptr queryBlockDescs(const QString &uri) { try { auto client = Pothos::RemoteClient(uri.toStdString()); auto env = client.makeEnvironment("managed"); return env->findProxy("Pothos/Util/DocUtils").call<Poco::JSON::Array::Ptr>("dumpJson"); } catch (const Pothos::Exception &ex) { poco_warning_f2(Poco::Logger::get("PothosGui.BlockCache"), "Failed to query JSON Docs from %s - %s", uri.toStdString(), ex.displayText()); } return Poco::JSON::Array::Ptr(); //empty JSON array }
void AffinityZoneEditor::updateCpuSelection(void) { //get node info and cache it auto uriStr = _hostsBox->itemText(_hostsBox->currentIndex()); if (_uriToNumaInfo[uriStr].empty()) try { auto env = Pothos::RemoteClient(uriStr.toStdString()).makeEnvironment("managed"); auto nodeInfos = env->findProxy("Pothos/System/NumaInfo").call<std::vector<Pothos::System::NumaInfo>>("get"); _uriToNumaInfo[uriStr] = nodeInfos; } catch (const Pothos::Exception &) {} delete _cpuSelection; _cpuSelection = new CpuSelectionWidget(_uriToNumaInfo[uriStr], this); connect(_cpuSelection, SIGNAL(selectionChanged(void)), this, SLOT(handleSpinSelChanged(void))); _cpuSelectionContainer->addWidget(_cpuSelection); }
static Pothos::Object @class_name@Factory(const Pothos::Object *args, const size_t numArgs) { //create python environment auto env = Pothos::ProxyEnvironment::make("python"); //convert arguments into proxy environment std::vector<Pothos::Proxy> proxyArgs(numArgs); for (size_t i = 0; i < numArgs; i++) { proxyArgs[i] = env->makeProxy(args[i]); } //locate the module auto mod = env->findProxy("@package_name@"); //call into the factory auto block = mod.getHandle()->call("@class_name@", proxyArgs.data(), proxyArgs.size()); return Pothos::Object(block); }
// Notify the debugger that this thread is executing a request in the given // sandbox. This ensures that the debugger knows about the sandbox, and adds // the thread to the set of threads currently active in the sandbox. void Debugger::registerSandbox(const DSandboxInfo &sandbox) { TRACE(2, "Debugger::registerSandbox\n"); // update sandbox first addOrUpdateSandbox(sandbox); // add thread to m_sandboxThreadInfoMap const StringData* sid = StringData::GetStaticString(sandbox.id()); ThreadInfo* ti = ThreadInfo::s_threadInfo.getNoCheck(); { SandboxThreadInfoMap::accessor acc; m_sandboxThreadInfoMap.insert(acc, sid); ThreadInfoSet& set = acc->second; set.insert(ti); } // find out whether this sandbox is being debugged DebuggerProxyPtr proxy = findProxy(sid); if (proxy) { ti->m_reqInjectionData.setDebugger(true); } }
// Notify the debugger that this thread is executing a request in the given // sandbox. This ensures that the debugger knows about the sandbox, and adds // the thread to the set of threads currently active in the sandbox. void Debugger::registerSandbox(const DSandboxInfo &sandbox) { TRACE(2, "Debugger::registerSandbox\n"); // update sandbox first addOrUpdateSandbox(sandbox); // add thread to m_sandboxThreadInfoMap const StringData* sid = makeStaticString(sandbox.id()); auto ti = &TI(); { SandboxThreadInfoMap::accessor acc; m_sandboxThreadInfoMap.insert(acc, sid); acc->second.insert(ti); } // Find out whether this sandbox is being debugged. auto proxy = findProxy(sid); if (proxy) { if (!DebuggerHook::attach<HphpdHook>(ti)) { Logger::Error("Failed to attach to thread: another debugger is " "unexpectedly hooked"); } } }
void Debugger::registerSandbox(const DSandboxInfo &sandbox) { // update sandbox first updateSandbox(sandbox); // add thread do m_sandboxThreadInfoMap const StringData* sid = StringData::GetStaticString(sandbox.id()); ThreadInfo* ti = ThreadInfo::s_threadInfo.getNoCheck(); { SandboxThreadInfoMap::accessor acc; m_sandboxThreadInfoMap.insert(acc, sid); ThreadInfoSet& set = acc->second; set.insert(ti); } // find out whether this sandbox is being debugged DebuggerProxyPtr proxy = findProxy(sid); if (proxy) { ti->m_reqInjectionData.debugger = true; if (hhvm) { DebuggerProxyVM* proxyVM = (DebuggerProxyVM*)proxy.get(); proxyVM->writeInjTablesToThread(); } } }
Pothos::Proxy Pothos::BlockRegistry::make(const std::string &path, ArgsType&&... args) { auto env = Pothos::ProxyEnvironment::make("managed"); auto registry = env->findProxy("Pothos/BlockRegistry"); return registry.call(path, std::forward<ArgsType>(args)...); }
/*********************************************************************** * make topology from JSON string - implementation **********************************************************************/ std::shared_ptr<Pothos::Topology> Pothos::Topology::make(const std::string &json) { //parse the json string/file to a JSON object const auto topObj = parseJSONStr(json); //create the proxy environment (local) and the registry auto env = Pothos::ProxyEnvironment::make("managed"); auto registry = env->findProxy("Pothos/BlockRegistry"); auto evaluator = env->findProxy("Pothos/Util/EvalEnvironment").callProxy("make"); //create thread pools std::map<std::string, Pothos::Proxy> threadPools; Poco::JSON::Object::Ptr threadPoolObj; if (topObj->isObject("threadPools")) threadPoolObj = topObj->getObject("threadPools"); std::vector<std::string> threadPoolNames; if (threadPoolObj) threadPoolObj->getNames(threadPoolNames); for (const auto &name : threadPoolNames) { std::stringstream ss; threadPoolObj->getObject(name)->stringify(ss); Pothos::ThreadPoolArgs args(ss.str()); threadPools[name] = env->findProxy("Pothos/ThreadPool").callProxy("new", args); } //create the topology and add it to the blocks //the IDs 'self', 'this', and '' can be used std::map<std::string, Pothos::Proxy> blocks; auto topology = Pothos::Topology::make(); blocks["self"] = env->makeProxy(topology); blocks["this"] = env->makeProxy(topology); blocks[""] = env->makeProxy(topology); //create the blocks Poco::JSON::Array::Ptr blockArray; if (topObj->isArray("blocks")) blockArray = topObj->getArray("blocks"); if (blockArray) for (size_t i = 0; i < blockArray->size(); i++) { if (not blockArray->isObject(i)) throw Pothos::DataFormatException( "Pothos::Topology::make()", "blocks["+std::to_string(i)+"] must be an object"); const auto &blockObj = blockArray->getObject(i); if (not blockObj->has("id")) throw Pothos::DataFormatException( "Pothos::Topology::make()", "blocks["+std::to_string(i)+"] missing 'id' field"); const auto id = blockObj->getValue<std::string>("id"); blocks[id] = makeBlock(registry, evaluator, blockObj); //set the thread pool const auto threadPoolName = blockObj->optValue<std::string>("threadPool", "default"); auto threadPoolIt = threadPools.find(threadPoolName); if (threadPoolIt != threadPools.end()) blocks[id].callVoid("setThreadPool", threadPoolIt->second); else if (threadPoolName != "default") throw Pothos::DataFormatException( "Pothos::Topology::make()", "blocks["+id+"] unknown threadPool = " + threadPoolName); } //create the topology and connect the blocks Poco::JSON::Array::Ptr connArray; if (topObj->isArray("connections")) connArray = topObj->getArray("connections"); if (connArray) for (size_t i = 0; i < connArray->size(); i++) { if (not connArray->isArray(i)) throw Pothos::DataFormatException( "Pothos::Topology::make()", "connections["+std::to_string(i)+"] must be an array"); const auto &connArgs = connArray->getArray(i); if (connArgs->size() != 4) throw Pothos::DataFormatException( "Pothos::Topology::make()", "connections["+std::to_string(i)+"] must be size 4"); //extract connection arg fields const auto srcId = connArgs->getElement<std::string>(0); const auto srcPort = connArgs->get(1).toString(); const auto dstId = connArgs->getElement<std::string>(2); const auto dstPort = connArgs->get(3).toString(); //check that the block IDs exist if (blocks.count(srcId) == 0) throw Pothos::DataFormatException( "Pothos::Topology::make()", "connections["+std::to_string(i)+"] no such ID: " + srcId); if (blocks.count(dstId) == 0) throw Pothos::DataFormatException( "Pothos::Topology::make()", "connections["+std::to_string(i)+"] no such ID: " + dstId); //make the connection topology->connect(blocks.at(srcId), srcPort, blocks.at(dstId), dstPort); } return topology; }
// Copyright (c) 2014-2015 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include <Pothos/Testing.hpp> #include <Pothos/Proxy.hpp> #include <Pothos/Framework.hpp> #include <Pothos/Exception.hpp> #include <Pothos/Object/Containers.hpp> #include <complex> #include <iostream> POTHOS_TEST_BLOCK("/util/tests", test_eval_expression) { //check that the following does not throw auto env = Pothos::ProxyEnvironment::make("managed"); auto EvalEnvironment = env->findProxy("Pothos/Util/EvalEnvironment"); auto evalEnv = EvalEnvironment.callProxy("new"); //booleans const auto resultT = evalEnv.call<Pothos::Object>("eval", "true"); POTHOS_TEST_TRUE(resultT.convert<bool>()); const auto resultF = evalEnv.call<Pothos::Object>("eval", "false"); POTHOS_TEST_TRUE(not resultF.convert<bool>()); //simple expression const auto result = evalEnv.call<Pothos::Object>("eval", "1 + 2"); POTHOS_TEST_EQUAL(result.convert<int>(), 3); //a pothos type //const auto result2 = evalEnv.call<Pothos::Object>("eval", "DType(\"int32\")");
// Copyright (c) 2014 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include <Pothos/Testing.hpp> #include <Pothos/Proxy.hpp> #include <Pothos/Proxy/Environment.hpp> #include <Pothos/Exception.hpp> #include <Poco/JSON/Array.h> #include <iostream> POTHOS_TEST_BLOCK("/gui/tests", test_doc_utils_dump_json) { //check that the following does not throw auto env = Pothos::ProxyEnvironment::make("managed"); auto proxy = env->findProxy("Pothos/Util/DocUtils"); const auto json = proxy.call<Poco::JSON::Array::Ptr>("dumpJson"); POTHOS_TEST_TRUE(json); }
// Copyright (c) 2014-2015 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include "SimulationClient.hpp" #include <Pothos/Testing.hpp> #include <Pothos/Proxy.hpp> #include <Pothos/Framework.hpp> #include <Poco/JSON/Object.h> #include <iostream> POTHOS_TEST_BLOCK("/fpga/tests", test_loopback) { //create client environment auto env = getSimulationEnv("LoopbackTb"); auto SimulationHarness = env->findProxy("Pothos/FPGA/SimulationHarness"); auto sourceIndexes = SimulationHarness.call<std::vector<int>>("getSourceIndexes"); POTHOS_TEST_EQUAL(sourceIndexes.size(), 1); POTHOS_TEST_EQUAL(sourceIndexes[0], 0); auto sinkIndexes = SimulationHarness.call<std::vector<int>>("getSinkIndexes"); POTHOS_TEST_EQUAL(sinkIndexes.size(), 1); POTHOS_TEST_EQUAL(sinkIndexes[0], 0); auto source0 = SimulationHarness.callProxy("getSourceBlock", 0); auto sink0 = SimulationHarness.callProxy("getSinkBlock", 0); auto registry = env->findProxy("Pothos/BlockRegistry"); auto feeder = registry.callProxy("/blocks/feeder_source", "int"); auto collector = registry.callProxy("/blocks/collector_sink", "int");
// Copyright (c) 2015-2015 Josh Blum // SPDX-License-Identifier: BSL-1.0 #include <Pothos/Testing.hpp> #include <Pothos/Framework.hpp> #include <Pothos/Proxy.hpp> #include <Poco/JSON/Object.h> #include <iostream> #include <complex> POTHOS_TEST_BLOCK("/comms/tests", test_symbol_mapper_slicer_float) { auto env = Pothos::ProxyEnvironment::make("managed"); auto registry = env->findProxy("Pothos/BlockRegistry"); auto feeder = registry.callProxy("/blocks/feeder_source", "unsigned char"); auto mapper = registry.callProxy("/comms/symbol_mapper", "float"); auto slicer = registry.callProxy("/comms/symbol_slicer", "float"); auto collector = registry.callProxy("/blocks/collector_sink", "unsigned char"); static const float mapD[] = {-3, -1, 1, 3}; std::vector<float> map(mapD, mapD+4); mapper.callProxy("setMap", map); slicer.callProxy("setMap", map); //load feeder blocks auto b0 = Pothos::BufferChunk(10*sizeof(unsigned char)); auto p0 = b0.as<unsigned char *>(); for (size_t i = 0; i < 10; i++) p0[i] = i&3; feeder.callProxy("feedBuffer", b0);
bool SOCKS5BytestreamManager::handleIqID( Stanza *stanza, int context ) { StringMap::iterator it = m_trackMap.find( stanza->id() ); if( it == m_trackMap.end() ) return false; switch( context ) { case S5BOpenStream: { switch( stanza->subtype() ) { case StanzaIqResult: { Tag* q = stanza->findChild( "query", "xmlns", XMLNS_BYTESTREAMS ); if( !q || !m_socks5BytestreamHandler ) return false; Tag* s = q->findChild( "streamhost-used" ); if( !s || !s->hasAttribute( "jid" ) ) return false; const std::string & proxy = s->findAttribute( "jid" ); const StreamHost* sh = findProxy( stanza->from(), proxy, (*it).second ); if( sh ) { SOCKS5Bytestream* s5b = 0; bool selfProxy = ( proxy == m_parent->jid().full() && m_server ); if( selfProxy ) { SHA sha; sha.feed( (*it).second ); sha.feed( m_parent->jid().full() ); sha.feed( stanza->from().full() ); s5b = new SOCKS5Bytestream( this, m_server->getConnection( sha.hex() ), m_parent->logInstance(), m_parent->jid(), stanza->from(), (*it).second ); } else { s5b = new SOCKS5Bytestream( this, m_parent->connectionImpl()->newInstance(), m_parent->logInstance(), m_parent->jid(), stanza->from(), (*it).second ); StreamHostList shl; shl.push_back( *sh ); s5b->setStreamHosts( shl ); } m_s5bMap[(*it).second] = s5b; m_socks5BytestreamHandler->handleOutgoingSOCKS5Bytestream( s5b ); if( selfProxy ) s5b->activate(); } break; } case StanzaIqError: m_socks5BytestreamHandler->handleSOCKS5BytestreamError( stanza, (*it).second ); break; default: break; } break; } case S5BActivateStream: { switch( stanza->subtype() ) { case StanzaIqResult: { S5BMap::const_iterator it5 = m_s5bMap.find( (*it).second ); if( it5 != m_s5bMap.end() ) (*it5).second->activate(); break; } case StanzaIqError: m_socks5BytestreamHandler->handleSOCKS5BytestreamError( stanza, (*it).second ); break; default: break; } break; } default: break; } m_trackMap.erase( it ); return false; }
void SOCKS5BytestreamManager::handleIqID( const IQ& iq, int context ) { StringMap::iterator it = m_trackMap.find( iq.id() ); if( it == m_trackMap.end() ) return; switch( context ) { case S5BOpenStream: { switch( iq.subtype() ) { case IQ::Result: { const Query* q = iq.findExtension<Query>( ExtS5BQuery ); if( q && m_socks5BytestreamHandler ) { const std::string& proxy = q->jid().full(); const StreamHost* sh = findProxy( iq.from(), proxy, (*it).second ); if( sh ) { SOCKS5Bytestream* s5b = 0; bool selfProxy = ( proxy == m_parent->jid().full() && m_server ); if( selfProxy ) { SHA sha; sha.feed( (*it).second ); sha.feed( iq.to().full() ); sha.feed( iq.from().full() ); s5b = new SOCKS5Bytestream( this, m_server->getConnection( sha.hex() ), m_parent->logInstance(), iq.to(), iq.from(), (*it).second ); } else { s5b = new SOCKS5Bytestream( this, m_parent->connectionImpl()->newInstance(), m_parent->logInstance(), iq.to(), iq.from(), (*it).second ); s5b->setStreamHosts( StreamHostList( 1, *sh ) ); } m_s5bMap[(*it).second] = s5b; m_socks5BytestreamHandler->handleOutgoingBytestream( s5b ); if( selfProxy ) s5b->activate(); } } break; } case IQ::Error: m_socks5BytestreamHandler->handleBytestreamError( iq, (*it).second ); break; default: break; } break; } case S5BActivateStream: { switch( iq.subtype() ) { case IQ::Result: { S5BMap::const_iterator it5 = m_s5bMap.find( (*it).second ); if( it5 != m_s5bMap.end() ) (*it5).second->activate(); break; } case IQ::Error: m_socks5BytestreamHandler->handleBytestreamError( iq, (*it).second ); break; default: break; } break; } default: break; } m_trackMap.erase( it ); }
/*********************************************************************** * Handler implementation **********************************************************************/ bool Pothos::RemoteHandler::runHandlerOnce(std::istream &is, std::ostream &os) { bool done = false; //deserialize the request const auto reqArgs = recvDatagram(is); //process the request and form the reply Pothos::ObjectKwargs replyArgs; replyArgs["tid"] = reqArgs.at("tid"); POTHOS_EXCEPTION_TRY { const auto &action = reqArgs.at("action").extract<std::string>(); if (action == "RemoteProxyEnvironment") { Pothos::ProxyEnvironmentArgs envArgs; for (const auto &entry : reqArgs) { if (entry.second.type() != typeid(std::string)) continue; envArgs[entry.first] = entry.second.extract<std::string>(); } const auto &name = reqArgs.at("name").extract<std::string>(); auto env = Pothos::ProxyEnvironment::make(name, envArgs); replyArgs["envID"] = getNewObjectId(Pothos::Object(env)); //a unique process ID for this server const auto info = Pothos::System::HostInfo::get(); replyArgs["upid"] = Pothos::Object(Pothos::ProxyEnvironment::getLocalUniquePid()); replyArgs["nodeId"] = Pothos::Object(info.nodeId); replyArgs["peerAddr"] = Pothos::Object(_peerAddr); } else if (action == "~RemoteProxyEnvironment") { removeObjectAtId(reqArgs.at("envID")); done = true; } else if (action == "findProxy") { auto env = getObjectAtId(reqArgs.at("envID")).extract<Pothos::ProxyEnvironment::Sptr>(); auto proxy = env->findProxy(reqArgs.at("name").extract<std::string>()); replyArgs["handleID"] = getNewObjectId(Pothos::Object(proxy)); } else if (action == "convertObjectToProxy") { auto env = getObjectAtId(reqArgs.at("envID")).extract<Pothos::ProxyEnvironment::Sptr>(); auto proxy = env->convertObjectToProxy(reqArgs.at("local")); replyArgs["handleID"] = getNewObjectId(Pothos::Object(proxy)); } else if (action == "convertProxyToObject") { auto env = getObjectAtId(reqArgs.at("envID")).extract<Pothos::ProxyEnvironment::Sptr>(); auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>(); auto local = env->convertProxyToObject(proxy); replyArgs["local"] = local; } else if (action == "~RemoteProxyHandle") { removeObjectAtId(reqArgs.at("handleID")); } else if (action == "call") { auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>(); //load the args std::vector<Pothos::Proxy> args; size_t argNo = 0; while (true) { auto it = reqArgs.find(std::to_string(argNo++)); if (it == reqArgs.end()) break; args.push_back(getObjectAtId(it->second).extract<Pothos::Proxy>()); } //make the call try { const auto &name = reqArgs.at("name").extract<std::string>(); auto result = proxy.getHandle()->call(name, args.data(), args.size()); replyArgs["handleID"] = getNewObjectId(Pothos::Object(result)); } catch (const Pothos::ProxyExceptionMessage &ex) { replyArgs["message"] = Pothos::Object(ex.message()); } } else if (action == "compareTo") { auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>(); auto other = getObjectAtId(reqArgs.at("otherID")).extract<Pothos::Proxy>(); replyArgs["result"] = Pothos::Object(proxy.compareTo(other)); } else if (action == "hashCode") { auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>(); replyArgs["result"] = Pothos::Object(proxy.hashCode()); } else if (action == "toString") { auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>(); replyArgs["result"] = Pothos::Object(proxy.toString()); } else if (action == "getClassName") { auto proxy = getObjectAtId(reqArgs.at("handleID")).extract<Pothos::Proxy>(); replyArgs["result"] = Pothos::Object(proxy.getClassName()); } else { poco_bugcheck_msg(action.c_str()); } } POTHOS_EXCEPTION_CATCH(const Pothos::Exception &ex) { replyArgs["errorMsg"] = Pothos::Object(ex.displayText()); }