A toy "database" program for storing and fetching key-values, accessible from a port.
#include <cstdio>
int main(
int argc,
char* argv[])
{
if (argc <= 1) {
printf("This is a very simple database\n");
printf("Call as: %s --name /database\n", argv[0]);
printf("Then you can test it by running:\n");
printf(" yarp rpc /database\n");
printf("And typing things like:\n");
printf(" set x 24\n");
printf(" get x\n");
printf(" get y\n");
printf(" rm x\n");
printf(" get x\n");
printf(" set \"my favorite numbers\" (5 10 16)\n");
printf(" get \"my favorite numbers\"\n");
}
Property option;
option.fromCommand(argc, argv);
Property state;
Port port;
port.open(option.check("name", Value("/database")).asString());
while (true) {
Bottle cmd;
Bottle response;
port.read(cmd, true);
Bottle tmp;
tmp.add(cmd.get(1));
std::string key = tmp.toString();
state.put(key, cmd.get(2));
break;
break;
state.unput(key);
break;
}
Value& v = state.find(key);
response.add(cmd.get(1));
if (!v.isNull()) {
response.add(v);
}
port.reply(response);
}
return 0;
}