示例#1
0
static std::vector<Port> resolvePorts(const Port &port, const bool isSource)
{
    std::vector<Port> ports;

    //resolve ports connected to the topology
    Pothos::Proxy subPorts;
    try
    {
        subPorts = port.obj.callProxy("resolvePorts", port.name, isSource);
    }
    catch (const Pothos::Exception &)
    {
        //its just a block, no ports to resolve
        ports.push_back(port);
        return ports;
    }

    const auto len = subPorts.call<size_t>("size");
    for (size_t i = 0; i < len; i++)
    {
        ports.push_back(proxyToPort(subPorts.callProxy("at", i)));
    }

    return ports;
}
示例#2
0
static Pothos::ProxyVector convertJObjectArrayToVector(const Pothos::Proxy &proxy)
{
    auto handle = std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle());
    auto jenv = std::dynamic_pointer_cast<JavaProxyEnvironment>(proxy.getEnvironment());

    auto ar = (jobjectArray) handle->value.l;
    Pothos::ProxyVector vec(jenv->env->GetArrayLength(ar));
    for (size_t i = 0; i < vec.size(); i++)
    {
        vec[i] = jenv->makeHandle(jenv->env->GetObjectArrayElement(ar, i));
    }
    return vec;
}
示例#3
0
std::vector<T> convertJArrayToNumericVector(const Pothos::Proxy &proxy)
{
    auto jenv = std::dynamic_pointer_cast<JavaProxyEnvironment>(proxy.getEnvironment());
    switch (sig)
    {
    #define cjatnv(PrimitiveType, jtype) \
    { \
        auto ar = (jtype ## Array) std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle())->value.l; \
        std::vector<T> vec(jenv->env->GetArrayLength(ar)); \
        jtype *elems = jenv->env->Get ## PrimitiveType ## ArrayElements(ar, nullptr); \
        for (size_t i = 0; i < vec.size(); i++) vec[i] = static_cast<T>(elems[i]); \
        jenv->env->Release ## PrimitiveType ## ArrayElements(ar, elems, JNI_ABORT); \
        return vec; \
    }
    case 'Z': cjatnv(Boolean, jboolean)
    case 'C': cjatnv(Char, jchar)
    case 'B': cjatnv(Byte, jbyte)
    case 'S': cjatnv(Short, jshort)
    case 'I': cjatnv(Int, jint)
    case 'J': cjatnv(Long, jlong)
    case 'F': cjatnv(Float, jfloat)
    case 'D': cjatnv(Double, jdouble)
    }
    poco_bugcheck_msg(std::string(1, sig).c_str()); throw;
}
示例#4
0
void save(Archive & ar, const Pothos::Proxy &t, const unsigned int)
{
    auto name = t.getEnvironment()->getName();
    ar << name;

    //serialize to stringstream
    std::stringstream ss;
    t.getEnvironment()->serialize(t, ss);
    const auto buff = ss.str();

    //save length and buffer
    const Poco::UInt32 length = Poco::UInt32(buff.size());
    ar << length;
    Pothos::serialization::binary_object bo((void *)buff.data(), buff.size());
    ar << bo;
}
示例#5
0
int RemoteProxyHandle::compareTo(const Pothos::Proxy &proxy) const
{
    std::shared_ptr<RemoteProxyHandle> handle;
    try
    {
        handle = env->getHandle(proxy);
    }
    catch(const std::exception &ex)
    {
        throw Pothos::ProxyCompareError("RemoteProxyHandle::compareTo()", Poco::format(
            "convert %s to remote - %s", proxy.toString(), std::string(ex.what())));
    }

    //create request
    Pothos::ObjectKwargs req;
    req["action"] = Pothos::Object("compareTo");
    req["handleID"] = Pothos::Object(this->remoteID);
    req["otherID"] = Pothos::Object(handle->remoteID);

    auto reply = env->transact(req);

    //check for an error
    auto errorMsgIt = reply.find("errorMsg");
    if (errorMsgIt != reply.end()) throw Pothos::ProxyCompareError(
        "RemoteProxyEnvironment::compareTo()", errorMsgIt->second.extract<std::string>());

    return reply["result"].convert<int>();
}
示例#6
0
/***********************************************************************
 * block factory - make blocks from JSON object
 **********************************************************************/
static Pothos::Proxy makeBlock(
    const Pothos::Proxy &registry,
    const Pothos::Proxy &evaluator,
    const Poco::JSON::Object::Ptr &blockObj)
{
    const auto id = blockObj->getValue<std::string>("id");

    if (not blockObj->has("path")) throw Pothos::DataFormatException(
        "Pothos::Topology::make()", "blocks["+id+"] missing 'path' field");
    const auto path = blockObj->getValue<std::string>("path");

    //load up the constructor args
    Poco::JSON::Array::Ptr argsArray;
    if (blockObj->isArray("args")) argsArray = blockObj->getArray("args");
    const auto ctorArgs = evalArgsArray(evaluator, argsArray);

    //create the block
    auto block = registry.getHandle()->call(path, ctorArgs.data(), ctorArgs.size());

    //make the calls
    Poco::JSON::Array::Ptr callsArray;
    if (blockObj->isArray("calls")) callsArray = blockObj->getArray("calls");
    if (callsArray) for (size_t i = 0; i < callsArray->size(); i++)
    {
        const auto callArray = callsArray->getArray(i);
        auto name = callArray->getElement<std::string>(0);
        const auto callArgs = evalArgsArray(evaluator, callArray, 1/*offset*/);
        block.getHandle()->call(name, callArgs.data(), callArgs.size());
    }

    return block;
}
示例#7
0
static Flow proxyToFlow(const Pothos::Proxy &flowProxy)
{
    Flow flow;
    flow.src = proxyToPort(flowProxy.get("src"));
    flow.dst = proxyToPort(flowProxy.get("dst"));
    return flow;
}
示例#8
0
static Port proxyToPort(const Pothos::Proxy &portProxy)
{
    Port port;
    port.name = portProxy.call<std::string>("get:name");
    port.obj = portProxy.get("obj");
    port.uid = portProxy.call<std::string>("get:uid");
    port.objName = portProxy.call<std::string>("get:objName");
    return port;
}
static Pothos::BufferChunk convertNumpyArrayToBufferChunk(const Pothos::Proxy &npArray)
{
    //extract shape and data type information
    const auto shape = npArray.get<Pothos::ProxyVector>("shape");
    const size_t numBytes = npArray.get<size_t>("nbytes");
    const size_t dimension = (shape.size() > 1)? shape.at(1).convert<size_t>() : 1;
    const auto dtypeName = npArray.get("dtype").get<std::string>("name");
    const Pothos::DType dtype(dtypeName, dimension);
    const size_t address = npArray.get("__array_interface__").call("get", "data").call("__getitem__", 0);

    //create a shared buffer that holds the numpy array
    auto sharedBuff = Pothos::SharedBuffer(address, numBytes, npArray.getHandle());

    //now create a buffer chunk of that shared buffer with matching dtype
    auto chunk = Pothos::BufferChunk(sharedBuff);
    chunk.dtype = dtype;
    return chunk;
}
示例#10
0
static Pothos::ProxyVector convertJVectorToVector(const Pothos::Proxy &proxy)
{
    Pothos::ProxyVector vec(proxy.call<size_t>("size"));
    for (size_t i = 0; i < vec.size(); i++)
    {
        vec[i] = proxy.callProxy("get", i);
    }
    return vec;
}
示例#11
0
static Pothos::ProxySet convertJSetToSet(const Pothos::Proxy &proxy)
{
    Pothos::ProxySet set;
    auto it = proxy.callProxy("iterator");
    while (it.call<bool>("hasNext"))
    {
        set.insert(it.callProxy("next"));
    }
    return set;
}
示例#12
0
static Pothos::ProxyMap convertJMapToMap(const Pothos::Proxy &proxy)
{
    Pothos::ProxyMap map;
    auto it = proxy.callProxy("entrySet").callProxy("iterator");
    while (it.call<bool>("hasNext"))
    {
        auto entry = it.callProxy("next");
        map[entry.callProxy("getKey")] = entry.callProxy("getValue");
    }
    return map;
}
示例#13
0
bool Pothos::Proxy::operator>(const Pothos::Proxy &obj) const
{
    try
    {
        return this->compareTo(obj) > 0;
    }
    catch (const Pothos::ProxyCompareError &)
    {
        return this->hashCode() > obj.hashCode();
    }
}
示例#14
0
static std::vector<Flow> resolveFlows(const Pothos::Proxy &obj)
{
    std::vector<Flow> flows;

    //resolve flows within the topology
    Pothos::Proxy subFlows;
    try
    {
        subFlows = obj.callProxy("resolveFlows");
    }
    catch (const Pothos::Exception &)
    {
        return flows;
    }

    const auto len = subFlows.call<size_t>("size");
    for (size_t i = 0; i < len; i++)
    {
        flows.push_back(proxyToFlow(subFlows.callProxy("at", i)));
    }

    return flows;
}
示例#15
0
/***********************************************************************
 * evaluate an args array (calls and constructors)
 **********************************************************************/
static std::vector<Pothos::Proxy> evalArgsArray(
    const Pothos::Proxy &evaluator,
    const Poco::JSON::Array::Ptr &argsArray,
    const size_t offset = 0)
{
    std::vector<Pothos::Proxy> args;
    if (argsArray) for (size_t i = offset; i < argsArray->size(); i++)
    {
        auto arg = argsArray->get(i).toString();
        if (argsArray->get(i).isString()) arg = "\""+arg+"\"";
        const auto obj = evaluator.call<Pothos::Object>("eval", arg);
        args.push_back(evaluator.getEnvironment()->convertObjectToProxy(obj));
    }
    return args;
}
示例#16
0
/***********************************************************************
 * create JSON stats object
 **********************************************************************/
static Poco::JSON::Object::Ptr queryWorkStats(const Pothos::Proxy &block)
{
    //try recursive traversal
    try
    {
        auto json = block.call<std::string>("queryJSONStats");
        Poco::JSON::Parser p; p.parse(json);
        return p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
    }
    catch (Pothos::Exception &) {}

    //otherwise, regular block, query stats
    auto actor = block.callProxy("get:_actor");
    auto workStats = actor.call<Poco::JSON::Object::Ptr>("queryWorkStats");
    Poco::JSON::Object::Ptr topStats(new Poco::JSON::Object());
    topStats->set(block.call<std::string>("uid"), workStats);
    return topStats;
}
示例#17
0
static T convertJPrimitiveToNum(const Pothos::Proxy &proxy)
{
    auto handle = std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle());
    assert(sig == handle->sig);
    return jvalueToNum<sig, T>(handle->value);
}
示例#18
0
static std::string convertJStringToString(const Pothos::Proxy &proxy)
{
    auto handle = std::dynamic_pointer_cast<JavaProxyHandle>(proxy.getHandle());
    auto env = std::dynamic_pointer_cast<JavaProxyEnvironment>(proxy.getEnvironment());
    return env->jstringToString(handle->value.l);
}