示例#1
0
Poco::JSON::Object::Ptr BlockEval::inspectPorts(void)
{
    auto block = _proxyBlock;
    Poco::JSON::Object::Ptr info = new Poco::JSON::Object();

    info->set("uid", block.call<std::string>("uid"));

    //TODO FIXME inspect will fail for topologies ATM, cant query isSignal/isSlot on topology

    Poco::JSON::Array::Ptr inputPorts = new Poco::JSON::Array();
    for (const auto &name : block.call<std::vector<std::string>>("inputPortNames"))
    {
        Poco::JSON::Object::Ptr portInfo = new Poco::JSON::Object();
        portInfo->set("name", name);
        portInfo->set("isSlot", block.callProxy("input", name).call<bool>("isSlot"));
        portInfo->set("size", block.callProxy("input", name).callProxy("dtype").call<unsigned>("size"));
        portInfo->set("dtype", block.callProxy("input", name).callProxy("dtype").call<std::string>("toString"));
        inputPorts->add(portInfo);
    }
    info->set("inputPorts", inputPorts);

    Poco::JSON::Array::Ptr outputPorts = new Poco::JSON::Array();
    for (const auto &name : block.call<std::vector<std::string>>("outputPortNames"))
    {
        Poco::JSON::Object::Ptr portInfo = new Poco::JSON::Object();
        portInfo->set("name", name);
        portInfo->set("isSignal", block.callProxy("output", name).call<bool>("isSignal"));
        portInfo->set("size", block.callProxy("output", name).callProxy("dtype").call<unsigned>("size"));
        portInfo->set("dtype", block.callProxy("output", name).callProxy("dtype").call<std::string>("toString"));
        outputPorts->add(portInfo);
    }
    info->set("outputPorts", outputPorts);

    return info;
}
示例#2
0
int main(int argc, char** argv)
{
//	MyVector vec;
	Poco::JSON::Array::Ptr pArray = new Poco::JSON::Array;
	Poco::DynamicStruct ds1;
	ds1["aaa"] = "a1";
	ds1["bbb"] = 10;
	ds1["ccc"] = 111;
	pArray->add(ds1);
	displayArray(pArray);
//	vec.push_back(ds1);
//	displayMyVector(vec);
	Poco::DynamicStruct ds2;
	ds2["aaa"] = "a2";
	ds2["bbb"] = 20;
	ds2["ccc"] = 222;
	pArray->add(ds2);
	displayArray(pArray);
//	vec.push_back(ds2);
//	displayMyVector(vec);
	Poco::DynamicStruct ds3;
	ds3["aaa"] = "a3";
	ds3["bbb"] = 30;
	ds3["ccc"] = 333;
	pArray->add(ds3);
	displayArray(pArray);
//	vec.push_back(ds3);
//	displayMyVector(vec);
	return 0;
}
示例#3
0
Poco::JSON::Array::Ptr ClusterQueueManagerMapper::inquire()
{
	createCommand(MQCMD_INQUIRE_CLUSTER_Q_MGR);

	// Required parameters
	addParameter<std::string>(MQCA_CLUSTER_Q_MGR_NAME, "ClusterQMgrName");

	// Optional parameters
	addParameter<std::string>(MQCACH_CHANNEL_NAME, "ChannelName");
	addParameter<std::string>(MQCA_CLUSTER_NAME, "ClusterName");
	addAttributeList(MQIACF_CLUSTER_Q_MGR_ATTRS, "ClusterQMgrAttrs");
	addParameter<std::string>(MQCACF_COMMAND_SCOPE, "CommandScope");
	addIntegerFilter();
	addStringFilter();

	PCF::Vector commandResponse;
	execute(commandResponse);

	Poco::JSON::Array::Ptr json = new Poco::JSON::Array();
	for(PCF::Vector::iterator it = commandResponse.begin(); it != commandResponse.end(); it++)
	{
		if ( (*it)->getReasonCode() != MQRC_NONE ) // Skip errors (2035 not authorized for example)
			continue;

		if ( (*it)->isExtendedResponse() ) // Skip extended response
			continue;

		json->add(createJSON(**it));
	}

	return json;
}
示例#4
0
void Controller::formElementToJSONArray(const std::string& name, Poco::JSON::Array::Ptr arr)
{
	for(Poco::Net::NameValueCollection::ConstIterator it = form().find(name); 
		it != form().end() && Poco::icompare(it->first, name) == 0;
		++it)
	{
		arr->add(it->second);
	}
}
示例#5
0
Poco::JSON::Array::Ptr ConnectionMapper::inquire()
{
	createCommand(MQCMD_INQUIRE_CONNECTION);

	// Required parameters
	if ( _input->has("ConnectionId") )
	{
		std::string hexId = _input->get("ConnectionId");
		if ( hexId.length() > MQ_CONNECTION_ID_LENGTH )
		{
			hexId.erase(MQ_CONNECTION_ID_LENGTH);
		}
		Buffer::Ptr id = new Buffer(hexId);

		pcf()->addParameter(MQBACF_CONNECTION_ID, id);
	}
	else
	{
		Buffer::Ptr id = new Buffer(MQ_CONNECTION_ID_LENGTH); // Empty buffer
		memset(id->data(), 0, MQ_CONNECTION_ID_LENGTH);
		pcf()->addParameter(MQBACF_GENERIC_CONNECTION_ID, id);
	}

	// Optional parameters
	//TODO: ByteStringFilter
	addParameter<std::string>(MQCACF_COMMAND_SCOPE, "CommandScope");
	addAttributeList(MQIACF_CONNECTION_ATTRS, "ConnectionAttrs");
	addParameterNumFromString(MQIACF_CONN_INFO_TYPE, "ConnInfoType");
	addIntegerFilter();
	addStringFilter();
	addParameterNumFromString(MQIA_UR_DISP, "URDisposition");

	if ( ! _input->has("ConnectionAttrs") )
	{
		// It seems that this is not set by default, so we do
		// it ourselves.
		MQLONG attrs[] = { MQIACF_ALL };
		pcf()->addParameterList(MQIACF_CONNECTION_ATTRS, attrs, 1);
	}

	PCF::Vector commandResponse;
	execute(commandResponse);

	Poco::JSON::Array::Ptr json = new Poco::JSON::Array();
	for(PCF::Vector::iterator it = commandResponse.begin(); it != commandResponse.end(); it++)
	{
		if ( (*it)->getReasonCode() != MQRC_NONE ) // Skip errors (2035 not authorized for example)
			continue;

		if ( (*it)->isExtendedResponse() ) // Skip extended response
			continue;

		json->add(createJSON(**it));
	}

	return json;
}
示例#6
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());
}
示例#7
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));
    }
}
示例#8
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;
}
示例#9
0
 static std::string dump(void)
 {
     Poco::JSON::Array::Ptr deviceObj = new Poco::JSON::Array();
     for (const auto &deviceName : Pothos::PluginRegistry::list("/devices"))
     {
         auto path = Pothos::PluginPath("/devices").join(deviceName).join("info");
         if (not Pothos::PluginRegistry::exists(path)) continue;
         auto plugin = Pothos::PluginRegistry::get(path);
         auto call = plugin.getObject().extract<Pothos::Callable>();
         deviceObj->add(call.call<Poco::JSON::Object::Ptr>());
     }
     std::stringstream ss;
     deviceObj->stringify(ss);
     return ss.str();
 }
