ReconstructMe SDK  2.6.43-0
Real-time 3D reconstruction engine
example_reconstructmesdk_remote_intro.cpp

Content

This is a one minute example showing how to use reme_bag_t, reme_bag_builder_t and reme_remote_t to communicate between two instances of ReconstructMe SDK running on different devices.

Boost is only used to generate examples and is not necessary for working with this SDK.

#include <boost/test/unit_test.hpp>
#include <iostream>
BOOST_AUTO_TEST_SUITE(example_reconstructmesdk)
/*
Process A:
Creates a reme_remote_t service and listens for a request to send greetings.
Once received, it will respond with a greeting.
*/
BOOST_AUTO_TEST_CASE(remote_a)
{
reme_remote_bind(c, r, "tcp://127.0.0.1:50000");
const char *topics[] = { "system/shutdown", "system/greet" };
reme_remote_subscribe(c, r, topics[0]);
reme_remote_subscribe(c, r, topics[1]);
reme_bag_create(c, &bag);
bool done = false;
while (!done) {
int topicIndex = -1;
const char *topicName = 0;
reme_remote_recv(c, r, &topicIndex, &topicName, bag, 1000);
if (topicIndex == 0) {
done = true;
}
if (topicIndex == 1) {
reme_bag_builder_set_string(c, bb, "aString", "Hello World");
reme_bag_builder_set_int(c, bb, "aInt", 10);
reme_remote_send(c, r, "system/greetings", bag);
}
}
}
/*
Process B:
Creates a reme_remote_t and connects to service. Requests a greet and wait for the other
process to respond.
*/
BOOST_AUTO_TEST_CASE(remote_b)
{
reme_remote_connect(c, r, "tcp://127.0.0.1:50000", 10000);
const char *topics[] = { "system/shutdown", "system/greetings" };
reme_remote_subscribe(c, r, topics[0]);
reme_remote_subscribe(c, r, topics[1]);
reme_bag_create(c, &bag);
// Notify just triggers a topic
reme_remote_notify(c, r, "system/greet");
bool done = false;
while (!done) {
int topicIndex = -1;
const char *topicName = 0;
reme_remote_recv(c, r, &topicIndex, &topicName, bag, 1000);
if (topicIndex == 0) {
done = true;
}
if (topicIndex == 1) {
int i;
const char *str = 0;
reme_bag_get_int(c, bag, "aInt", &i);
reme_bag_get_string(c, bag, "aString", &str);
printf("int: %d, string: %s\n", i, str);
reme_remote_notify(c, r, "system/shutdown");
}
}
}
BOOST_AUTO_TEST_SUITE_END()