Ejemplo n.º 1
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>();
		}
	}
}
Ejemplo n.º 2
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;
}
Ejemplo n.º 3
0
/*!
 * paste only one object type so handlePaste can control the order of creation
 */
static GraphObjectList handlePasteType(GraphDraw *draw, const Poco::JSON::Array::Ptr &graphObjects, const std::string &type)
{
    GraphObjectList newObjects;
    for (size_t objIndex = 0; objIndex < graphObjects->size(); objIndex++)
    {
        const auto jGraphObj = graphObjects->getObject(objIndex);
        const auto what = jGraphObj->getValue<std::string>("what");
        GraphObject *obj = nullptr;
        if (what != type) continue;
        if (what == "Block") obj = new GraphBlock(draw);
        if (what == "Breaker") obj = new GraphBreaker(draw);
        if (what == "Connection") obj = new GraphConnection(draw);
        if (what == "Widget") obj = new GraphWidget(draw);
        if (obj == nullptr) continue;
        try {obj->deserialize(jGraphObj);}
        catch (const Pothos::NotFoundException &)
        {
            delete obj;
            continue;
        }
        obj->setSelected(true);
        newObjects.push_back(obj);
    }
    return newObjects;
}
Ejemplo n.º 4
0
static Poco::AutoPtr<Poco::XML::Element> portInfoToElem(Poco::AutoPtr<Poco::XML::Document> xmlDoc, const Poco::JSON::Array::Ptr &portsInfo, const std::string &prefix)
{
    auto nodeTd = xmlDoc->createElement("td");
    nodeTd->setAttribute("border", "0");
    auto table = xmlDoc->createElement("table");
    nodeTd->appendChild(table);
    table->setAttribute("border", "0");
    table->setAttribute("cellspacing", "0");

    for (size_t i = 0; i < portsInfo->size(); i++)
    {
        const auto portInfo = portsInfo->getObject(i);
        auto name = portInfo->getValue<std::string>("name");
        auto isSigSlot = portInfo->getValue<bool>("isSigSlot");

        auto tr = xmlDoc->createElement("tr");
        table->appendChild(tr);
        auto td = xmlDoc->createElement("td");
        tr->appendChild(td);
        td->setAttribute("border", "1");
        if (prefix == "in"  and isSigSlot)     td->setAttribute("bgcolor", "#AEC6CF");
        if (prefix == "in"  and not isSigSlot) td->setAttribute("bgcolor", "#779ECB");
        if (prefix == "out" and isSigSlot)     td->setAttribute("bgcolor", "#77DD77");
        if (prefix == "out" and not isSigSlot) td->setAttribute("bgcolor", "#03C03C");
        td->setAttribute("port", "__"+prefix+"__"+name);
        unsigned value = 0;
        if (Poco::NumberParser::tryParseUnsigned(name, value)) name = prefix+name;
        td->appendChild(xmlDoc->createTextNode(name));
    }

    return nodeTd;
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
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;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
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());
}
Ejemplo n.º 9
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());
}
Ejemplo n.º 10
0
void save(Archive & ar, const Poco::JSON::Array::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;
}
Ejemplo n.º 11
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;
}
Ejemplo n.º 12
0
void ConnectionController::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 connection id and will result in inquiring
		// only that connection.
		if ( parameters.size() > 1 )
		{
			pcfParameters->set("ConnectionId", parameters[1]);
		}

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

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

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

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

		handleFilterForm(pcfParameters);
	}

	ConnectionMapper mapper(*commandServer(), pcfParameters);
	set("connections", mapper.inquire());
}
Ejemplo n.º 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;
}
Ejemplo n.º 14
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();
 }
Ejemplo n.º 15
0
/***********************************************************************
 * evaluate an args array (calls and constructors)
 **********************************************************************/
