/* * Expected usage: * * rcl_node_t node = rcl_get_zero_initialized_node(); * rcl_node_options_t * node_ops = rcl_node_get_default_options(); * rcl_ret_t ret = rcl_node_init(&node, "node_name", node_ops); * // ... error handling and then use the node, but finally deinitialize it: * ret = rcl_node_fini(&node); * // ... error handling for rcl_node_fini() */ int main(int argc, char ** argv) { rcl_ret_t ret1 = rcl_init(argc, argv, rcl_get_default_allocator()); // std::cout << "ret1: " << ret1 << std::endl; rcl_node_t node_ptr; node_ptr = rcl_get_zero_initialized_node(); const char * name = "ros_test_node_victor"; rcl_node_options_t node_options = rcl_node_get_default_options(); rcl_ret_t ret = rcl_node_init(&node_ptr, name, &node_options); rcl_strings_t node_names; node_names = rcl_get_zero_initialized_strings(); rcl_ret_t ret3 = rcl_get_node_names(&node_names); //std::cout << "ret: " << ret3 << std::endl; for(unsigned int i = 0; i < node_names.count; i++){ std::cout << "->/" << node_names.data[i] << std::endl; } rcl_topic_names_and_types_t topic_names_and_types; topic_names_and_types.topic_count = 0; topic_names_and_types.topic_names = NULL; topic_names_and_types.type_names = NULL; rcl_ret_t result = rcl_get_topic_names_and_types(&node_ptr, &topic_names_and_types); std::cout << "result: " << result << std::endl; for(unsigned int i = 0; i < topic_names_and_types.topic_count; i++){ std::cout << topic_names_and_types.topic_names[i] << std::endl; } }
void SetUp() { stop_memory_checking(); rcl_ret_t ret; ret = rcl_init(0, nullptr, rcl_get_default_allocator()); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); this->node_ptr = new rcl_node_t; *this->node_ptr = rcl_get_zero_initialized_node(); const char * name = "node_name"; rcl_node_options_t node_options = rcl_node_get_default_options(); ret = rcl_node_init(this->node_ptr, name, &node_options); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); set_on_unexpected_malloc_callback([]() {ASSERT_FALSE(true) << "UNEXPECTED MALLOC";}); set_on_unexpected_realloc_callback([]() {ASSERT_FALSE(true) << "UNEXPECTED REALLOC";}); set_on_unexpected_free_callback([]() {ASSERT_FALSE(true) << "UNEXPECTED FREE";}); start_memory_checking(); }
class CLASSNAME (TestSubscriptionFixture, RMW_IMPLEMENTATION) : public ::testing::Test { public: rcl_node_t * node_ptr; void SetUp() { stop_memory_checking(); rcl_ret_t ret; ret = rcl_init(0, nullptr, rcl_get_default_allocator()); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); this->node_ptr = new rcl_node_t; *this->node_ptr = rcl_get_zero_initialized_node(); const char * name = "node_name"; rcl_node_options_t node_options = rcl_node_get_default_options(); ret = rcl_node_init(this->node_ptr, name, &node_options); ASSERT_EQ(RCL_RET_OK, ret) << rcl_get_error_string_safe(); set_on_unexpected_malloc_callback([]() {ASSERT_FALSE(true) << "UNEXPECTED MALLOC";}); set_on_unexpected_realloc_callback([]() {ASSERT_FALSE(true) << "UNEXPECTED REALLOC";}); set_on_unexpected_free_callback([]() {ASSERT_FALSE(true) << "UNEXPECTED FREE";}); start_memory_checking(); }
int main(int argc, char ** argv) { int main_ret = 0; { if (rcl_init(argc, argv, rcl_get_default_allocator()) != RCL_RET_OK) { fprintf(stderr, "Error in rcl init: %s\n", rcl_get_error_string_safe()); return -1; } rcl_node_t node = rcl_get_zero_initialized_node(); const char * name = "node_name"; rcl_node_options_t node_options = rcl_node_get_default_options(); if (rcl_node_init(&node, name, &node_options) != RCL_RET_OK) { fprintf(stderr, "Error in node init: %s\n", rcl_get_error_string_safe()); return -1; } auto node_exit = make_scope_exit([&main_ret, &node]() { if (rcl_node_fini(&node) != RCL_RET_OK) { fprintf(stderr, "Error in node fini: %s\n", rcl_get_error_string_safe()); main_ret = -1; } }); const rosidl_service_type_support_t * ts = ROSIDL_GET_TYPE_SUPPORT( example_interfaces, srv, AddTwoInts); const char * topic = "add_two_ints"; rcl_client_t client = rcl_get_zero_initialized_client(); rcl_client_options_t client_options = rcl_client_get_default_options(); rcl_ret_t ret = rcl_client_init(&client, &node, ts, topic, &client_options); if (ret != RCL_RET_OK) { fprintf(stderr, "Error in client init: %s\n", rcl_get_error_string_safe()); return -1; } auto client_exit = make_scope_exit([&client, &main_ret, &node]() { if (rcl_client_fini(&client, &node)) { fprintf(stderr, "Error in client fini: %s\n", rcl_get_error_string_safe()); main_ret = -1; } }); // Initialize a request. example_interfaces__srv__AddTwoInts_Request client_request; example_interfaces__srv__AddTwoInts_Request__init(&client_request); client_request.a = 1; client_request.b = 2; int64_t sequence_number; if (rcl_send_request(&client, &client_request, &sequence_number)) { fprintf(stderr, "Error in send request: %s\n", rcl_get_error_string_safe()); return -1; } if (sequence_number != 1) { fprintf(stderr, "Got invalid sequence number\n"); return -1; } example_interfaces__srv__AddTwoInts_Request__fini(&client_request); // Initialize the response owned by the client and take the response. example_interfaces__srv__AddTwoInts_Response client_response; example_interfaces__srv__AddTwoInts_Response__init(&client_response); if (!wait_for_client_to_be_ready(&client, 1000, 100)) { fprintf(stderr, "Client never became ready\n"); return -1; } rmw_request_id_t header; if (rcl_take_response(&client, &header, &client_response) != RCL_RET_OK) { fprintf(stderr, "Error in send response: %s\n", rcl_get_error_string_safe()); return -1; } example_interfaces__srv__AddTwoInts_Response__fini(&client_response); } return main_ret; }
int main(int argc, char ** argv) { int main_ret = 0; { if (rcl_init(argc, argv, rcl_get_default_allocator()) != RCL_RET_OK) { fprintf(stderr, "Error in rcl init: %s\n", rcl_get_error_string_safe()); return -1; } rcl_node_t node = rcl_get_zero_initialized_node(); const char * name = "node_name"; rcl_node_options_t node_options = rcl_node_get_default_options(); if (rcl_node_init(&node, name, &node_options) != RCL_RET_OK) { fprintf(stderr, "Error in node init: %s\n", rcl_get_error_string_safe()); return -1; } auto node_exit = make_scope_exit([&main_ret, &node]() { if (rcl_node_fini(&node) != RCL_RET_OK) { fprintf(stderr, "Error in node fini: %s\n", rcl_get_error_string_safe()); main_ret = -1; } }); const rosidl_service_type_support_t * ts = ROSIDL_GET_TYPE_SUPPORT( example_interfaces, srv, AddTwoInts); const char * topic = "add_two_ints"; rcl_service_t service = rcl_get_zero_initialized_service(); rcl_service_options_t service_options = rcl_service_get_default_options(); rcl_ret_t ret = rcl_service_init(&service, &node, ts, topic, &service_options); if (ret != RCL_RET_OK) { fprintf(stderr, "Error in service init: %s\n", rcl_get_error_string_safe()); return -1; } auto service_exit = make_scope_exit([&main_ret, &service, &node]() { if (rcl_service_fini(&service, &node)) { fprintf(stderr, "Error in service fini: %s\n", rcl_get_error_string_safe()); main_ret = -1; } }); std::this_thread::sleep_for(std::chrono::milliseconds(1000)); // Initialize a response. example_interfaces__srv__AddTwoInts_Response service_response; example_interfaces__srv__AddTwoInts_Response__init(&service_response); auto response_exit = make_scope_exit([&service_response]() { example_interfaces__srv__AddTwoInts_Response__fini(&service_response); }); // Block until a client request comes in. if (!wait_for_service_to_be_ready(&service, 1000, 100)) { fprintf(stderr, "Service never became ready\n"); return -1; } // Take the pending request. example_interfaces__srv__AddTwoInts_Request service_request; example_interfaces__srv__AddTwoInts_Request__init(&service_request); auto request_exit = make_scope_exit([&service_request]() { example_interfaces__srv__AddTwoInts_Request__fini(&service_request); }); rmw_request_id_t header; // TODO(jacquelinekay) May have to check for timeout error codes if (rcl_take_request(&service, &header, &service_request) != RCL_RET_OK) { fprintf(stderr, "Error in take_request: %s\n", rcl_get_error_string_safe()); return -1; } // Sum the request and send the response. service_response.sum = service_request.a + service_request.b; if (rcl_send_response(&service, &header, &service_response) != RCL_RET_OK) { fprintf(stderr, "Error in send_response: %s\n", rcl_get_error_string_safe()); return -1; } // Our scope exits should take care of fini for everything } return main_ret; }