Esempio n. 1
0
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();
}
Esempio n. 2
0
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>());
    }
}
Esempio n. 3
0
 Pothos::Object opaqueCallHandler(const std::string &name, const Pothos::Object *inputArgs, const size_t numArgs)
 {
     if (name == "_setPyBlock") return Pothos::Block::opaqueCallHandler(name, inputArgs, numArgs);
     if (not _block) throw name;
     auto env = _block.getEnvironment();
     Pothos::ProxyVector args(numArgs);
     for (size_t i = 0; i < numArgs; i++)
     {
         args[i] = env->convertObjectToProxy(inputArgs[i]);
     }
     auto result = _block.getHandle()->call(name, args.data(), args.size());
     return env->convertProxyToObject(result);
 }
Esempio n. 4
0
void ProxyBlockEval::handleCall(const Poco::JSON::Object::Ptr &callObj)
{
    auto env = Pothos::ProxyEnvironment::make("managed");
    const auto callName = callObj->get("name").extract<std::string>();
    std::vector<Pothos::Proxy> callArgs;
    for (auto arg : *callObj->getArray("args"))
    {
        const auto obj = this->lookupOrEvalAsType(arg);
        callArgs.push_back(env->convertObjectToProxy(obj));
    }
    try
    {
        _proxyBlock.getHandle()->call(callName, callArgs.data(), callArgs.size());
    }
    catch (const Pothos::Exception &ex)
    {
        throw Pothos::Exception("ProxyBlockEval call("+callName+")", ex);
    }
}
Esempio n. 5
0
 Proxy makeProxy(const ValueType &local)
 {
     return convertObjectToProxy(Pothos::Object::make(local));
 }
Esempio n. 6
0
/***********************************************************************
 * 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());
    }
Esempio n. 7
0
// Copyright (c) 2013-2013 Josh Blum
// SPDX-License-Identifier: BSL-1.0

#include <Pothos/Testing.hpp>
#include <Pothos/Proxy.hpp>
#include <iostream>
#include <vector>
#include <cstdlib>

POTHOS_TEST_BLOCK("/proxy/java/tests", test_basic_types)
{
    auto env = Pothos::ProxyEnvironment::make("java");

    auto noneProxy = env->convertObjectToProxy(Pothos::Object());
    auto nullObject = env->convertProxyToObject(noneProxy);
    POTHOS_TEST_TRUE(not nullObject);

    POTHOS_TEST_EQUAL(env->makeProxy(true).convert<bool>(), true);
    POTHOS_TEST_EQUAL(env->makeProxy(false).convert<bool>(), false);

    const char charVal = char((std::rand()-RAND_MAX/2)/(RAND_MAX >> 8));
    POTHOS_TEST_EQUAL(env->makeProxy(charVal).convert<char>(), charVal);

    const short shortVal = short((std::rand()-RAND_MAX/2));
    POTHOS_TEST_EQUAL(env->makeProxy(shortVal).convert<short>(), shortVal);

    const int intVal = int(std::rand()-RAND_MAX/2);
    POTHOS_TEST_EQUAL(env->makeProxy(intVal).convert<int>(), intVal);

    const long longVal = long(std::rand()-RAND_MAX/2);
    POTHOS_TEST_EQUAL(env->makeProxy(longVal).convert<long>(), longVal);