/*********************************************************************** * BlockRegistry factory - retrieve factory and instantiate with args **********************************************************************/ static Pothos::Object blockRegistryMake(const std::string &path, const Pothos::Object *args, const size_t numArgs) { const auto pluginPath = Pothos::PluginPath("/blocks", path); const auto plugin = Pothos::PluginRegistry::get(pluginPath); const auto factory = plugin.getObject().extract<Pothos::Callable>(); //handle opaque factory case if (isOpaqueFactory(factory)) return factory.call<Pothos::Object>(args, numArgs); //check that the number of args match if (numArgs != factory.getNumArgs()) throw Pothos::InvalidArgumentException( "Pothos::BlockRegistry("+path+")", Poco::format( "factory expected %z args, but got %z args", factory.getNumArgs(), numArgs)); //handle factories that return Block pointer types if (factory.type(-1) == typeid(Pothos::Block*)) { auto element = factory.opaqueCall(args, numArgs).extract<Pothos::Block *>(); if (element->getName().empty()) element->setName(path); //a better name element->holdRef(Pothos::Object(plugin.getModule())); return Pothos::Object(std::shared_ptr<Pothos::Block>(element)); } //handle factories that return Block shared pointer types if (factory.type(-1) == typeid(std::shared_ptr<Pothos::Block>)) { auto element = factory.opaqueCall(args, numArgs).extract<std::shared_ptr<Pothos::Block>>(); if (element->getName().empty()) element->setName(path); //a better name element->holdRef(Pothos::Object(plugin.getModule())); return Pothos::Object(element); } //handle factories that return Topology pointer types if (factory.type(-1) == typeid(Pothos::Topology*)) { auto element = factory.opaqueCall(args, numArgs).extract<Pothos::Topology *>(); if (element->getName().empty()) element->setName(path); //a better name element->holdRef(Pothos::Object(plugin.getModule())); return Pothos::Object(std::shared_ptr<Pothos::Topology>(element)); } //handle factories that return Topology shared pointer types if (factory.type(-1) == typeid(std::shared_ptr<Pothos::Topology>)) { auto element = factory.opaqueCall(args, numArgs).extract<std::shared_ptr<Pothos::Topology>>(); if (element->getName().empty()) element->setName(path); //a better name element->holdRef(Pothos::Object(plugin.getModule())); return Pothos::Object(element); } throw Pothos::IllegalStateException("Pothos::BlockRegistry::make("+path+")", factory.toString()); }
void setInputRule(Rule::Semantic inputRule, Rule const &rule) { releaseRef(inputRules[inputRule]); inputRules[inputRule] = holdRef(rule); updateForChangedInput(inputRule); }
void attach(GLShader const *shader) { DENG2_ASSERT(shader->isReady()); alloc(); glAttachShader(name, shader->glName()); LIBGUI_ASSERT_GL_OK(); shaders.insert(holdRef(shader)); }
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; }
void InputFieldSpeechButtonElement::setRecognitionResult(int, const String& result) { HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode()); // The call to setValue() below dispatches an event, and an event handler in the page might // remove the input element from DOM. To make sure it remains valid until we finish our work // here, we take a temporary reference. RefPtr<HTMLInputElement> holdRef(input); input->setValue(result); input->dispatchFormControlChangeEvent(); renderer()->repaint(); }
void InputFieldSpeechButtonElement::defaultEventHandler(Event* event) { // For privacy reasons, only allow clicks directly coming from the user. if (!event->fromUserGesture()) { HTMLDivElement::defaultEventHandler(event); return; } // On mouse down, select the text and set focus. HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode()); if (event->type() == eventNames().mousedownEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { if (renderer() && renderer()->visibleToHitTesting()) { if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(this); m_capturing = true; } } // The call to focus() below dispatches a focus event, and an event handler in the page might // remove the input element from DOM. To make sure it remains valid until we finish our work // here, we take a temporary reference. RefPtr<HTMLInputElement> holdRef(input); input->focus(); input->select(); event->setDefaultHandled(); } // On mouse up, release capture cleanly. if (event->type() == eventNames().mouseupEvent && event->isMouseEvent() && static_cast<MouseEvent*>(event)->button() == LeftButton) { if (m_capturing && renderer() && renderer()->visibleToHitTesting()) { if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(0); m_capturing = false; } } } if (event->type() == eventNames().clickEvent) { switch (m_state) { case Idle: if (speechInput()->startRecognition(m_listenerId, input->renderer()->absoluteBoundingBoxRect())) setState(Recording); break; case Recording: speechInput()->stopRecording(m_listenerId); break; case Recognizing: // Nothing to do here, we will continue to wait for results. break; } event->setDefaultHandled(); } if (!event->defaultHandled()) HTMLDivElement::defaultEventHandler(event); }
static Pothos::Object blockRegistryMake(const std::string &path, const Pothos::Object *args, const size_t numArgs) { const auto pluginPath = Pothos::PluginPath("/blocks").join(path.substr(1)); const auto plugin = Pothos::PluginRegistry::get(pluginPath); const auto factory = plugin.getObject().extract<Pothos::Callable>(); if (factory.type(-1) == typeid(Pothos::Block*)) { auto element = factory.opaqueCall(args, numArgs).extract<Pothos::Block *>(); if (element->getName().empty()) element->setName(path); //a better name element->holdRef(Pothos::Object(plugin.getModule())); return Pothos::Object(std::shared_ptr<Pothos::Block>(element)); } if (factory.type(-1) == typeid(Pothos::Topology*)) { auto element = factory.opaqueCall(args, numArgs).extract<Pothos::Topology *>(); if (element->getName().empty()) element->setName(path); //a better name element->holdRef(Pothos::Object(plugin.getModule())); return Pothos::Object(std::shared_ptr<Pothos::Topology>(element)); } throw Pothos::IllegalStateException("Pothos::BlockRegistry::make("+path+")", factory.toString()); }