Beispiel #1
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>());
    }
}
Beispiel #2
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;
}
Beispiel #3
0
void updateTasksList()
{
	printf("updateTasksList()\n");
	tasksNum = task_manager->getTasksNumber();
	if(tasksNum > 0)
	{
		Poco::JSON::Object::Ptr pObj = new Poco::JSON::Object;
		task_manager->getTasks(pObj);
		Poco::DynamicStruct ds = *pObj;
		printf("ds:%s\n", ds.toString().c_str());
		if(pObj->has("tasks"))
			printf("pObj has tasks\n");
		if(pObj->isArray("tasks"))
			printf("pObj is array tasks\n");
		Poco::JSON::Array::Ptr pArray = pObj->getArray("tasks");
		printf("tasksNum:%d, array size:%d\n", tasksNum, pArray->size());
		for(int i = 0; i < tasksNum; i++)
		{
			memset(pTask[i], 0, sizeof(TaskInfo));
			Poco::Dynamic::Var var = pArray->get(i);
			Poco::DynamicStruct dss = var.extract<Poco::DynamicStruct>();
			pTask[i]->id = (Poco::Int64)dss["id"].extract<Poco::Int64>();
			pTask[i]->option = dss["option"].extract<int>();
			pTask[i]->hour = dss["hour"].extract<int>();
			pTask[i]->minute = dss["minute"].extract<int>();
			pTask[i]->weekday = dss["weekday"].extract<int>();
		}
	}
}
QString BlockPropertiesPanel::getParamDocString(const Poco::JSON::Object::Ptr &paramDesc)
{
    assert(paramDesc);
    QString output;
    output += QString("<h3>%1</h3>").arg(QString::fromStdString(paramDesc->getValue<std::string>("name")));
    if (paramDesc->isArray("desc")) for (const auto &lineObj : *paramDesc->getArray("desc"))
    {
        const auto line = lineObj.extract<std::string>();
        if (line.empty()) output += "<p /><p>";
        else output += QString::fromStdString(line)+"\n";
    }
    else output += QString("<p>%1</p>").arg(tr("Undocumented"));
    return output;
}
Beispiel #5
0
bool BlockTreeWidget::blockDescMatchesFilter(const Poco::JSON::Object::Ptr &blockDesc)
{
    if (_filter.isEmpty()) return true;

    const auto path = blockDesc->get("path").extract<std::string>();
    const auto name = blockDesc->get("name").extract<std::string>();

    //construct a candidate string from path, name, categories, and keywords.
    std::string candidate = path+name;
    if (blockDesc->isArray("categories")) for (auto categoryObj : *blockDesc->getArray("categories"))
    {
        candidate += categoryObj.extract<std::string>();
    }
    if(blockDesc->isArray("keywords"))
    {
        const auto keywords = blockDesc->getArray("keywords");
        for(auto keyword : *keywords) candidate += keyword.extract<std::string>();
    }

    //reject if filter string not found in candidate
    candidate = Poco::toLower(candidate);
    const auto searchToken = Poco::toLower(_filter.toStdString());
    return (candidate.find(searchToken) != std::string::npos);
}