本文整理汇总了C++中DummyConnector类的典型用法代码示例。如果您正苦于以下问题:C++ DummyConnector类的具体用法?C++ DummyConnector怎么用?C++ DummyConnector使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DummyConnector类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: write
bool Bottle::write(PortReader& reader, bool textMode)
{
DummyConnector con;
con.setTextMode(textMode);
write(con.getWriter());
return reader.read(con.getReader());
}
示例2: add_one
bool add_one() {
printf("\n*** add_one()\n");
ClientPeek client_peek;
Demo client;
client.yarp().attachAsClient(client_peek);
client.add_one(14);
Server server;
Bottle bot("[add] [one] 14");
DummyConnector con;
bot.write(con.getWriter());
server.read(con.getReader());
bot.read(con.getReader());
printf("Result is %s\n", bot.toString().c_str());
if (bot.get(0).asInt() != 15) return false;
bot.fromString("[add] [one] 15");
DummyConnector con2;
bot.write(con2.getWriter());
server.read(con2.getReader());
bot.read(con2.getReader());
printf("Result is %s\n", bot.toString().c_str());
if (bot.get(0).asInt() != 16) return false;
return true;
}
示例3: testEmptyList
void testEmptyList() {
// based on a case submitted by Stephane Lallee; doesn't appear to
// fail here as he sees going from TCL to C++
report(0,"test empty list");
Bottle b;
b.fromString("appp plan-clean (\"<Plan>\" \"<Names>\" cover \"</Names>\" \"<isAtomic>\" 1 \"</isAtomic>\" \"<motorCommand>\" () \"</motorCommand>\" \"<Primitive>\" (cover 28988.470168 \"<args>\" \"7106\" \"7103\" \"</args>\" \"<argsRole>\" object1 arg2 object2 arg1 subject \"7107\" \"</argsRole>\" \"<preReqRelations>\" \"</preReqRelations>\" \"<preForRelations>\" \"</preForRelations>\" \"<postAddRelations>\" \"</postAddRelations>\" \"<postRemRelations>\" \"</postRemRelations>\" \"<addRelations>\" \"</addRelations>\" \"<remRelations>\" visible null arg2 \"</remRelations>\") \"</Primitive>\" \"<SubPlans>\" \"</SubPlans>\" \"</Plan>\")");
Bottle b2 = b;
checkEqual(b2.size(),3,"copy ok level 1");
Bottle *sub = b2.get(2).asList();
checkTrue(sub!=NULL,"list where list expected");
if (sub!=NULL) {
checkEqual(sub->size(),16,"copy ok level 2");
}
DummyConnector con;
con.setTextMode(false);
b.write(con.getWriter());
Bottle b3;
b3.read(con.getReader());
checkEqual(b3.size(),b.size(),"binary read/write ok");
sub = b3.get(2).asList();
checkTrue(sub!=NULL,"list where list expected");
if (sub!=NULL) {
checkEqual(sub->size(),16,"copy ok level 2");
}
}
示例4: write
bool BufferedConnectionWriter::write(PortReader& obj)
{
DummyConnector con;
con.setTextMode(isTextMode());
if (!write(con.getWriter()))
return false;
return obj.read(con.getReader());
}
示例5: read
bool Bottle::read(const PortWriter& writer, bool textMode)
{
implementation->edit();
DummyConnector con;
con.setTextMode(textMode);
writer.write(con.getWriter());
return read(con.getReader());
}
示例6: checkBottle
void checkBottle() {
report(0,"check bottle compatibility...");
Bottle b("2 3 (0.0 1.1 2.2 3.3 4.4 5.5)");
Matrix m(6,1);
DummyConnector con;
b.write(con.getWriter());
m.read(con.getReader());
checkEqual(m.rows(),(size_t) 2,"row size correct");
checkEqual(m.cols(),(size_t) 3,"col size correct");
checkTrue(m[1][2]>5 && m[1][2]<6, "content is sane");
}
示例7: testText
void testText() {
report(0,"checking text mode");
DummyConnector con;
BinPortable<BinPortableTarget> t1, t2;
t1.content().x = 10;
t1.content().y = 20;
t1.write(con.getWriter());
t2.read(con.getReader());
checkEqual(t2.content().x, 10, "x value");
checkEqual(t2.content().y, 20, "y value");
}
示例8: process
bool process() {
produce.wait();
if (!active) return false;
mutex.wait();
Bottle b = msgs.front();
msgs.pop_front();
mutex.post();
DummyConnector con;
b.write(con.getWriter());
owner.read(con.getReader());
mutex.wait();
available_threads++;
mutex.post();
return active;
}
示例9: test_void
bool test_void() {
printf("\n*** test_void()\n");
ClientPeek client_peek;
Demo client;
client.yarp().attachAsClient(client_peek);
client.test_void(14);
client.test_1way(14);
Server server;
Bottle bot("[test] [void] 14");
DummyConnector con;
bot.write(con.getWriter());
server.read(con.getReader());
bot.read(con.getReader());
printf("Result is %s (should be blank)\n", bot.toString().c_str());
return bot.size()==0 && !bot.isNull();
}
示例10:
bool yarp::os::impl::HttpCarrier::write(Protocol& proto, SizedWriter& writer) {
DummyConnector con;
con.setTextMode(true);
for (size_t i=writer.headerLength(); i<writer.length(); i++) {
con.getWriter().appendBlock(writer.data(i),writer.length(i));
}
Bottle b;
b.read(con.getReader());
ConstString body = b.find("web").toString();
if (body.length()!=0) {
ConstString header;
header += NetType::toHexString(body.length()).c_str();
header += "\r\n";
Bytes b2((char*)header.c_str(),header.length());
proto.os().write(b2);
Bytes b3((char*)body.c_str(),body.length());
proto.os().write(b3);
proto.os().write('\r');
proto.os().write('\n');
} else {
ConstString txt = b.toString() + "\r\n";
ConstString header;
header += NetType::toHexString(txt.length()).c_str();
header += "\r\n";
Bytes b2((char*)header.c_str(),header.length());
proto.os().write(b2);
Bytes b3((char*)txt.c_str(),txt.length());
proto.os().write(b3);
proto.os().write('\r');
proto.os().write('\n');
}
proto.os().flush();
return proto.os().isOk();
}
示例11: getNameServerContact
bool YarpNameSpace::writeToNameServer(PortWriter& cmd,
PortReader& reply,
const ContactStyle& style) {
Contact srv = getNameServerContact();
String cmd0 = "NAME_SERVER";
DummyConnector con0;
cmd.write(con0.getWriter());
Bottle in;
in.read(con0.getReader());
for (int i=0; i<in.size(); i++) {
cmd0 += " ";
cmd0 += in.get(i).toString().c_str();
}
NameClient& nic = HELPER(this);
String result = nic.send(cmd0);
Bottle reply2;
reply2.addString(result.c_str());
DummyConnector con;
reply2.write(con.getWriter());
reply.read(con.getReader());
return result!="";
}
示例12: checkPair
void checkPair() {
report(0,"checking portable-pair serialization...");
// potential problem reported by Miguel Sarabia Del Castillo
Matrix m;
size_t rr = 10;
size_t cc = 5;
makeTestMatrix(m,rr,cc);
double value = 3.14;
yarp::os::PortablePair<yarp::sig::Matrix, yarp::os::Value> msg, msg2;
msg.head = m;
msg.body = yarp::os::Value(value);
DummyConnector con;
msg.write(con.getWriter());
ConnectionReader& reader = con.getReader();
msg2.read(reader);
checkEqual(msg.head.rows(),msg2.head.rows(),"matrix row match");
checkEqual(msg.head.cols(),msg2.head.cols(),"matrix col match");
checkEqualish(msg.body.asFloat64(),msg2.body.asFloat64(),"value match");
Bottle bot;
bot.read(msg);
Bottle *bot1 = bot.get(0).asList();
Bottle *bot2 = bot.get(1).asList();
checkTrue(bot1!=nullptr&&bot2!=nullptr,"got head/body");
if (bot1==nullptr || bot2==nullptr) return;
checkEqual((size_t) bot1->get(0).asInt32(),rr,"row count matches");
checkEqual((size_t) bot1->get(1).asInt32(),cc,"column count matches");
Bottle *lst = bot1->get(2).asList();
checkTrue(lst!=nullptr,"have data");
if (!lst) return;
checkEqual(lst->size(),(rr*cc),"data length matches");
checkEqualish(bot2->get(0).asFloat64(),value,"value match");
}
示例13: queryName
bool RosNameSpace::writeToNameServer(PortWriter& cmd,
PortReader& reply,
const ContactStyle& style) {
DummyConnector con0;
cmd.write(con0.getWriter());
Bottle in;
in.read(con0.getReader());
ConstString key = in.get(0).asString();
ConstString arg1 = in.get(1).asString();
Bottle cmd2, cache;
if (key=="query") {
Contact c = queryName(arg1.c_str());
c.setName("");
Bottle reply2;
reply2.addString(arg1.c_str());
reply2.addString(c.toString().c_str());
DummyConnector con;
reply2.write(con.getWriter());
reply.read(con.getReader());
return true;
} else if (key=="list") {
cmd2.addString("getSystemState");
cmd2.addString("dummy_id");
if (!NetworkBase::write(getNameServerContact(), cmd2, cache, style)) {
fprintf(stderr, "Failed to contact ROS server\n");
return false;
}
Bottle out;
out.addVocab(Vocab::encode("many"));
Bottle *parts = cache.get(2).asList();
Property nodes;
Property topics;
Property services;
if (parts) {
for (int i=0; i<3; i++) {
Bottle *part = parts->get(i).asList();
if (!part) continue;
for (int j=0; j<part->size(); j++) {
Bottle *unit = part->get(j).asList();
if (!unit) continue;
ConstString stem = unit->get(0).asString();
Bottle *links = unit->get(1).asList();
if (!links) continue;
if (i<2) {
topics.put(stem, 1);
} else {
services.put(stem, 1);
}
for (int j=0; j<links->size(); j++) {
nodes.put(links->get(j).asString(), 1);
}
}
}
Property *props[3] = {&nodes, &topics, &services};
const char *title[3] = {"node", "topic", "service"};
for (int p=0; p<3; p++) {
Bottle blist;
blist.read(*props[p]);
for (int i=0; i<blist.size(); i++) {
ConstString name = blist.get(i).asList()->get(0).asString();
Bottle& info = out.addList();
info.addString(title[p]);
info.addString(name);
}
}
}
out.write(reply);
return true;
} else {
return false;
}
}
示例14: header
bool yarp::os::impl::HttpCarrier::reply(Protocol& proto, SizedWriter& writer) {
DummyConnector con;
con.setTextMode(true);
for (size_t i=writer.headerLength(); i<writer.length(); i++) {
con.getWriter().appendBlock(writer.data(i),writer.length(i));
}
Bottle b;
b.read(con.getReader());
ConstString mime = b.check("mime",Value("text/html")).asString();
ConstString body;
bool using_json = false;
if (stream!=NULL) {
if (stream->useJson()) {
mime = "text/json";
asJson(body,&b,stream->typeHint());
using_json = true;
}
}
if (b.check("web")&&!using_json) {
body = b.find("web").toString();
}
if (b.check("stream")&&!using_json) {
String header("HTTP/1.1 200 OK\r\nContent-Type: ");
header += mime;
header += "\r\n";
header += "Transfer-Encoding: chunked\r\n";
header += "\r\n";
int N = 2*1024;
header += NetType::toHexString(body.length()+N);
header += "\r\n";
Bytes b2((char*)header.c_str(),header.length());
proto.os().write(b2);
// chrome etc won't render until enough chars are received.
for (int i=0; i<N; i++) {
proto.os().write(' ');
}
Bytes b3((char*)body.c_str(),body.length());
proto.os().write(b3);
proto.os().write('\r');
proto.os().write('\n');
if (stream!=NULL) {
stream->flip();
}
return true;
}
if (stream!=NULL) {
stream->finish();
}
// Could check response codes, mime types here.
if (body.length()!=0 || using_json) {
ConstString mime = b.check("mime",Value("text/html")).asString();
String header("HTTP/1.1 200 OK\nContent-Type: ");
header += mime;
header += "\n";
header += "Access-Control-Allow-Origin: *\n";
header += "\n";
Bytes b2((char*)header.c_str(),header.length());
proto.os().write(b2);
//body = b.toString();
Bytes b3((char*)body.c_str(),body.length());
proto.os().write(b3);
} else {
writer.write(proto.os());
}
proto.os().flush();
return proto.os().isOk();
}