示例#1
0
TEST(MessageManagerSuite, init)
{
  MessageManager manager;
  TestClient client;

  EXPECT_TRUE(manager.init(&client));
  EXPECT_FALSE(manager.init(NULL));

}
int main(int argc, char** argv)
{
  // Initialize ROS node "sm_talker"
  ros::init(argc, argv, "sm_listener");

  // Required to start timers for non-node ROS use.
  ros::Time::init();

  // Little message to know she's started
  ROS_INFO_STREAM("STARTING SM_MANAGER");

  // Create and execute manager
  // * Create a TCP server connection on TCP_PORT (see common.h)
  // * Initialize manager using server connection
  // * Initialize handler using server connection
  // * Add handler to manager
  // * Execute manager spin loop
  TcpServer server;
  server.init(TCP_PORT);

  MessageManager manager;
  MyHandler handler;

  manager.init(&server);

  // Handler initilaized with reply connection (typically the same as
  // incoming connection but now always)
  handler.init(&server);
  manager.add(&handler);
  manager.spin();

  return 0;
}
示例#3
0
TEST(MessageManagerSuite, addHandler)
{
  MessageManager manager;
  TestClient client;
  PingHandler handler;

  EXPECT_EQ(0, (int)manager.getNumHandlers());

  ASSERT_TRUE(manager.init(&client));
  EXPECT_EQ(1, (int)manager.getNumHandlers());
  EXPECT_FALSE(manager.add(NULL));

  ASSERT_TRUE(handler.init(&client));
  EXPECT_FALSE(manager.add(&handler));
}
int main(int argc, char** argv)
{
    char ip[1024] = "192.168.0.50"; // Robot IP address
    TcpClient connection;
    MessageManager manager;

    ros::init(argc, argv, "state_interface");
    ros::NodeHandle n;

    JointRelayHandler jr_handler(n);

    ROS_INFO("Setting up client");
    connection.init(ip, StandardSocketPorts::STATE);
    connection.makeConnect();

    jr_handler.init(&connection);

    manager.init(&connection);
    manager.add(&jr_handler);

    manager.spin();
}
示例#5
0
TEST(DISABLED_MessageManagerSuite, tcp)
{
  const int port = TEST_PORT_BASE + 201;
  char ipAddr[] = "127.0.0.1";

  TestClient* client = new TestClient();
  TestServer server;
  SimpleMessage pingRequest, pingReply;
  MessageManager msgManager;

  // MessageManager uses ros::ok, which needs ros spinner
  ros::AsyncSpinner spinner(0);
  spinner.start();

  ASSERT_TRUE(pingRequest.init(StandardMsgTypes::PING, CommTypes::SERVICE_REQUEST, ReplyTypes::INVALID));

  // TCP Socket testing

  // Construct server
  ASSERT_TRUE(server.init(port));

  // Construct a client
  ASSERT_TRUE(client->init(&ipAddr[0], port));

  // Connect server and client
  pthread_t serverConnectThrd;
  pthread_create(&serverConnectThrd, NULL, connectServerFunc, &server);

  ASSERT_TRUE(client->makeConnect());
  pthread_join(serverConnectThrd, NULL);

  // Listen for client connection, init manager and start thread
  ASSERT_TRUE(msgManager.init(&server));

  // TODO: The message manager is not thread safe (threads are used for testing,
  // but running the message manager in a thread results in errors when the
  // underlying connection is deconstructed before the manager
  //boost::thread spinSrvThrd(boost::bind(&MessageManager::spin, &msgManager));
  pthread_t spinSrvThrd;
  pthread_create(&spinSrvThrd, NULL, spinFunc, &msgManager);

  // Ping the server
  ASSERT_TRUE(client->sendMsg(pingRequest));
  ASSERT_TRUE(client->receiveMsg(pingReply));
  ASSERT_TRUE(client->sendAndReceiveMsg(pingRequest, pingReply));

  // Delete client and try to reconnect

  delete client;
  sleep(10); //Allow time for client to destruct and free up port
  client = new TestClient();

  ASSERT_TRUE(client->init(&ipAddr[0], port));
  ASSERT_TRUE(client->makeConnect());
  ASSERT_TRUE(client->sendAndReceiveMsg(pingRequest, pingReply));

  pthread_cancel(spinSrvThrd);
  pthread_join(spinSrvThrd, NULL);

  delete client;
}