00001 import ros.*; 00002 import ros.communication.*; 00003 import ros.pkg.test_rosjava_jni.srv.*; 00004 00005 public class AddTwoIntsServer { 00006 public static void main(String args[]) 00007 throws InterruptedException, RosException { 00008 final Ros ros = Ros.getInstance(); 00009 ros.init("AddTwoIntsServer"); 00010 00011 NodeHandle n = ros.createNodeHandle(); 00012 00013 ServiceServer.Callback<AddTwoInts.Request,AddTwoInts.Response> scb = 00014 new ServiceServer.Callback<AddTwoInts.Request,AddTwoInts.Response>() { 00015 public AddTwoInts.Response call(AddTwoInts.Request request) { 00016 AddTwoInts.Response res = new AddTwoInts.Response(); 00017 res.sum = request.a + request.b; 00018 ros.logInfo("request: x=" + request.a + ", y=" + request.b); 00019 ros.logInfo("sending back response: " + res.sum); 00020 return res; 00021 } 00022 }; 00023 00024 ServiceServer<AddTwoInts.Request,AddTwoInts.Response,AddTwoInts> srv = 00025 n.advertiseService("add_two_ints", new AddTwoInts(), scb); 00026 00027 ros.logInfo("Ready to add two ints."); 00028 00029 n.spin(); 00030 } 00031 }