예제 #1
0
/**
 * looks up the uuid for a specific GA - this is needed to match incoming telegrams to the right device
 */
string uuidFromGA(Variant::Map devicemap, string ga) {
	for (Variant::Map::const_iterator it = devicemap.begin(); it != devicemap.end(); ++it) {
		Variant::Map device;

		device = it->second.asMap();
		for (Variant::Map::const_iterator itd = device.begin(); itd != device.end(); itd++) {
			if (itd->second.asString() == ga) {
				// printf("GA %s belongs to %s\n", itd->second.asString().c_str(), it->first.c_str());
				return(it->first);
			}
		}
	}	
	return("");
}
예제 #2
0
파일: DataAddr.cpp 프로젝트: ChugR/qpid-cpp
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();
}
예제 #3
0
uint32_t encodedSize(const Variant::Map& values)
{
    uint32_t size = 4/*size field*/ + 4/*count field*/;
    for(Variant::Map::const_iterator i = values.begin(); i != values.end(); ++i) {
        size += 1/*size of key*/ + (i->first).size() + 1/*typecode*/ + encodedSize(i->second);
    }
    return size;
}
예제 #4
0
파일: agodmx.cpp 프로젝트: mce35/agocontrol
/**
 * announces our devices in the channelmap to the resolver
 */
void AgoDmx::reportDevices(Variant::Map channelmap) {
    for (Variant::Map::const_iterator it = channelmap.begin(); it != channelmap.end(); ++it) {
        Variant::Map device;

        device = it->second.asMap();
        agoConnection->addDevice(device["internalid"].asString().c_str(), device["devicetype"].asString().c_str());
    }
}
예제 #5
0
/**
 * looks up the type for a specific GA - this is needed to match incoming telegrams to the right event type
 */
string typeFromGA(Variant::Map device, string ga) {
	for (Variant::Map::const_iterator itd = device.begin(); itd != device.end(); itd++) {
		if (itd->second.asString() == ga) {
			// printf("GA %s belongs to %s\n", itd->second.asString().c_str(), itd->first.c_str());
			return(itd->first);
		}
	}
	return("");
}
예제 #6
0
void PnData::write(const Variant::Map& map)
{
    pn_data_put_map(data);
    pn_data_enter(data);
    for (Variant::Map::const_iterator i = map.begin(); i != map.end(); ++i) {
        pn_data_put_string(data, str(i->first));
        write(i->second);
    }
    pn_data_exit(data);
}
예제 #7
0
void encode(const Variant::Map& map, uint32_t len, qpid::framing::Buffer& buffer)
{
    uint32_t s = buffer.getPosition();
    buffer.putLong(len - 4);//exclusive of the size field itself
    buffer.putLong(map.size());
    for (Variant::Map::const_iterator i = map.begin(); i != map.end(); ++i) {
        buffer.putShortString(i->first);
    	encode(i->second, buffer);
    }
    (void) s; assert(s + len == buffer.getPosition());
}
예제 #8
0
/**
 * announces our devices in the devicemap to the resolver
 */
void reportDevices(Variant::Map devicemap) {
	for (Variant::Map::const_iterator it = devicemap.begin(); it != devicemap.end(); ++it) {
		Variant::Map device;
		Variant::Map content;
		Message event;

		// printf("uuid: %s\n", it->first.c_str());
		device = it->second.asMap();
		// printf("devicetype: %s\n", device["devicetype"].asString().c_str());
		agoConnection->addDevice(it->first.c_str(), device["devicetype"].asString().c_str(), true);
	}
}
예제 #9
0
파일: Agent.cpp 프로젝트: ChugR/qpid-cpp
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());
    }
}
예제 #10
0
int
main(int argc, char *argv[])
{
	string broker = "amqp:tcp:127.0.0.1:5672";
	string address;

	static struct option options[] = {
		{"broker", 1, NULL, 'b'},
		{"address", 1, NULL, 'a'},
		{NULL, 0, NULL, 0}
	};

	int c;
	while (1) {
		c = getopt_long(argc, argv, ":b:a:", options, NULL);
		if (-1 == c) break;

		switch (c) {
		case 'b':
			broker = optarg;
			break;
		case 'a':
			address = optarg;
			break;
		case ':':
			cerr << argv[optind - 1] << " requires an argument" << endl;
			usage(argv);
			break;
		case '?':
			cerr << "unknown argument: " << argv[optind - 1] << endl;
			usage(argv);
			break;
		default:
			usage(argv);
			break;
		}
	}

	if (address.empty()) {
		cerr << "--address required" << endl;
		usage(argv);
	}

	cout << "config: address = " << address << "; broker = " << broker << endl;

	Connection connection(broker);
	connection.open();
	Session session = connection.createSession();
	Receiver receiver = session.createReceiver(address);
	receiver.setCapacity(1024);

	int count = 0;
	while (1) {
		Message message = receiver.fetch();
		Variant::Map content;
		decode(message, content);

		string id = message.getSubject();

		if ("DONE" == id) {
			session.acknowledge();
			break;
		}

		for (qpid::types::Variant::Map::const_iterator i = content.begin();
			 content.end() != i;
			 i++) {
			cout << id << " " << (*i).first << " " << (*i).second << endl;
		}
		if (!(++count % 128)) session.acknowledge();
	}
	session.acknowledge();

	receiver.close();
	connection.close();

	return 0;
}
예제 #11
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;
}