示例#10
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;
}
示例#11
0
Poco::JSON::Array::Ptr QueueManagerPing::execute()
{
	PCFCommand::execute();

	Poco::JSON::Array::Ptr json = new Poco::JSON::Array();

	for(PCF::Vector::const_iterator it = begin(); it != end(); it++)
	{
		if ( (*it)->isExtendedResponse() ) // Skip extended response
			continue;

		Poco::JSON::Object::Ptr data = new Poco::JSON::Object();
		json->add(createJSON(**it));
	}

	return json;
}
Poco::JSON::Array::Ptr ChannelAuthenticationRecordInquire::execute()
{
	PCFCommand::execute();

	Poco::JSON::Array::Ptr json = new Poco::JSON::Array();

	for(PCF::Vector::const_iterator it = begin(); it != end(); it++)
	{
		if ( (*it)->getReasonCode() != MQRC_NONE ) // Skip errors (2035 not authorized for example)
			continue;

		if ( (*it)->isExtendedResponse() ) // Skip extended response
			continue;

		json->add(createJSON(**it));
	}

	return json;
}
示例#13
0
Poco::JSON::Array::Ptr ChannelInitiatorMapper::inquire()
{
	createCommand(MQCMD_INQUIRE_CHANNEL_INIT);

	// Optional parameters
	addParameter<std::string>(MQCACF_COMMAND_SCOPE, "CommandScope");

	PCF::Vector commandResponse;
	execute(commandResponse);

	Poco::JSON::Array::Ptr json = new Poco::JSON::Array();
	for(PCF::Vector::iterator it = commandResponse.begin(); it != commandResponse.end(); it++)
	{
		if ( (*it)->isExtendedResponse() ) // Skip extended response
			continue;

		json->add(createJSON(**it));
	}

	return json;
}
示例#14
0
Poco::JSON::Array::Ptr ProcessMapper::inquire()
{
	createCommand(MQCMD_INQUIRE_PROCESS);

	// Required parameters
	addParameter<std::string>(MQCA_PROCESS_NAME, "ProcessName");

	// Optional parameters
	addParameter<std::string>(MQCACF_COMMAND_SCOPE, "CommandScope");
	addIntegerFilter();
	addAttributeList(MQIACF_PROCESS_ATTRS, "ProcessAttrs");
	addParameterNumFromString(MQIA_QSG_DISP, "QSGDisposition");
	addStringFilter();

	PCF::Vector commandResponse;
	execute(commandResponse);

	bool excludeSystem = _input->optValue("ExcludeSystem", false);

	Poco::JSON::Array::Ptr json = new Poco::JSON::Array();
	for(PCF::Vector::iterator it = commandResponse.begin(); it != commandResponse.end(); it++)
	{
		if ( (*it)->getReasonCode() != MQRC_NONE ) // Skip errors (2035 not authorized for example)
			continue;

		if ( (*it)->isExtendedResponse() ) // Skip extended response
			continue;

		std::string processName = (*it)->getParameterString(MQCA_PROCESS_NAME);
		if (   excludeSystem
			&& processName.compare(0, 7, "SYSTEM.") == 0 )
		{
			continue;
		}

		json->add(createJSON(**it));
	}

	return json;
}
示例#15
0
/***********************************************************************
 * Load a JSON block description from file and register the descriptions.
 * return a list of registration paths and a list of paths for blocks.
 **********************************************************************/
