Exemple #1
0
void WindowFunction::setType(const std::string &type)
{
    //parse the input
    Poco::RegularExpression::MatchVec matches;
    Poco::RegularExpression("^\\s*(\\w+)\\s*(\\((.*)\\))?\\s*$").match(type, 0, matches);
    if (matches.empty()) throw Pothos::InvalidArgumentException("WindowFunction("+type+")", "cant parse window type");

    //parse the args
    Poco::JSON::Array::Ptr args(new Poco::JSON::Array());
    if (matches.size() > 3)
    {
        auto argsStr = type.substr(matches[3].offset, matches[3].length);
        Poco::JSON::Parser p; p.parse("["+argsStr+"]");
        args = p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>();
    }

    //check input
    auto name = Poco::toLower(type.substr(matches[1].offset, matches[1].length));
    if (name == "kaiser")
    {
        if (args->size() != 1) throw Pothos::InvalidArgumentException("WindowFunction("+type+")", "expects format: kaiser(beta)");
    }
    else if (args->size() != 0) throw Pothos::InvalidArgumentException("WindowFunction("+type+")", name + " takes no arguments");

    //bind window function
    if (name == "rectangular") _calc = &rectangular;
    else if (name == "hann") _calc = &hann;
    else if (name == "hamming") _calc = &hamming;
    else if (name == "blackman") _calc = &blackman;
    else if (name == "bartlett") _calc = &bartlett;
    else if (name == "flattop") _calc = &flattop;
    else if (name == "kaiser") _calc = std::bind(&kaiser, std::placeholders::_1, std::placeholders::_2, args->getElement<double>(0));
    else throw Pothos::InvalidArgumentException("WindowFunction::setType("+type+")", "unknown window name");
    this->reload();
}
Exemple #2
0
AffinityZoneEditor *AffinityZonesDock::createZoneFromName(const QString &zoneName)
{
    auto editor = new AffinityZoneEditor(this);
    _editorsTabs->addTab(editor, zoneName);
    if (zoneName == getSettings().value("AffinityZones/currentZone").toString()) _editorsTabs->setCurrentWidget(editor);

    //restore the settings from save -- even if this is a new panel with the same name as a previous one
    auto json = getSettings().value("AffinityZones/zones/"+zoneName).toString();
    if (not json.isEmpty()) try
    {
        Poco::JSON::Parser p; p.parse(json.toStdString());
        auto dataObj = p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
        editor->loadFromConfig(dataObj);
    }
    catch (const Poco::JSON::JSONException &ex)
    {
        poco_error_f2(Poco::Logger::get("PothosGui.AffinityZonesDock"), "Failed to load editor for zone '%s' -- %s", zoneName.toStdString(), ex.displayText());
    }

    //now connect the changed signal after initialization+restore changes
    connect(editor, SIGNAL(settingsChanged(void)), this, SLOT(handleZoneEditorChanged(void)));
    connect(editor, SIGNAL(settingsChanged(void)), _mapper, SLOT(map(void)));
    _mapper->setMapping(editor, zoneName);

    //when to update colors
    connect(editor, SIGNAL(settingsChanged(void)), this, SLOT(updateTabColors(void)));
    this->updateTabColors();

    return editor;
}
Exemple #3
0
void GraphDraw::dropEvent(QDropEvent *event)
{
    const auto &byteArray = event->mimeData()->data("text/json/pothos_block");
    Poco::JSON::Parser p; p.parse(std::string(byteArray.constData(), byteArray.size()));
    const auto blockDesc = p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();

    this->getGraphEditor()->handleAddBlock(blockDesc, event->pos());
    QWidget::dropEvent(event);
}
void load(Archive & ar, Poco::JSON::Object::Ptr &t, const unsigned int)
{
    bool isNull = false;
    ar >> isNull;
    if (isNull) return;
    std::string s; ar >> s;
    Poco::JSON::Parser p; p.parse(s);
    t = p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
}
Exemple #5
0
//! Turn a simple expression into a type-specific container
static Poco::Dynamic::Var exprToDynVar(const std::string &expr)
{
    try
    {
        Poco::JSON::Parser p; p.parse("["+expr+"]");
        return p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>()->get(0);
    }
    catch (const Poco::Exception &){}
    return expr;
}
Exemple #6
0
OpenClKernel::OpenClKernel(const std::string &deviceId, const std::string &portMarkup):
    _localSize(1),
    _globalFactor(1.0),
    _productionFactor(1.0)
{
    const auto colon = deviceId.find(":");
    const auto platformIndex = Poco::NumberParser::parseUnsigned(deviceId.substr(0, colon));
    const auto deviceIndex = Poco::NumberParser::parseUnsigned(deviceId.substr(colon+1));

    /* Identify a platform */
    cl_int err = 0;
    cl_uint num_platforms = 0;
    cl_platform_id platforms[64];
    err = clGetPlatformIDs(64, platforms, &num_platforms);
    if (err < 0) throw Pothos::Exception("OpenClKernel::clGetPlatformIDs()", clErrToStr(err));
    if (platformIndex >= num_platforms) throw Pothos::Exception("OpenClKernel()", "platform index does not exist");
    _platform = platforms[platformIndex];

    /* Access a device */
    cl_uint num_devices = 0;
    cl_device_id devices[64];
    err = clGetDeviceIDs(_platform, CL_DEVICE_TYPE_ALL, 64, devices, &num_devices);
    if (err < 0) throw Pothos::Exception("OpenClKernel::clGetDeviceIDs()", clErrToStr(err));
    if (deviceIndex >= num_devices) throw Pothos::Exception("OpenClKernel()", "device index does not exist");
    _device = devices[deviceIndex];

    /* Create context */
    _context = lookupContextCache(_device);

    /* Create ports */
    _myDomain = "OpenCl_"+std::to_string(size_t(_device));
    Poco::JSON::Parser p; p.parse(portMarkup);
    const auto ports = p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>();
    const auto inputs = ports->getArray(0);
    const auto outputs = ports->getArray(1);
    for (size_t i = 0; i < inputs->size(); i++)
    {
        this->setupInput(i, Pothos::DType("custom", inputs->getElement<int>(i)), _myDomain);
    }
    for (size_t i = 0; i < outputs->size(); i++)
    {
        this->setupOutput(i, Pothos::DType("custom", outputs->getElement<int>(i)), _myDomain);
    }

    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setSource));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setLocalSize));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, getLocalSize));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setGlobalFactor));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, getGlobalFactor));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, setProductionFactor));
    this->registerCall(POTHOS_FCN_TUPLE(OpenClKernel, getProductionFactor));
}
Exemple #7
0
/***********************************************************************
 * 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());
    }
Exemple #8
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;
}
Exemple #9
0
/***********************************************************************
 * String/file parser - make JSON object from string
 **********************************************************************/
