Ejemplo n.º 1
0
std::string agocontrol::variantListToJSONString(qpid::types::Variant::List list) {
	string result;
	result += "[";
	for (Variant::List::const_iterator it = list.begin(); it != list.end(); ++it) {
		std::string tmpstring;
		switch(it->getType()) {
			case VAR_MAP:
				result += variantMapToJSONString(it->asMap());
				break;
			case VAR_LIST:
				result += variantListToJSONString(it->asList());
				break;
			case VAR_STRING:
				tmpstring = it->asString();
				replaceString(tmpstring, "\"", "\\\"");	
				result += "\"" +  tmpstring + "\"";
				break;
			default:
				if (it->asString().size() != 0) {
					result += it->asString();
				} else {
					result += "null";
				}
		}
		if ((it != list.end()) && (next(it) != list.end())) result += ",";
	}
	result += "]";
	return result;
}
Ejemplo n.º 2
0
void AgentImpl::handleDataIndication(const Variant::List& list, const Message& msg)
{
    Variant::Map::const_iterator aIter;
    const Variant::Map& props(msg.getProperties());
    boost::shared_ptr<SyncContext> context;

    aIter = props.find("qmf.content");
    if (aIter == props.end())
        return;

    string content_type(aIter->second.asString());
    if (content_type != "_event")
        return;

    for (Variant::List::const_iterator lIter = list.begin(); lIter != list.end(); lIter++) {
        const Variant::Map& eventMap(lIter->asMap());
        Data data(new DataImpl(eventMap, this));
        int severity(SEV_NOTICE);
        uint64_t timestamp(0);

        aIter = eventMap.find("_severity");
        if (aIter != eventMap.end())
            severity = int(aIter->second.asInt8());

        aIter = eventMap.find("_timestamp");
        if (aIter != eventMap.end())
            timestamp = aIter->second.asUint64();

        auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_EVENT));
        eventImpl->setAgent(this);
        eventImpl->addData(data);
        eventImpl->setSeverity(severity);
        eventImpl->setTimestamp(timestamp);
        if (data.hasSchema())
            learnSchemaId(data.getSchemaId());
        session.enqueueEvent(eventImpl.release());
    }
}
Ejemplo n.º 3
0
void AgentImpl::handleQueryResponse(const Variant::List& list, const Message& msg)
{
    const string& cid(msg.getCorrelationId());
    Variant::Map::const_iterator aIter;
    const Variant::Map& props(msg.getProperties());
    uint32_t correlator;
    bool final(false);
    boost::shared_ptr<SyncContext> context;

    aIter = props.find("partial");
    if (aIter == props.end())
        final = true;

    aIter = props.find("qmf.content");
    if (aIter == props.end())
        return;

    string content_type(aIter->second.asString());
    if (content_type != "_schema" && content_type != "_schema_id" && content_type != "_data")
        return;

    try { correlator = boost::lexical_cast<uint32_t>(cid); }
    catch(const boost::bad_lexical_cast&) { correlator = 0; }

    {
        qpid::sys::Mutex::ScopedLock l(lock);
        map<uint32_t, boost::shared_ptr<SyncContext> >::iterator iter = contextMap.find(correlator);
        if (iter != contextMap.end())
            context = iter->second;
    }

    if (context.get() != 0) {
        //
        // This response is associated with a synchronous request.
        //
        qpid::sys::Mutex::ScopedLock cl(context->lock);
        if (!context->response.isValid())
            context->response = ConsoleEvent(new ConsoleEventImpl(CONSOLE_QUERY_RESPONSE));

        if (content_type == "_data")
            for (Variant::List::const_iterator lIter = list.begin(); lIter != list.end(); lIter++) {
                Data data(new DataImpl(lIter->asMap(), this));
                ConsoleEventImplAccess::get(context->response).addData(data);
                if (data.hasSchema())
                    learnSchemaId(data.getSchemaId());
            }
        else if (content_type == "_schema_id")
            for (Variant::List::const_iterator lIter = list.begin(); lIter != list.end(); lIter++) {
                SchemaId schemaId(new SchemaIdImpl(lIter->asMap()));
                ConsoleEventImplAccess::get(context->response).addSchemaId(schemaId);
                learnSchemaId(schemaId);
            }
        else if (content_type == "_schema")
            for (Variant::List::const_iterator lIter = list.begin(); lIter != list.end(); lIter++) {
                Schema schema(new SchemaImpl(lIter->asMap()));
                schemaCache->declareSchema(schema);
            }

        if (final) {
            ConsoleEventImplAccess::get(context->response).setFinal();
            ConsoleEventImplAccess::get(context->response).setAgent(this);
            context->cond.notify();
        }
    } else {