示例#1
0
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();
}
示例#2
0
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;
}
示例#3
0
/***********************************************************************
 * 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
}
示例#4
0
文件: thread.c 项目: scam-lang/scam
/* thread - start up a pthread to evaluate an expression 
 *        - car(args)  := captured calling environment
 *        - cadr(args) := expression to be evaluated
 *
 *        - the calling environment gets extended, and then the expression is evaluated
 *              under the extended environment
 */
int
thread(int args)
    {
    T_P();
    ++CreatedThreads;
    ++WorkingThreads;
    P();
    ENSURE_MEMORY(MAKE_ENVIRONMENT_SIZE+INTEGER_SIZE, &args , (int *) 0);
    /* Extend the environment and create the pseudo-tid */
    int env = makeEnvironment(car(args),0,0,0);
    int expr = cadr(args);
    int tid = ++ScamThreadID;

    /* fatal if we exceed the thread limit */
    if (tid > MAX_THREADS - 1)
        {
        V();
        T_V();
        Fatal("You have reached the max thread limit of %d\n", MAX_THREADS);
        }

    int ret = newIntegerUnsafe(tid);

    ThreadQueue[tid].env  = env;
    ThreadQueue[tid].expr = expr;
    ThreadQueue[tid].tid  = tid;
    V();

    int *arg = malloc(sizeof(int));
    *arg = tid;
    int p_ret = pthread_create(&Thread[CreatedThreads-1], NULL, (void *)InternalThread,(void *)arg);

    T_V();
    if(p_ret)
        {
        Fatal("Error creating threads.\n");
        }

    return ret;
    }