Example #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("");
}
Example #2
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;
}
Example #3
0
/**
 * 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());
    }
}
Example #4
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("");
}
Example #5
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);
}
Example #6
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());
}
Example #7
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);
	}
}
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;
}