Пример #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>());
    }
}
Пример #2
0
string ExposerConfig::extract_token(string response_string) {
	try
	{
		//Try to extract token
		Poco::JSON::Parser parser;
		Poco::Dynamic::Var result = parser.parse(response_string);
		Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
		string tmptoken = object->get("token");

		ostringstream tmpmsg;
		//tmpmsg << " ===== Got a token: " << tmptoken;
		tmpmsg << " ===== Got a token.";
		Log::log(Log::INFO, tmpmsg.str());

		return tmptoken;
	}
	catch (std::exception &ex)
	{
		ostringstream tmpmsg;
		tmpmsg << "Exception when trying to read token: " << ex.what();
		Log::log(Log::ERROR, tmpmsg.str());
		return "";
	}

}
Пример #3
0
void ChannelController::copy()
{
	Poco::JSON::Object::Ptr pcfParameters;
	if (data().has("input") && data().isObject("input"))
	{
		pcfParameters = data().getObject("input");
	}
	else
	{
		pcfParameters = new Poco::JSON::Object();

		std::vector<std::string> parameters = getParameters();
		if (parameters.size() > 2)
		{
			pcfParameters->set("FromChannelName", parameters[2]);
		}
		if (parameters.size() > 1)
		{
			pcfParameters->set("ToChannelName", parameters[1]);
		}

		// Copy all query parameters to PCF
		for (Poco::Net::NameValueCollection::ConstIterator it = form().begin(); it != form().end(); ++it)
		{
			pcfParameters->set(it->first, it->second);
		}
	}

	ChannelCopy command(*commandServer(), pcfParameters);
	command.execute();
}
Пример #4
0
void ChannelController::start()
{
	Poco::JSON::Object::Ptr pcfParameters;

	if ( data().has("input") && data().isObject("input") )
	{
			pcfParameters = data().getObject("input");
	}
	else
	{
			pcfParameters = new Poco::JSON::Object();
			setData("input", pcfParameters);

			std::vector<std::string> parameters = getParameters();
			// First parameter is queuemanager
			// Second parameter is a channelname
			if ( parameters.size() > 1 )
			{
				  pcfParameters->set("ChannelName", parameters[1]);
			}
			else
			{
				  if ( form().has("ChannelName") ) pcfParameters->set("ChannelName", form().get("ChannelName"));
			}

			if ( form().has("CommandScope") ) pcfParameters->set("CommandScope", form().get("CommandScope"));
			if ( form().has("ChannelDisposition") ) pcfParameters->set("ChannelDisposition", form().get("ChannelDisposition"));
	}

	ChannelStart command(*commandServer(), pcfParameters);
	setData("data", command.execute());
}
Пример #5
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>();
		}
	}
}
Пример #6
0
void QueueStatusController::inquire()
{
	Poco::JSON::Object::Ptr pcfParameters;

	if ( data().has("input") && data().isObject("input") )
	{
		pcfParameters = data().getObject("input");
	}
	else
	{
		pcfParameters = new Poco::JSON::Object();
		setData("input", pcfParameters);

		std::vector<std::string> parameters = getParameters();
		// First parameter is queuemanager
		// Second parameter can be a queuename. If this is passed, the
		// query parameter QName or queueName is ignored.
		if ( parameters.size() > 1 )
		{
			pcfParameters->set("QName", parameters[1]);
		}
		else
		{
			// Handle query parameters
			pcfParameters->set("QName", form().get("QName", "*"));
		}

		pcfParameters->set("ExcludeSystem", form().get("ExcludeSystem", "false").compare("true") == 0);
		pcfParameters->set("ExcludeTemp", form().get("ExcludeTemp", "false").compare("true") == 0);

		if ( form().has("CommandScope") )
		{
			pcfParameters->set("CommandScope", form().get("CommandScope"));
		}
		if ( form().has("QSGDisposition") )
		{
			pcfParameters->set("QSGDisposition", form().get("QSGDisposition"));
		}

		if ( form().has("StatusType") ) pcfParameters->set("StatusType", form().get("StatusType"));
		if ( form().has("OpenType") ) pcfParameters->set("OpenType", form().get("OpenType"));

		handleFilterForm(pcfParameters);

		Poco::JSON::Array::Ptr attrs = new Poco::JSON::Array();
		formElementToJSONArray("QStatusAttrs", attrs);
		if ( attrs->size() == 0 ) // Nothing found for QStatusAttrs, try Attrs
		{
			formElementToJSONArray("Attrs", attrs);
		}
		if ( attrs->size() > 0 )
		{
			pcfParameters->set("QStatusAttrs", attrs);
		}

	}

	QueueStatusInquire command(*commandServer(), pcfParameters);
	setData("data", command.execute());
}
Пример #7
0
void ChannelController::create()
{
	Poco::JSON::Object::Ptr pcfParameters;
	if (data().has("input") && data().isObject("input"))
	{
		pcfParameters = data().getObject("input");
	}
	else
	{
		pcfParameters = new Poco::JSON::Object();

		std::vector<std::string> parameters = getParameters();
		if (parameters.size() > 1)
		{
			pcfParameters->set("ChannelName", parameters[1]);
		}
		if (parameters.size() > 2)
		{
			pcfParameters->set("ChannelType", parameters[2]);
		}
		// Copy all query parameters to PCF, except ChannelName if it is already set on the URI
		for (Poco::Net::NameValueCollection::ConstIterator it = form().begin(); it != form().end(); ++it)
		{
			if (parameters.size() > 1 && Poco::icompare(it->first, "ChannelName") == 0) continue;
			if (parameters.size() > 2 && Poco::icompare(it->first, "ChannelType") == 0) continue;
			pcfParameters->set(it->first, it->second);
		}
	}
	ChannelCreate command(*commandServer(), pcfParameters);
	command.execute();
}
Пример #8
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;
}
Пример #9
0
int main(int argc, char** argv)
{
	Poco::JSON::Object::Ptr obj;

	std::string dir = Poco::Environment::get("POCO_BASE") + "/JSON/samples/Benchmark/";
	Poco::Path filePath(dir, "input");

	std::ostringstream ostr;

	if ( filePath.isFile() )
	{
		Poco::File inputFile(filePath);
		if ( inputFile.exists() )
		{
			Poco::FileInputStream fis(filePath.toString());
			Poco::StreamCopier::copyStream(fis, ostr);
		}
		else
		{
			std::cout << filePath.toString() << " doesn't exist!" << std::endl;
			return 1; 
		}
	}

	std::cout << std::setw(25) << "POCO JSON";

	std::string jsonStr = ostr.str();
	
	try
	{
		Poco::JSON::DefaultHandler handler;
		Poco::JSON::Parser parser;
		parser.setHandler(&handler);
		Poco::Timestamp time1;
		parser.parse(jsonStr);
		Poco::DynamicAny result = handler.result();
		Poco::Timestamp time2;
		printTimeDiff(time1, time2);

		if ( result.type() == typeid(Poco::JSON::Object::Ptr) )
		{
			obj = result.extract<Poco::JSON::Object::Ptr>();
		}

		//Serialize to string
		std::ostringstream out;
		Poco::Timestamp time3;
		obj->stringify(out);
		Poco::Timestamp time4;
		printTimeDiff(time3, time4);
		std::cout << std::endl;
	}
	catch(Poco::JSON::JSONException jsone)
	{
		std::cout << jsone.message() << std::endl;
	}

	return 0;
}
Пример #10
0
void ServiceController::inquire()
{
	Poco::JSON::Object::Ptr pcfParameters;

	if ( data().has("filter") && data().isObject("filter") )
	{
		pcfParameters = data().getObject("filter");
	}
	else
	{
		pcfParameters = new Poco::JSON::Object();
		set("filter", pcfParameters);

		std::vector<std::string> parameters = getParameters();
		// First parameter is queuemanager
		// Second parameter can be a servicename. If this is passed
		// the query parameter ServiceName is ignored.
		if ( parameters.size() > 1 )
		{
			pcfParameters->set("ServiceName", parameters[1]);
		}
		else
		{
			// Handle query parameters
			std::string serviceNameField;
			if ( form().has("ServiceName") )
			{
				serviceNameField = form().get("ServiceName");
			}
			else if ( form().has("name") )
			{
				serviceNameField = form().get("name");
			}
			if ( serviceNameField.empty() )
			{
				serviceNameField = "*";
			}
			pcfParameters->set("ServiceName", serviceNameField);
		}

		pcfParameters->set("ExcludeSystem", form().get("ExcludeSystem", "false").compare("true") == 0);

		Poco::JSON::Array::Ptr attrs = new Poco::JSON::Array();
		formElementToJSONArray("ServiceAttrs", attrs);
		if ( attrs->size() == 0 ) // Nothing found for ServiceAttrs, try Attrs
		{
			formElementToJSONArray("Attrs", attrs);
		}
		if ( attrs->size() > 0 )
		{
			pcfParameters->set("ServiceAttrs", attrs);
		}

		handleFilterForm(pcfParameters);
	}

	ServiceMapper mapper(*commandServer(), pcfParameters);
	set("services", mapper.inquire());
}
Пример #11
0
void save(Archive & ar, const Poco::JSON::Object::Ptr &t, const unsigned int)
{
    bool isNull = t.isNull();
    ar << isNull;
    if (isNull) return;
    std::ostringstream oss; t->stringify(oss);
    std::string s = oss.str(); ar << s;
}
Пример #12
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();
}
Пример #13
0
//! helper to convert the port info vector into JSON for serialization of the block
static Poco::JSON::Array::Ptr portInfosToJSON(const std::vector<Pothos::PortInfo> &infos)
{
    Poco::JSON::Array::Ptr array = new Poco::JSON::Array();
    for (const auto &info : infos)
    {
        Poco::JSON::Object::Ptr portInfo = new Poco::JSON::Object();
        portInfo->set("name", info.name);
        portInfo->set("isSigSlot", info.isSigSlot);
        portInfo->set("size", info.dtype.size());
        portInfo->set("dtype", info.dtype.toMarkup());
        array->add(portInfo);
    }
    return array;
}
Пример #14
0
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;
}
Пример #15
0
void GraphConnection::deserialize(Poco::JSON::Object::Ptr obj)
{
    auto outputId = QString::fromStdString(obj->getValue<std::string>("outputId"));
    auto inputId = QString::fromStdString(obj->getValue<std::string>("inputId"));
    auto outputKey = QString::fromStdString(obj->getValue<std::string>("outputKey"));
    auto inputKey = QString::fromStdString(obj->getValue<std::string>("inputKey"));

    auto draw = dynamic_cast<GraphDraw *>(this->parent());
    assert(draw != nullptr);

    //resolve IO objects by id
    QPointer<GraphObject> inputObj = nullptr;
    QPointer<GraphObject> outputObj = nullptr;
    for (const auto obj : draw->getGraphObjects(false))
    {
        if (obj->getId() == inputId) inputObj = obj;
        if (obj->getId() == outputId) outputObj = obj;
    }

    if (inputObj.isNull()) throw Pothos::Exception("GraphConnection::deserialize()", "cant resolve object with ID: '"+inputId.toStdString()+"'");
    if (outputObj.isNull()) throw Pothos::Exception("GraphConnection::deserialize()", "cant resolve object with ID: '"+outputId.toStdString()+"'");

    this->setupEndpoint(GraphConnectionEndpoint(inputObj, GraphConnectableKey(inputKey, true)));
    this->setupEndpoint(GraphConnectionEndpoint(outputObj, GraphConnectableKey(outputKey, false)));

    assert(this->getInputEndpoint().isValid());
    assert(this->getOutputEndpoint().isValid());

    GraphObject::deserialize(obj);
}
Пример #16
0
void Controller::searchSimilarRequest(std::map<std::string, std::string>& params, const Poco::Dynamic::Var& request) {
    Record record;
    vector<uint8_t>* image_data = NULL;
    int count = 10;
    
    if (params.count("blockHash")) {
        record.getHashes()[BlockHash] = str2bin(params["blockHash"]);
    }
    if (params.count("dHash")) {
        record.getHashes()[DHash] = str2bin(params["dHash"]);
    }
    if (params.count("gaussDHash")) {
        record.getHashes()[GaussDHash] = str2bin(params["gaussDHash"]);
    }
    if (params.count("gauss2DHash")) {
        record.getHashes()[Gauss2DHash] = str2bin(params["gauss2DHash"]);
    }
    if (params.count("gaussBlockHash")) {
        record.getHashes()[GaussBlockHash] = str2bin(params["gaussBlockHash"]);
    }
    if (params.count("url")) {
        image_data = Image::fromUrl(params["url"]);
    }
    if (params.count("count")) {
        count = atoi(params["count"].c_str());
    }
    
    if (!request.isEmpty()) {
        Poco::JSON::Object::Ptr json = request.extract<Poco::JSON::Object::Ptr>();
        if (!image_data && json->has("image_base64")) {
            image_data = Image::fromBase64(json->getValue<string>("image_base64"));
        }
        if (!image_data && json->has("image_url")) {
            image_data = Image::fromUrl(json->getValue<string>("image_url"));
        }
    }
    
    if (image_data) {
        HashAlgorithmManager::getInstance().attachSimilarHashes(record, image_data);
        delete image_data;
    }
    
    appio::print_ok(HashManager::getInstance().searchSimilar(record, count));
}
Пример #17
0
/*!
 * Extract an args array and kwargs object parsed from an args string
 */
