Пример #1
0
DataAddrImpl::DataAddrImpl(const Variant::Map& map) : agentEpoch(0)
{
    Variant::Map::const_iterator iter;

    iter = map.find("_agent_name");
    if (iter != map.end())
        agentName = iter->second.asString();

    iter = map.find("_object_name");
    if (iter != map.end())
        name = iter->second.asString();

    iter = map.find("_agent_epoch");
    if (iter != map.end())
        agentEpoch = (uint32_t) iter->second.asUint64();
}
Пример #2
0
void AgentImpl::handleMethodResponse(const Variant::Map& response, const Message& msg)
{
    const string& cid(msg.getCorrelationId());
    Variant::Map::const_iterator aIter;
    Variant::Map argMap;
    uint32_t correlator;
    boost::shared_ptr<SyncContext> context;

    QPID_LOG(trace, "RCVD MethodResponse cid=" << cid << " map=" << response);

    aIter = response.find("_arguments");
    if (aIter != response.end())
        argMap = aIter->second.asMap();

    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);
        context->response = ConsoleEvent(new ConsoleEventImpl(CONSOLE_METHOD_RESPONSE));
        ConsoleEventImplAccess::get(context->response).setArguments(argMap);
        ConsoleEventImplAccess::get(context->response).setAgent(this);
        context->cond.notify();
    } else {
        //
        // This response is associated with an asynchronous request.
        //
        auto_ptr<ConsoleEventImpl> eventImpl(new ConsoleEventImpl(CONSOLE_METHOD_RESPONSE));
        eventImpl->setCorrelator(correlator);
        eventImpl->setAgent(this);
        eventImpl->setArguments(argMap);
        session.enqueueEvent(eventImpl.release());
    }
}
Пример #3
0
	Variant JSONReader::parse_object()
	{
		if (!skip_char('{'))
			throw Exception(position(), "expected start of object");

		Variant::Map map;

		skip_space();

		while (!skip_char('}'))
		{
			Variant key = parse_string();

			if (map.find(key.as_string()) != map.cend())
				throw Exception(position(), "duplicate key");

			skip_space();
			if (!skip_char(':'))
				throw Exception(position(), "expected :");

			map.emplace(key.as_string(), parse_value());

			skip_space();

			if (skip_char(','))
			{
				skip_space();
				if (at('}'))
					throw Exception(position(), "expected key instead of } after ,");
			}
			else if (!at('}'))
			{
				throw Exception(position(), "expected , or }");
			}
		}

		return Variant(std::move(map));
	}
Пример #4
0
qpid::types::Variant::Map commandHandler(qpid::types::Variant::Map content) {
	qpid::types::Variant::Map returnval;
	std::string internalid = content["internalid"].asString();
	printf("received command  %s for device %s\n", content["command"].asString().c_str(), internalid.c_str());
	qpid::types::Variant::Map::const_iterator it = deviceMap.find(internalid);
	qpid::types::Variant::Map device;
	if (it != deviceMap.end()) {
		device=it->second.asMap();
	} else {
		returnval["result"]=-1;
	}
	Telegram *tg = new Telegram();
	eibaddr_t dest;
	bool handled=true;
	if (content["command"] == "on") {
		string destGA = device["onoff"];
		dest = Telegram::stringtogaddr(destGA);
		if (device["devicetype"]=="drapes") {
			tg->setShortUserData(0);
		} else {
			tg->setShortUserData(1);
		}
	} else if (content["command"] == "off") {
		string destGA = device["onoff"];
		dest = Telegram::stringtogaddr(destGA);
		if (device["devicetype"]=="drapes") {
			tg->setShortUserData(1);
		} else {
			tg->setShortUserData(0);
		}
	} else if (content["command"] == "stop") {
		string destGA = device["stop"];
		dest = Telegram::stringtogaddr(destGA);
		tg->setShortUserData(1);
	} else if (content["command"] == "push") {
		string destGA = device["push"];
		dest = Telegram::stringtogaddr(destGA);
		tg->setShortUserData(0);
	} else if (content["command"] == "setlevel") {
		int level=0;
		string destGA = device["setlevel"];
		dest = Telegram::stringtogaddr(destGA);
		level = atoi(content["level"].asString().c_str());
		tg->setDataFromChar(level);
	} else if (content["command"] == "setcolor") {
		int level=0;
		Telegram *tg2 = new Telegram();
		Telegram *tg3 = new Telegram();
		tg->setDataFromChar(atoi(content["red"].asString().c_str()));
		dest = Telegram::stringtogaddr(device["red"].asString());
		tg2->setDataFromChar(atoi(content["green"].asString().c_str()));
		tg2->setGroupAddress(Telegram::stringtogaddr(device["green"].asString()));
		tg3->setDataFromChar(atoi(content["blue"].asString().c_str()));
		tg3->setGroupAddress(Telegram::stringtogaddr(device["blue"].asString()));
		pthread_mutex_lock (&mutexCon);
		printf("sending telegram\n");
		tg2->sendTo(eibcon);
		printf("sending telegram\n");
		tg3->sendTo(eibcon);
		pthread_mutex_unlock (&mutexCon);

	} else {
		handled=false;
	}
	if (handled) {	
		tg->setGroupAddress(dest);
		printf("sending telegram\n");
		pthread_mutex_lock (&mutexCon);
		bool result = tg->sendTo(eibcon);
		pthread_mutex_unlock (&mutexCon);
		printf("Result: %i\n",result);
		returnval["result"]=result ? 0 : -1;
	} else {
		printf("ERROR, received undhandled command\n");
		returnval["result"]=-1;
	}
	return returnval;
}