static std::vector<Pothos::Proxy> evalArgsArray(
    const Pothos::Proxy &evaluator,
    const Poco::JSON::Array::Ptr &argsArray,
    const size_t offset = 0)
{
    std::vector<Pothos::Proxy> args;
    if (argsArray) for (size_t i = offset; i < argsArray->size(); i++)
    {
        auto arg = argsArray->get(i).toString();
        if (argsArray->get(i).isString()) arg = "\""+arg+"\"";
        const auto obj = evaluator.call<Pothos::Object>("eval", arg);
        args.push_back(evaluator.getEnvironment()->convertObjectToProxy(obj));
    }
    return args;
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
0
/***********************************************************************
 * Helper method for unit tests
 **********************************************************************/
static bool connectionsHave(
    const Poco::JSON::Array::Ptr &connsArray,
    const std::string &srcId, const std::string &srcName,
    const std::string &dstId, const std::string &dstName
)
{
    for (size_t c_i = 0; c_i < connsArray->size(); c_i++)
    {
        const auto connObj = connsArray->getObject(c_i);
        if (connObj->getValue<std::string>("srcId") != srcId) continue;
        if (connObj->getValue<std::string>("srcName") != srcName) continue;
        if (connObj->getValue<std::string>("dstId") != dstId) continue;
        if (connObj->getValue<std::string>("dstName") != dstName) continue;
        return true;
    }
    return false;
}
Ejemplo n.º 18
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;
}
Ejemplo n.º 19
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);
	}
}
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;
}
Ejemplo n.º 21
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));
    }
}
Ejemplo n.º 22
0
void MeetingConnImpl::OnGetRoomUserList(Object::Ptr object)
{
	Var varStatus = object->get("status");
	if(varStatus == 0)
	{
		Var resultObj = object->get("result");
		Poco::JSON::Array::Ptr array =resultObj.extract<Poco::JSON::Array::Ptr>();
		for(Poco::Int32 i = 0; i<array->size();i++)
		{
			Parser parser;
			Var result;
			Var item = array->get(i);
			string strItem = item;
			try
			{

				result = parser.parse(strItem);

			}
			catch(JSONException& jsone)
			{
				std::cout << jsone.message() << std::endl;
				return;
			}

			Object::Ptr tempObj = result.extract<Object::Ptr>();
			Var varSessionID = tempObj->get("sessionID");
			Var varUserName = tempObj->get("userName");
			Var varUserRole = tempObj->get("userRole");
			Var varClientType = tempObj->get("clientType");
			
			string strUserName = varUserName;
			
			uint32_t userRole = varUserRole;
			uint32_t clientType = varClientType;
			uint64_t sessionID= varSessionID;

			MeetingFrameImpl::GetInstance()->On_MeetingEvent_Member_Online(sessionID,(char*)strUserName.data(),"",clientType,userRole);
		}
	}
}
Ejemplo n.º 23
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;
}
Ejemplo n.º 24
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;
}
Ejemplo n.º 25
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;
}
Ejemplo n.º 26
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));
    }
}
Ejemplo n.º 27
0
void parseModesFile() {


    printf("Parse\n"    );

    try {
    //Application& app = Application::instance();
    /*
    [
     { "code":1, "width":640, "height":480, "rate":60, "aspect_ratio":"4:3", "scan":"p", "3d_modes":[] }
    ]
   */


      //std::string conf = std::string(" [ { \"code\":1 ,  \"width\":640, \"height\":480 } ,  { \"code\":3 ,  \"width\":800, \"height\":600 } ]");
      std::string conf =readFileToString("data/modes.json");
      Parser parser;
      Var result = parser.parse(conf);

      Poco::JSON::Array::Ptr arr = result.extract<Poco::JSON::Array::Ptr>();
      for (int i=0;i<arr->size(); i++) {
          Object::Ptr object = arr->getObject(i);
          printf("w,h=%d,%d\n",object->getValue<int>("width"),object->getValue<int>("height"));
      }

      Query myQuery(result);

      //Var topic=myQuery.find("code");
      //int value = topic.convert<int>();
      //printf("Value=%d\n",value);
    } catch (...)
    {
        printf("Exception\n");

    }

}
Ejemplo n.º 28
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;
}
Ejemplo n.º 29
0
/***********************************************************************
 * Strip top and bottom whitespace from a document array
 **********************************************************************/
static Poco::JSON::Array::Ptr stripDocArray(const Poco::JSON::Array::Ptr &in)
{
    Poco::JSON::Array::Ptr out(new Poco::JSON::Array());

    for (size_t i = 0; i < in->size(); i++)
    {
        //dont add empty lines if the last line is empty
        const auto line = in->getElement<std::string>(i);
        std::string lastLine;
        if (out->size() != 0) lastLine = out->getElement<std::string>(out->size()-1);
        if (not lastLine.empty() or not line.empty()) out->add(line);
    }

    //remove trailing empty line from docs
    if (out->size() != 0 and out->getElement<std::string>(out->size()-1).empty())
    {
        out->remove(out->size()-1);
    }

    return out;
}
Ejemplo n.º 30
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());
}