示例#1
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;
}
示例#2
0
void GraphEditor::load(void)
{
    auto fileName = this->getCurrentFilePath().toStdString();

    if (fileName.empty())
    {
        _stateManager->resetToDefault();
        handleStateChange(GraphState("document-new", tr("Create new topology")));
        _stateManager->saveCurrent();
        this->render();
        return;
    }

    try
    {
        poco_information_f1(Poco::Logger::get("PothosGui.GraphEditor.load"), "Loading %s from file", fileName);
        postStatusMessage(tr("Loading %1").arg(QString::fromStdString(fileName)));
        std::ifstream inFile(fileName.c_str());
        this->loadState(inFile);
    }
    catch (const std::exception &ex)
    {
        poco_error_f2(Poco::Logger::get("PothosGui.GraphEditor.load"), "Error loading %s: %s", fileName, std::string(ex.what()));
    }

    _stateManager->resetToDefault();
    handleStateChange(GraphState("document-new", tr("Load topology from file")));
    _stateManager->saveCurrent();
    this->updateGraphEditorMenus();
    this->render();
}
示例#3
0
/**
 * Ham get Item co key=itemID trong HashDB.
 * @param hashDB
 * @param itemID
 * @return Item
 */
Item ItemDB::getItemInHashDB(string itemID) {
    string value;
    Item itemReturn;
    try {
        hashDB.get(itemID, &value);
        itemReturn = convertJsonToItem(value);
        itemReturn.itemID = itemID;
        return itemReturn;
    } catch (...) {
        cerr << "getItemInHashDB: Get error " << hashDB.error().name() << endl;
        poco_error_f2(*logger, "getItemInHashDB: Can't open ItemID %s in HashDB. Error is %s.", itemID, hashDB.error().name());
        itemReturn.itemID = "-1";
        return itemReturn;
    }
}
示例#4
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());
    }