static void extractArgs(const std::string &argsStr, Poco::JSON::Array::Ptr &args, Poco::JSON::Object::Ptr &kwargs)
{
    for (const auto &arg : splitCommaArgs(argsStr))
    {
        const Poco::StringTokenizer kvpTok(arg, "=", Poco::StringTokenizer::TOK_TRIM);
        const std::vector<std::string> kvp(kvpTok.begin(), kvpTok.end());
        if (kwargs and kvp.size() == 2) kwargs->set(kvp[0], exprToDynVar(kvp[1]));
        else if (args) args->add(exprToDynVar(arg));
    }
}
Пример #18
0
void AuthorityServiceController::inquire()
{
	Poco::JSON::Object::Ptr pcfParameters;

	if ( data().has("filter") && data().isObject("filter") )
	{
		pcfParameters = data().getObject("filter");
		// There is a bug in MQCMD_INQUIRE_AUTH_SERVICE, AuthServiceAttrs is required!
		if ( !pcfParameters->has("AuthServiceAttrs") )
		{
			Poco::JSON::Array::Ptr attrs = new Poco::JSON::Array();
			attrs->add("All");
			pcfParameters->set("AuthServiceAttrs", attrs);
		}
	}
	else
	{
		pcfParameters = new Poco::JSON::Object();
		set("filter", pcfParameters);

		Poco::JSON::Array::Ptr attrs = new Poco::JSON::Array();
		formElementToJSONArray("AuthServiceAttrs", attrs);
		if ( attrs->size() == 0 ) // Nothing found for AuthServiceAttrs, try Attrs
		{
			formElementToJSONArray("Attrs", attrs);
		}
		if ( attrs->size() == 0 ) // Default must be specified for this command!
		{
			attrs->add("All");
		}
		pcfParameters->set("AuthServiceAttrs", attrs);

		if ( form().has("ServiceComponent") )
		{
			pcfParameters->set("ServiceComponent", form().get("ServiceComponent"));
		}

		handleFilterForm(pcfParameters);
	}

	AuthorityServiceMapper mapper(*commandServer(), pcfParameters);
	set("authservices", mapper.inquire());
}
Пример #19
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);
    }
}
Пример #20
0
Poco::JSON::Object::Ptr AffinityZoneEditor::getCurrentConfig(void) const
{
    Poco::JSON::Object::Ptr config = new Poco::JSON::Object();
    config->set("color", _colorPicker->currentColor().name().toStdString());
    config->set("hostUri", _hostsBox->itemText(_hostsBox->currentIndex()).toStdString());
    config->set("processName", _processNameEdit->text().toStdString());
    config->set("numThreads", _numThreadsSpin->value());
    config->set("priority", _prioritySpin->value()/100.0);
    assert(_cpuSelection != nullptr);
    config->set("affinityMode", _cpuSelection->mode());
    Poco::JSON::Array::Ptr affinityMask = new Poco::JSON::Array();
    for (auto num : _cpuSelection->selection()) affinityMask->add(num);
    config->set("affinityMask", affinityMask);
    config->set("yieldMode", _yieldModeBox->itemData(_yieldModeBox->currentIndex()).toString().toStdString());
    return config;
}
Пример #21
0
void QueueController::clear()
{
	Poco::JSON::Object::Ptr pcfParameters;

	if (data().has("input") && data().isObject("input"))
	{
		pcfParameters = data().getObject("input");
	}
	else
	{
		pcfParameters = new Poco::JSON::Object();
		meta().set("input", pcfParameters);

		std::vector<std::string> parameters = getParameters();
		// First parameter is queuemanager
		// Second parameter can be a queuename. If this is passed, the
		// query parameter QName or queueName is ignored.
		if (parameters.size() > 1)
		{
			pcfParameters->set("QName", parameters[1]);
		}
		else
		{
			// Handle query parameters
			pcfParameters->set("QName", form().get("QName", "*"));
		}

		if (form().has("CommandScope"))
		{
			pcfParameters->set("CommandScope", form().get("CommandScope"));
		}

		if (form().has("QSGDisposition"))
		{
			pcfParameters->set("QSGDisposition", form().get("QSGDisposition"));
		}

	}

	QueueClear command(*commandServer(), pcfParameters);
	setData("data", command.execute());
}
Пример #22
0
void ChannelController::remove()
{
	Poco::JSON::Object::Ptr pcfParameters;

	if (data().has("input") && data().isObject("input"))
	{
		pcfParameters = data().getObject("input");
	}
	else
	{
		pcfParameters = new Poco::JSON::Object();
		meta().set("input", pcfParameters);

		std::vector<std::string> parameters = getParameters();
		// First parameter is queuemanager
		// Second parameter can be a queuename. If this is passed, the
		// query parameter QName or queueName is ignored.
		if (parameters.size() > 1)
		{
			pcfParameters->set("ChannelName", parameters[1]);
		}
		else
		{
			// Handle query parameters
			std::string channelName;
			if (form().has("ChannelName"))
			{
				channelName = form().get("ChannelName");
			}
			pcfParameters->set("ChannelName", channelName);
		}

		if (form().has("CommandScope"))
		{
			pcfParameters->set("CommandScope", form().get("CommandScope"));
		}

		if (form().has("QSGDisposition"))
		{
			pcfParameters->set("QSGDisposition", form().get("QSGDisposition"));
		}

		if (form().has("ChannelType"))
		{
			pcfParameters->set("ChannelType", form().get("ChannelType"));
		}

		if (form().has("ChannelTable"))
		{
			pcfParameters->set("ChannelTable", form().get("ChannelTable"));
		}
	}

	ChannelRemove command(*commandServer(), pcfParameters);
	command.execute();
}
Пример #23
0
bool CSystemManager::getDevVersion(Poco::JSON::Object::Ptr& param, std::string& detail)
{
	CConfigManager* config = CConfigManager::instance();
	JSON::Object::Ptr pUpdate;
	config->getConfig("Update", pUpdate);
	if(pUpdate.isNull() || !pUpdate->has("infoPath"))
	{
		detail = "901";
		return false;
	}
	std::string infoPath = pUpdate->getValue<std::string>("infoPath");
	File file(infoPath);
	if(!file.exists())
	{
		detail = "465";
		return false;
	}
	Util::JSONConfiguration info;
	std::string version;
	std::string buildtime;
	try
	{
		info.load(infoPath);
		version = info.getString(UPDATE_VERSION_STR);
		buildtime = info.getString(UPDATE_BUILDTIME_STR);
	}
	catch(Exception& e)
	{
		detail = "465";
		warnf("%s, %d: Load device info file failed, %s", __FILE__, __LINE__, e.message().c_str());
		return false;
	}
	if(param->has(REG_TOKEN_STR))
	{
		param->remove(REG_TOKEN_STR);
	}
	param->set(SYSTEM_VERSION_STR, version);
	param->set(SYSTEM_BUILDTIME_STR, buildtime);
	return true;
}
Пример #24
0
void AffinityZoneEditor::loadFromConfig(const Poco::JSON::Object::Ptr &config)
{
    if (config->has("color"))
    {
        auto color = QString::fromStdString(config->getValue<std::string>("color"));
        _colorPicker->blockSignals(true);
        _colorPicker->setCurrentColor(QColor(color));
        _colorPicker->blockSignals(false);
    }
    if (config->has("hostUri"))
    {
        auto uri = QString::fromStdString(config->getValue<std::string>("hostUri"));
        this->selectThisUri(uri);
    }
    if (config->has("processName"))
    {
        auto name = QString::fromStdString(config->getValue<std::string>("processName"));
        _processNameEdit->setText(name);
    }
    if (config->has("numThreads"))
    {
        _numThreadsSpin->setValue(config->getValue<int>("numThreads"));
    }
    if (config->has("priority"))
    {
        _prioritySpin->setValue(int(config->getValue<double>("priority")*100));
    }
    if (config->has("affinityMode") and config->has("affinityMask"))
    {
        auto mode = config->getValue<std::string>("affinityMode");
        auto mask = config->getArray("affinityMask");
        std::vector<size_t> selection;
        for (size_t i = 0; i < mask->size(); i++) selection.push_back(mask->getElement<int>(i));
        _cpuSelection->setup(mode, selection);
    }
    if (config->has("yieldMode"))
    {
        auto mode = QString::fromStdString(config->getValue<std::string>("yieldMode"));
        for (int i = 0; i < _yieldModeBox->count(); i++)
        {
            if (_yieldModeBox->itemData(i).toString() == mode) _yieldModeBox->setCurrentIndex(i);
        }
    }
}
Пример #25
0
static std::vector<std::pair<std::string, std::string>> resolvePorts(
    const Poco::JSON::Object::Ptr &topObj,
    const std::string &blockId,
    const std::string &portName,
    const bool resolveSrc
)
{
    assert(topObj);
    std::vector<std::pair<std::string, std::string>> results;

    const auto blocksObj = topObj->getObject("blocks");
    assert(blocksObj);
    if (not blocksObj->has(blockId)) return results;
    const auto blockObj = blocksObj->getObject(blockId);
    assert(blockObj);

    if (not blockIsHier(blockObj))
    {
        results.push_back(std::make_pair(blockId, portName));
        return results;
    }

    const auto connsArray = blockObj->getArray("connections");
    for (size_t c_i = 0; c_i < connsArray->size(); c_i++)
    {
        const auto subConnObj = connsArray->getObject(c_i);
        assert(subConnObj);
        std::string subId, subName;

        if (resolveSrc)
        {
            if (subConnObj->getValue<std::string>("dstId") != blockId) continue;
            if (subConnObj->getValue<std::string>("dstName") != portName) continue;
            subId = subConnObj->getValue<std::string>("srcId");
            subName = subConnObj->getValue<std::string>("srcName");
        }
        else
        {
            if (subConnObj->getValue<std::string>("srcId") != blockId) continue;
            if (subConnObj->getValue<std::string>("srcName") != portName) continue;
            subId = subConnObj->getValue<std::string>("dstId");
            subName = subConnObj->getValue<std::string>("dstName");
        }

        //ignore pass-through connections in this loop
        if (subId != blockId) results.push_back(std::make_pair(subId, subName));
    }

    return results;
}
Пример #26
0
void addTask()
{
	printf("\n>>>>    Add task    <<<<\n");
	printf("Task option:");
	int option;
	int ret;
	ret = 0;
	ret = scanf("%d", &option);
	printf("Hour:");
	int hour;
	ret = scanf("%d", &hour);
	printf("Minute:");
	int minute;
	ret = scanf("%d", &minute);
	printf("Weekday:");
	int weekday = 0;
	char str[9];
	ret = scanf("%s", str);
	unsigned short mask = 0x40;
	for(int i = 0; i < 7; i++)
	{
		if(str[i] == '1')
			weekday |= mask;
		mask = mask >> 1;
	}
	printf("%x\n", weekday);
	Poco::JSON::Object::Ptr pObj = new Poco::JSON::Object;
	pObj->set("option", option);
	pObj->set("hour", hour);
	pObj->set("minute", minute);
	pObj->set("weekday", weekday);
	Poco::Int64 retval = task_manager->addTask(pObj);
	printf("Add task result: %llu.\n", retval);
	updateTasksList();
	ret++;
	getchar();
}
Пример #27
0
static Poco::JSON::Array::Ptr getConnectedPortInfos(
    const Poco::JSON::Object::Ptr &topObj,
    const std::string &blockId,
    const bool enbFilter,
    const bool isInput)
{
    const auto connsArray = topObj->getArray("connections");
    const auto blocksObj = topObj->getObject("blocks");
    const auto blockObj = blocksObj->getObject(blockId);

    //grab the raw ports info
    Poco::JSON::Array::Ptr portsInfo(new Poco::JSON::Array());
    if (isInput and blockObj->has("inputs")) portsInfo = blockObj->getArray("inputs");
    if (not isInput and blockObj->has("outputs")) portsInfo = blockObj->getArray("outputs");

    //no filtering? return ASAP
    if (not enbFilter) return portsInfo;

    Poco::JSON::Array::Ptr filteredPortsInfo(new Poco::JSON::Array());
    for (size_t i = 0; i < portsInfo->size(); i++)
    {
        const auto portInfo = portsInfo->getObject(i);
        for (size_t c_i = 0; c_i < connsArray->size(); c_i++)
        {
            const auto conn = connsArray->getObject(c_i);
            if (
                (not isInput and blockId == conn->getValue<std::string>("srcId") and portInfo->getValue<std::string>("name") == conn->getValue<std::string>("srcName")) or
                (isInput and blockId == conn->getValue<std::string>("dstId") and portInfo->getValue<std::string>("name") == conn->getValue<std::string>("dstName"))
            )
            {
                filteredPortsInfo->add(portInfo);
                break;
            }
        }
    }
    return filteredPortsInfo;
}
Пример #28
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);
}
Пример #29
0
string ExposerConfig::extract_sessionid(string json_string) {
	try
	{
		//Try to extract sessionid
		Poco::JSON::Parser parser;
		Poco::Dynamic::Var result = parser.parse(json_string);
		Poco::JSON::Object::Ptr object = result.extract<Poco::JSON::Object::Ptr>();
		string tmpsessionid = object->get("id");

		ostringstream tmpmsg;
		tmpmsg << " ===== Got a sessionid: " << tmpsessionid;
		Log::log(Log::INFO, tmpmsg.str());

		return tmpsessionid;

	}
	catch (Poco::Exception &ex)
	{
		ostringstream tmpmsg;
		tmpmsg << "Exception when trying to read sessionid: " << ex.displayText();
		Log::log(Log::ERROR, tmpmsg.str());
		return "";
	}
}
Пример #30
0
JNIEXPORT void Java_com_demo_pocodemo_MainActivity_JSONDemo(JNIEnv* env, jobject thiz) {

	// smart pointer, so don't worry about cleaning up
	Poco::JSON::Object::Ptr inner = new Poco::JSON::Object;
	inner->set("some_number", 5);
	inner->set("some_string", "xyz");

	std::string key = "new_object";
	Poco::JSON::Object::Ptr result = new Poco::JSON::Object;
	result->set(key, inner);
	printf("isObject: %i\n", result->isObject(key)); // true

	printf("size of inner json obj : %i\n", inner->size()); // true
}