Exemplo n.º 1
0
bool test_live() {
    printf("\n*** test_live()\n");

    Network yarp;
    yarp.setLocalMode(true);

    Demo client;
    Server server;

    Port client_port,server_port;
    client_port.open("/client");
    server_port.open("/server");
    yarp.connect(client_port.getName(),server_port.getName());

    int x = 0;
    client.yarp().attachAsClient(client_port);
    server.yarp().attachAsServer(server_port);
    x = client.add_one(99);
    printf("Result %d\n", x);
    client.test_void(200);
    client.test_void(201);
    x = client.add_one(100);
    printf("Result %d\n", x);
    client.test_1way(200);
    client.test_1way(201);
    x = client.add_one(101);
    printf("Result %d\n", x);

    return (x==102);
}
Exemplo n.º 2
0
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;
}
Exemplo n.º 3
0
int main(int argc, char *argv[]) {
  Property config;
  config.fromCommand(argc,argv);

  Network yarp;
  Port client_port;

  std::string servername= config.find("server").asString().c_str();
  client_port.open("/demo/client");
  if (!yarp.connect("/demo/client",servername.c_str()))
  {
     std::cout << "Error! Could not connect to server " << servername << std::endl;
     return -1;
  }

  Demo demo;
  demo.yarp().attachAsClient(client_port);

  PointD point;
  point.x = 0;
  point.y = 0;
  point.z = 0;
  PointD offset;
  offset.x = 1;
  offset.y = 2;
  offset.z = 3;

  std::cout << "== get_answer ==" << std::endl;
  int answer=demo.get_answer();
  std::cout << answer << std::endl;

  std::cout<<"== add_one =="<<std::endl;
  answer = demo.add_one(answer);
  std::cout << answer << std::endl;

  std::cout<<"== double_down =="<<std::endl;
  answer = demo.double_down(answer);
  std::cout << answer << std::endl;

  std::cout<<"== add_point =="<<std::endl;
  point = demo.add_point(point,offset);
  std::cout<<("== done! ==\n");

  return 0;
}
Exemplo n.º 4
0
int main(int argc, char *argv[]) {
  Property config;
  config.fromCommand(argc,argv);

  Network yarp;
  Port client_port;

  std::string servername= config.find("server").asString().c_str();
  client_port.open("/demo/client");
  if (!yarp.connect("/demo/client",servername.c_str()))
  {
     std::cout << "Error! Could not connect to server " << servername << std::endl;
     return -1;
  }

  Demo demo;
  demo.yarp().attachAsClient(client_port);
  
  // Let's chat with the server!
  
  std::cout << "Hey are you up and running?" << std::endl;
  while(!demo.is_running())
  {
      std::cout << "No? Well... start!" << std::endl;
      demo.start();
  }
  
  std::cout << "Wonderful! I have a question for you... so, what's the answer??" << std::endl;
  int32_t answer=demo.get_answer();
  std::cout << "What?? " << answer << "?? Are you kidding??";
  answer = demo.add_one(answer);
  std::cout << " It's definitely " << answer << "!!" << std::endl;
  demo.set_answer(answer);
  std::cout << "Got it? So, repeat after me: the answer is ... " << demo.get_answer() << "! Great!" << std::endl;

  std::cout << "Ok you can relax now, I'll leave you alone" << std::endl;
  demo.stop();
  
  std::cout<<"Bye" << std::endl;

  return 0;
}
Exemplo n.º 5
0
int main(int argc, char *argv[]) {
  Property config;
  config.fromCommand(argc,argv);
  Network yarp;
  /* This port will be used to talk to the remote server*/
  Port client_port;
  std::string servername= config.find("server").asString().c_str();
  client_port.open("/demo/client");
  /* connect to server */
  if (!yarp.connect("/demo/client",servername.c_str()))
  {
     std::cout << "Error! Could not connect to server " << servername << std::endl;
     return -1;
  }
  /* Instatate proxy object and attach it to the port -- the proxy will use this port to talk to the server*/
  Demo demo;
  demo.yarp().attachAsClient(client_port);
  /* Now we are ready to chat with the server! */
  /* Notice that from now on we will invoke only the server methods declared in demo.thrift/Demo.h */
  std::cout << "Hey are you up and running?" << std::endl;
  while(!demo.is_running())
  {
      std::cout << "No? Well... start!" << std::endl;
      demo.start();
  }
  std::cout << "Wonderful! I have a question for you... so, what's the answer??" << std::endl;
  int32_t answer=demo.get_answer();
  std::cout << "What?? " << answer << "?? Are you kidding??";
  answer = demo.add_one(answer);
  std::cout << " It's definitely " << answer << "!!" << std::endl;
  demo.set_answer(answer);
  std::cout << "Got it? So, repeat after me: the answer is ... " << demo.get_answer() << "! Great!" << std::endl;
  std::cout << "Ok you can relax now, I'll leave you alone" << std::endl;
  demo.stop();
  std::cout<<"Bye" << std::endl;
  return 0;
}