示例#5
0
void Pothos::InputPort::asyncMessagesPush(const Pothos::Object &message, const Pothos::BufferChunk &token)
{
    assert(_actor != nullptr);
    std::lock_guard<Util::SpinLock> lock(_asyncMessagesLock);
    if (_asyncMessages.full())
    {
        if (_asyncMessages.size() >= MaxQueueCapacity)
        {
            _asyncMessages.clear();
            poco_error_f2(Poco::Logger::get("Pothos.InputPort.messages"),
                "%s[%s] detected input message overflow condition",
                _actor->block->getName(), this->alias());
        }
        else _asyncMessages.set_capacity(_asyncMessages.capacity()*2);
    }
    _asyncMessages.push_back(std::make_pair(message, token));
    _actor->flagExternalChange();
}
示例#6
0
void GraphEditor::save(void)
{
    assert(not this->getCurrentFilePath().isEmpty());

    auto fileName = this->getCurrentFilePath().toStdString();
    try
    {
        std::ofstream outFile(fileName.c_str());
        this->dumpState(outFile);
    }
    catch (const std::exception &ex)
    {
        poco_error_f2(Poco::Logger::get("PothosGui.GraphEditor.save"), "Error saving %s: %s", fileName, std::string(ex.what()));
    }

    _stateManager->saveCurrent();
    this->render();
}
示例#7
0
void Pothos::InputPort::slotCallsPush(const Pothos::Object &args, const Pothos::BufferChunk &token)
{
    {
        std::lock_guard<Util::SpinLock> lock(_slotCallsLock);
        if (_slotCalls.full())
        {
            if (_slotCalls.size() >= MaxQueueCapacity)
            {
                _slotCalls.clear();
                poco_error_f2(Poco::Logger::get("Pothos.InputPort.slots"),
                    "%s[%s] detected input slot overflow condition",
                    _actor->block->getName(), this->alias());
            }
            else _slotCalls.set_capacity(_slotCalls.capacity()*2);
        }
        _slotCalls.emplace_back(args, token);
    }

    assert(_actor != nullptr);
    _actor->flagExternalChange();
}
示例#8
0
void EnvironmentEval::update(void)
{
    if (this->isFailureState()) _env.reset();

    try
    {
        //env already exists, try test communication
        if (_env)
        {
            _env->findProxy("Pothos/Util/EvalEnvironment");
        }
        //otherwise, make a new env
        else
        {
            _env = this->makeEnvironment();
            auto EvalEnvironment = _env->findProxy("Pothos/Util/EvalEnvironment");
            _eval = EvalEnvironment.callProxy("make");
            _failureState = false;
        }
    }
    catch (const Pothos::Exception &ex)
    {
        //dont report errors if we were already in failure mode
        if (_failureState) return;
        _failureState = true;

        //determine if the remote host is offline or the process just crashed
        const auto hostUri = getHostProcFromConfig(_zoneName, _config).first;
        try
        {
            Pothos::RemoteClient client(hostUri);
            _errorMsg = tr("Remote environment %1 crashed").arg(_zoneName);
        }
        catch(const Pothos::RemoteClientError &)
        {
            _errorMsg = tr("Remote host %1 is offline").arg(QString::fromStdString(hostUri));
        }
        poco_error_f2(Poco::Logger::get("PothosGui.EnvironmentEval.update"), "%s - %s", ex.displayText(), _errorMsg.toStdString());
    }
}
示例#9
0
Template::Ptr TemplateCache::getTemplate(const Path& path)
{
	if ( _logger )
	{
		poco_trace_f1(*_logger, "Trying to load %s", path.toString());
	}
	Path templatePath = resolvePath(path);
	std::string templatePathname = templatePath.toString();
	if ( _logger )
	{
		poco_trace_f1(*_logger, "Path resolved to %s", templatePathname);
	}
	File templateFile(templatePathname);

	Template::Ptr tpl;

	std::map<std::string, Template::Ptr>::iterator it = _cache.find(templatePathname);
	if ( it == _cache.end() )
	{
		if ( templateFile.exists() )
		{
			if ( _logger )
			{
				poco_information_f1(*_logger, "Loading template %s", templatePath.toString());
			}

			tpl = new Template(templatePath);

			try
			{
				tpl->parse();
				_cache[templatePathname] = tpl;
			}
			catch(JSONTemplateException& jte)
			{
				if ( _logger )
				{
					poco_error_f2(*_logger, "Template %s contains an error: %s", templatePath.toString(), jte.message());
				}
			}
		}
		else
		{
			if ( _logger )
			{
				poco_error_f1(*_logger, "Template file %s doesn't exist", templatePath.toString());
			}
			throw FileNotFoundException(templatePathname);
		}
	}
	else
	{
		tpl = it->second;
		if ( tpl->parseTime() < templateFile.getLastModified() )
		{
			if ( _logger )
			{
				poco_information_f1(*_logger, "Reloading template %s", templatePath.toString());
			}

			tpl = new Template(templatePath);

			try
			{
				tpl->parse();
				_cache[templatePathname] = tpl;
			}
			catch(JSONTemplateException& jte)
			{
				if ( _logger )
				{
					poco_error_f2(*_logger, "Template %s contains an error: %s", templatePath.toString(), jte.message());
				}
			}
		}
	}

	return tpl;
}
示例#10
0
void GraphEditor::exportToJSONTopology(const QString &fileName)
{
    poco_information_f1(_logger, "Exporting %s", fileName.toStdString());
    Poco::JSON::Object topObj;

    //all graph objects excluding widgets which are not exported
    //we will have to filter out graphical blocks as well
    const auto graphObjects = this->getGraphObjects(~GRAPH_WIDGET);

    //global variables
    Poco::JSON::Array globals;
    for (const auto &name : this->listGlobals())
    {
        const auto &value = this->getGlobalExpression(name);
        Poco::JSON::Object globalObj;
        globalObj.set("name", name.toStdString());
        globalObj.set("value", value.toStdString());
        globals.add(globalObj);
    }
    if (globals.size() > 0) topObj.set("globals", globals);

    //thread pools (filled in by blocks loop)
    Poco::JSON::Object threadPools;
    auto affinityZones = AffinityZonesDock::global();

    //blocks
    Poco::JSON::Array blocks;
    std::map<size_t, const GraphBlock*> uidToBlock;
    for (const auto *obj : graphObjects)
    {
        const auto block = dynamic_cast<const GraphBlock *>(obj);
        if (block == nullptr) continue;
        if (block->isGraphWidget()) continue;
        uidToBlock[block->uid()] = block;

        //copy in the the id and path
        Poco::JSON::Object blockObj;
        blockObj.set("id", block->getId().toStdString());
        blockObj.set("path", block->getBlockDescPath());

        //setup the thread pool when specified
        const auto affinityZone = block->getAffinityZone();
        if (not affinityZone.isEmpty() and affinityZone != "gui")
        {
            const auto config = affinityZones->zoneToConfig(affinityZone);
            threadPools.set(affinityZone.toStdString(), config);
            blockObj.set("threadPool", affinityZone.toStdString());
        }

        //block description args are in the same format
        const auto desc = block->getBlockDesc();
        if (desc->has("args")) blockObj.set("args", desc->get("args"));

        //copy in the named calls in array format
        Poco::JSON::Array calls;
        if (desc->isArray("calls")) for (const auto &elem : *desc->getArray("calls"))
        {
            const auto callObj = elem.extract<Poco::JSON::Object::Ptr>();
            Poco::JSON::Array call;
            call.add(callObj->get("name"));
            for (const auto &arg : *callObj->getArray("args")) call.add(arg);
            calls.add(call);
        }
        blockObj.set("calls", calls);

        //copy in the parameters as local variables
        Poco::JSON::Array locals;
        for (const auto &name : block->getProperties())
        {
            Poco::JSON::Object local;
            local.set("name", name.toStdString());
            local.set("value", block->getPropertyValue(name).toStdString());
            locals.add(local);
        }
        blockObj.set("locals", locals);

        blocks.add(blockObj);
    }
    topObj.set("blocks", blocks);
    if (threadPools.size() > 0) topObj.set("threadPools", threadPools);

    //connections
    Poco::JSON::Array connections;
    for (const auto &connInfo : TopologyEval::getConnectionInfo(graphObjects))
    {
        //the block may have been filtered out
        //check that its found in the mapping
        auto srcIt = uidToBlock.find(connInfo.srcBlockUID);
        if (srcIt == uidToBlock.end()) continue;
        auto dstIt = uidToBlock.find(connInfo.dstBlockUID);
        if (dstIt == uidToBlock.end()) continue;

        //create the connection information in order
        Poco::JSON::Array connArr;
        connArr.add(srcIt->second->getId().toStdString());
        connArr.add(connInfo.srcPort);
        connArr.add(dstIt->second->getId().toStdString());
        connArr.add(connInfo.dstPort);
        connections.add(connArr);
    }
    topObj.set("connections", connections);

    //write to file
    try
    {
        std::ofstream outFile(fileName.toStdString().c_str());
        topObj.stringify(outFile, 4/*indent*/);
    }
    catch (const std::exception &ex)
    {
        poco_error_f2(_logger, "Error exporting %s: %s", fileName, std::string(ex.what()));
    }
}