static std::vector<Pothos::PluginPath> blockDescParser(std::istream &is, std::vector<Pothos::PluginPath> &blockPaths)
{
    std::vector<Pothos::PluginPath> entries;

    //parse the stream into a JSON array
    const auto result = Poco::JSON::Parser().parse(is);
    Poco::JSON::Array::Ptr arrayOut;
    if (result.type() == typeid(Poco::JSON::Object::Ptr))
    {
        arrayOut = new Poco::JSON::Array();
        arrayOut->add(result.extract<Poco::JSON::Object::Ptr>());
    }
    else arrayOut = result.extract<Poco::JSON::Array::Ptr>();
    for (size_t i = 0; i < arrayOut->size(); i++)
    {
        auto obj = arrayOut->getObject(i);
        assert(obj);
        std::stringstream ossJsonObj;
        obj->stringify(ossJsonObj);
        const std::string JsonObjStr(ossJsonObj.str());

        std::vector<std::string> paths;
        paths.push_back(obj->getValue<std::string>("path"));
        if (obj->has("aliases")) for (const auto &alias : *obj->getArray("aliases"))
        {
            paths.push_back(alias.toString());
        }

        //register the block description for every path
        for (const auto &path : paths)
        {
            const auto pluginPath = Pothos::PluginPath("/blocks/docs", path);
            Pothos::PluginRegistry::add(pluginPath, JsonObjStr);
            entries.push_back(pluginPath);
            blockPaths.push_back(Pothos::PluginPath("/blocks", path));
        }
    }
    return entries;
}
示例#16
0
Poco::JSON::Array::Ptr ChannelStatusMapper::inquire()
{
	createCommand(MQCMD_INQUIRE_CHANNEL_STATUS);

	// Required parameters
	addParameter<std::string>(MQCACH_CHANNEL_NAME, "ChannelName");

	// Optional parameters
	addParameterNumFromString(MQIACH_CHANNEL_DISP, "ChannelDisposition");
	addParameter<std::string>(MQCACH_CLIENT_ID, "ClientIdentifier");
	addAttributeList(MQIACH_CHANNEL_INSTANCE_ATTRS, "ChannelInstanceAttrs");
	addParameterNumFromString(MQIACH_CHANNEL_INSTANCE_TYPE, "ChannelInstanceType");
	addParameter<std::string>(MQCACF_COMMAND_SCOPE, "CommandScope");
	addParameter<std::string>(MQCACH_CONNECTION_NAME, "ConnectionName");
	addIntegerFilter();
	addStringFilter();
	addParameter<std::string>(MQCACH_XMIT_Q_NAME, "XmitQName");

	PCF::Vector commandResponse;
	execute(commandResponse);

	Poco::JSON::Array::Ptr json = new Poco::JSON::Array();

	for(PCF::Vector::iterator it = commandResponse.begin(); it != commandResponse.end(); it++)
	{
		if ( (*it)->isExtendedResponse() ) // Skip Extended Response
			continue;

		if ( (*it)->getReasonCode() != MQRC_NONE ) // Skip errors (2035 not authorized for example)
			continue;

		json->add(createJSON(**it));
	}

	return json;
}
示例#17
0
void AuthorityRecordController::inquire()
{
	if ( qmgr()->zos() )
	{
		// Authority records are not supported on z/OS
		setResponseStatus(Poco::Net::HTTPResponse::HTTP_NOT_IMPLEMENTED, "/authrec/inquire not implemented for z/OS");
		return;
	}

	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 authentication information name and will result in inquiring
		// only that queue and ignores all query parameters.
		if ( parameters.size() > 1 )
		{
			pcfParameters->set("ProfileName", parameters[1]);
		}
		else
		{
			// Handle query parameters
			if ( form().has("ProfileName") )
			{
				pcfParameters->set("ProfileName", form().get("ProfileName"));
			}
		}

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

		Poco::JSON::Array::Ptr jsonOptions = new Poco::JSON::Array();
		pcfParameters->set("Options", jsonOptions);
		for(Poco::Net::NameValueCollection::ConstIterator itOptions = form().find("Options");
			itOptions != form().end() && Poco::icompare(itOptions->first, "Options") == 0;
			++itOptions)
		{
			jsonOptions->add(itOptions->second);
		}

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

	AuthorityRecordInquire command(*commandServer(), pcfParameters);
	setData("data", command.execute());
}
示例#18
0
Poco::JSON::Array::Ptr AuthorityRecordMapper::inquire()
{
	createCommand(MQCMD_INQUIRE_AUTH_RECS);

	// Required parameters
	MQLONG options = 0;
	Poco::JSON::Array::Ptr optionsValue = _input->getArray("Options");
	if ( !optionsValue.isNull() )
	{
		for(Poco::JSON::Array::ValueVec::const_iterator it = optionsValue->begin(); it != optionsValue->end(); ++it)
		{
			std::string value = *it;
			if ( value.compare("Name All Matching") == 0 )
			{
				options |= MQAUTHOPT_NAME_ALL_MATCHING;
			}
			else if ( value.compare("Name Explicit") == 0 )
			{
				options |= MQAUTHOPT_NAME_EXPLICIT;
			}
			else if ( value.compare("Entity Explicit") == 0 )
			{
				options |= MQAUTHOPT_ENTITY_EXPLICIT;
			}
			else if ( value.compare("Entity Set") == 0 )
			{
				options |= MQAUTHOPT_ENTITY_SET;
			}
			else if ( value.compare("Name As Wildcard") == 0 )
			{
				options |= MQAUTHOPT_NAME_AS_WILDCARD;
			}
		}
		pcf()->addParameter(MQIACF_AUTH_OPTIONS, options);
	}
	// When no ProfileName is passed, set to empty string
	if ( !_input->has("ProfileName") ) _input->set("ProfileName", "");
	addParameter<std::string>(MQCACF_AUTH_PROFILE_NAME, "ProfileName");
	addParameterNumFromString(MQIACF_OBJECT_TYPE, "ObjectType");

	// Optional parameters
	addParameter<std::string>(MQCACF_ENTITY_NAME, "EntityName");
	addParameterNumFromString(MQIACF_ENTITY_TYPE, "EntityType");
	addAttributeList(MQIACF_AUTH_PROFILE_ATTRS, "ProfileAttrs");
	addParameter<std::string>(MQCACF_SERVICE_COMPONENT, "ServiceComponent");

	PCF::Vector commandResponse;
	execute(commandResponse);

	Poco::JSON::Array::Ptr json = new Poco::JSON::Array();

	for(PCF::Vector::iterator it = commandResponse.begin(); it != commandResponse.end(); it++)
	{
		if ( (*it)->isExtendedResponse() ) // Skip extended response
			continue;

		if ( (*it)->getReasonCode() != MQRC_NONE ) // Skip errors (2035 not authorized for example)
			continue;

		json->add(createJSON(**it));
	}

	return json;
}
示例#19
0
void Dictionary::mapToJSON(const PCF& pcf, Poco::JSON::Object::Ptr& json, bool alwaysCreate) const
{
	std::vector<MQLONG> parameters = pcf.getParameters();
	for(std::vector<MQLONG>::iterator it = parameters.begin(); it != parameters.end(); ++it)
	{
		std::string name = getName(*it);
		if ( name.empty() )
		{
			if ( alwaysCreate )
			{
				name = "id_" + Poco::NumberFormatter::format(*it);
			}
			else
			{
				continue;
			}
		}

		if ( json->has(name) ) continue; // Don't overwrite already added properties

		Poco::JSON::Object::Ptr field = new Poco::JSON::Object();
		json->set(name, field);

		field->set("id", *it);

		if ( pcf.isNumber(*it) )
		{
			MQLONG value = pcf.getParameterNum(*it);
			field->set("value", value);

			if ( hasDisplayMap(*it) )
			{
				std::string displayValue = getDisplayValue(*it, value);
				if ( displayValue.empty() )
				{
					displayValue = "Unknown value " + Poco::NumberFormatter::format(value) + " for " + Poco::NumberFormatter::format(*it);
				}
				field->set("display", displayValue);
			}
		}
		else if ( pcf.isString(*it) )
		{
			field->set("value", pcf.getParameterString(*it));
		}
		else if ( pcf.isNumberList(*it) )
		{
			std::vector<MQLONG> values = pcf.getParameterNumList(*it);
			Poco::JSON::Array::Ptr jsonValues = new Poco::JSON::Array();
			field->set("value", jsonValues);

			if ( hasDisplayMap(*it) )
			{
				for(std::vector<MQLONG>::iterator vit = values.begin(); vit != values.end(); ++vit)
				{
					Poco::JSON::Object::Ptr jsonValueObject = new Poco::JSON::Object();

					std::string displayValue = getDisplayValue(*it, *vit);
					if ( displayValue.empty() )
					{
						displayValue = "Unknown value " + Poco::NumberFormatter::format(*vit) + " for " + Poco::NumberFormatter::format(*it);
					}
					jsonValueObject->set("value", *vit);
					jsonValueObject->set("display", displayValue);
					jsonValues->add(jsonValueObject);
				}
			}
			else
			{
				for(std::vector<MQLONG>::iterator vit = values.begin(); vit != values.end(); ++vit)
				{
					jsonValues->add(*vit);
				}
			}
		}
		else if ( pcf.isStringList(*it) )
		{
			Poco::JSON::Array::Ptr jsonValues = new Poco::JSON::Array();
			field->set("value", jsonValues);

			std::vector<std::string> strings = pcf.getParameterStringList(*it);
			for(std::vector<std::string>::iterator vit = strings.begin(); vit != strings.end(); ++vit)
			{
				jsonValues->add(*vit);
			}
		}
		else
		{
			poco_assert_dbg(false);
		}
	}
}