static Poco::JSON::Object::Ptr parseJSONStr(const std::string &json)
{
    //determine markup string or file path
    bool isPath = false;
    try {isPath = Poco::File(json).exists();}
    catch (...){}

    //parse the json string/file to a JSON object
    Poco::JSON::Parser p;
    if (isPath)
    {
        std::ifstream ifs(json);
        p.parse(ifs);
    }
    else
    {
        p.parse(json);
    }
    return p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
}
Exemple #10
0
Pothos::ThreadPoolArgs::ThreadPoolArgs(const std::string &json):
    numThreads(0),
    priority(0.0)
{
    //parse to JSON object
    Poco::JSON::Parser p;
    p.parse(json);
    auto topObj = p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();

    //parse out the optional fields
    this->numThreads = topObj->optValue<int>("numThreads", 0);
    this->priority = topObj->optValue<double>("priority", 0.0);
    this->affinityMode = topObj->optValue<std::string>("affinityMode", "");
    this->yieldMode = topObj->optValue<std::string>("yieldMode", "");

    //parse out the affinity list
    Poco::JSON::Array::Ptr affinityArray;
    if (topObj->isArray("affinity")) affinityArray = topObj->getArray("affinity");
    if (affinityArray) for (size_t i = 0; i < affinityArray->size(); i++)
    {
        this->affinity.push_back(affinityArray->getElement<int>(i));
    }
}
std::string Pothos::Topology::dumpJSON(const std::string &request)
{
    //extract input request
    Poco::JSON::Parser p; p.parse(request.empty()?"{}":request);
    auto configObj = p.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
    assert(configObj);
    const auto modeConfig = configObj->optValue<std::string>("mode", "flat");

    //parse request into traversal arguments
    const bool flatten = (modeConfig == "flat");
    const bool traverse = (modeConfig != "rendered");
    const auto &flows = (modeConfig == "rendered")?_impl->activeFlatFlows:_impl->flows;

    //replace rendered names with names from flattened hierarchy
    Poco::JSON::Object::Ptr flatBlocks;
    if (modeConfig == "rendered")
    {
        Poco::JSON::Parser pFlat; pFlat.parse(this->dumpJSON("{\"mode\":\"flat\"}"));
        auto flatObj = pFlat.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
        assert(flatObj);
        flatBlocks = flatObj->getObject("blocks");
        assert(flatBlocks);
    }

    //output object
    Poco::JSON::Object::Ptr topObj(new Poco::JSON::Object());

    //create blocks map
    Poco::JSON::Object::Ptr blocksObj(new Poco::JSON::Object());
    topObj->set("blocks", blocksObj);
    for (const auto &block : getObjSetFromFlowList(flows))
    {
        //gather block info
        Poco::JSON::Object::Ptr blockObj(new Poco::JSON::Object());
        const auto blockId = block.call<std::string>("uid");
        blocksObj->set(blockId, blockObj);

        //replace rendered names with names from flattened hierarchy
        blockObj->set("name", block.call<std::string>("getName"));
        if (flatBlocks and flatBlocks->has(blockId))
        {
            blockObj->set("name", flatBlocks->getObject(blockId)->getValue<std::string>("name"));
        }

        //input port info
        Poco::JSON::Array::Ptr inputsArray(new Poco::JSON::Array());
        for (const auto &portInfo : block.call<std::vector<PortInfo>>("inputPortInfo"))
        {
            inputsArray->add(portInfoToObj(portInfo));
        }
        if (inputsArray->size() > 0) blockObj->set("inputs", inputsArray);

        //output port info
        Poco::JSON::Array::Ptr outputsArray(new Poco::JSON::Array());
        for (const auto &portInfo : block.call<std::vector<PortInfo>>("outputPortInfo"))
        {
            outputsArray->add(portInfoToObj(portInfo));
        }
        if (outputsArray->size() > 0) blockObj->set("outputs", outputsArray);

        //sub-topology info
        if (traverse and this->uid() != blockId) try
        {
            auto subDump = block.call<std::string>("dumpJSON", "{\"mode\":\"top\"}");
            Poco::JSON::Parser psub; psub.parse(subDump);
            auto subObj = psub.getHandler()->asVar().extract<Poco::JSON::Object::Ptr>();
            assert(subObj);
            std::vector<std::string> names; subObj->getNames(names);
            for (const auto &name : names) blockObj->set(name, subObj->get(name));
        }
        catch (const Pothos::Exception &){}
    }

    //create connections list
    Poco::JSON::Array::Ptr connsArray(new Poco::JSON::Array());
    topObj->set("connections", connsArray);
    for (const auto &flow : flows)
    {
        Poco::JSON::Object::Ptr connObj(new Poco::JSON::Object());
        connsArray->add(connObj);
        connObj->set("srcId", flow.src.uid);
        connObj->set("srcName", flow.src.name);
        connObj->set("dstId", flow.dst.uid);
        connObj->set("dstName", flow.dst.name);
    }

    //recursive flatten when instructed
    while (flatten and flattenDump(topObj));

    //return the string-formatted result
    std::stringstream ss; topObj->stringify(ss, 4);
    return ss.str();
}
Exemple #12
0
void GraphEditor::handlePaste(void)
{
    if (not this->isVisible()) return;
    auto draw = this->getCurrentGraphDraw();

    auto mimeData = QApplication::clipboard()->mimeData();
    const bool canPaste = mimeData->hasFormat("text/json/pothos_object_array") and
                      not mimeData->data("text/json/pothos_object_array").isEmpty();
    if (not canPaste) return;

    //extract object array
    const auto data = mimeData->data("text/json/pothos_object_array");
    const std::string dataStr(data.constData(), data.size());
    std::istringstream iss(dataStr);
    Poco::JSON::Parser p; p.parse(iss);
    auto graphObjects = p.getHandler()->asVar().extract<Poco::JSON::Array::Ptr>();
    assert(graphObjects);

    //rewrite ids
    std::map<std::string, std::string> oldIdToNew;
    for (size_t objIndex = 0; objIndex < graphObjects->size(); objIndex++)
    {
        const auto jGraphObj = graphObjects->getObject(objIndex);
        auto oldId = jGraphObj->getValue<std::string>("id");
        oldIdToNew[oldId] = this->newId(QString::fromStdString(oldId)).toStdString();
    }
    for (size_t objIndex = 0; objIndex < graphObjects->size();)
    {
        for (auto &pair : *graphObjects->getObject(objIndex))
        {
            if (QString::fromStdString(pair.first).endsWith("id", Qt::CaseInsensitive))
            {
                //if not in oldIdToNew, remove from list
                if (oldIdToNew.count(pair.second) == 0)
                {
                    graphObjects->remove(objIndex);
                    goto nextObj;
                }
                pair.second = oldIdToNew[pair.second];
            }
        }
        objIndex++;
        nextObj: continue;
    }

    //unselect all objects
    draw->deselectAllObjs();

    //create objects
    GraphObjectList objsToMove;
    objsToMove.append(handlePasteType(draw, graphObjects, "Block"));
    objsToMove.append(handlePasteType(draw, graphObjects, "Breaker"));
    handlePasteType(draw, graphObjects, "Connection"); //dont append, connection position doesnt matter
    objsToMove.append(handlePasteType(draw, graphObjects, "Widget"));

    //deal with initial positions of pasted objects
    QPointF cornerest(1e6, 1e6);
    for (auto obj : objsToMove)
    {
        cornerest.setX(std::min(cornerest.x(), obj->pos().x()));
        cornerest.setY(std::min(cornerest.y(), obj->pos().y()));
    }

    //determine an acceptable position to center the paste
    auto view = dynamic_cast<QGraphicsView *>(this->currentWidget());
    auto pastePos = view->mapToScene(view->mapFromGlobal(QCursor::pos()));
    if (not view->sceneRect().contains(pastePos))
    {
        pastePos = view->mapToScene(this->size().width()/2, this->size().height()/2);
    }

    //move objects into position
    for (auto obj : objsToMove) obj->setPos(obj->pos()-cornerest+pastePos);

    handleStateChange(GraphState("edit-paste", tr("Paste %1").arg(draw->getSelectionDescription())));
}