#include <ros/ros.h>
#include <service_client_pkg/ServiceClientExMsg.h>
#include <iostream>
#include <string>
using namespace std;
bool infoinquiry(service_client_pkg::ServiceClientExMsgRequest&request,service_client_pkg::ServiceClientExMsgResponse& response)
{
ROS_INFO("callback activated");
string input_name(request.name);
response.in_class=false;
if(input_name.compare("Tom") == 0)
{
ROS_INFO("Student information about Tom");
response.in_class=true;
response.boy=true;
response.age=20;
response.personality="outgoing";
}
if(input_name.compare("Mary") == 0)
{
ROS_INFO("Student information about Mary");
response.in_class=true;
response.boy=false;
response.age=21;
response.personality="introverted";
}
return true;
}
int main(int argc,char ** argv)
{
ros::init(argc,argv,"service_example_node");
ros::NodeHandle n;
ros::ServiceServer service =n.advertiseService("info_inquiry_byname", infoinquiry);
ROS_INFO("Ready to inquiry names.");
ros::spin();
return 0;
}
add_executable(service_example_node src/service_example_node.cpp)
add_dependencies(service_example_node
${${PROJECT_NAME}_EXPORTED_TARGETS}
${catkin_EXPORTED_TARGETS})
target_link_libraries(service_example_node ${catkin_LIBRARIES})