00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 package ros.roscpp;
00039
00040 import ros.RosException;
00041 import ros.ServiceServer;
00042 import ros.communication.Message;
00043 import ros.communication.Service;
00044
00045 public class CppServiceServer<Q extends Message, A extends Message, S extends Service<Q, A> > implements ServiceServer<Q, A, S> {
00046 private String name;
00047 private long cppCallback;
00048 private long cppServiceServer;
00049
00050 private CppServiceServer() { }
00051
00052 protected static <Q extends Message, A extends Message, S extends Service<Q, A> > CppServiceServer<Q,A,S>
00053 create(long cppHandle, String name, S serviceTemplate, Callback<Q, A> callback) throws RosException {
00054 CppServiceServer<Q, A, S> that = new CppServiceServer<Q, A, S>();
00055 that.name = name;
00056 that.cppCallback = JNI.createSrvCallback(callback, serviceTemplate.getMD5Sum(), serviceTemplate.getDataType(),
00057 serviceTemplate.createRequest(), serviceTemplate.createResponse());
00058 if (that.cppCallback == 0) throw new RuntimeException("Could not create callback wrapper.");
00059 that.cppServiceServer = JNI.advertiseService(cppHandle, name, that.cppCallback);
00060 if (that.cppServiceServer == 0) {
00061 JNI.deleteSrvCallback(that.cppCallback);
00062 throw new RosException("Could not create service server " + name);
00063 }
00064 return that;
00065 }
00066
00067 public String getService() {return name; }
00068
00069 public boolean isValid() { return (cppServiceServer != 0) && JNI.isServiceServerValid(cppServiceServer); }
00070
00071 public void shutdown() {
00072 if (!isValid()) return;
00073 JNI.shutdownServiceServer(cppServiceServer);
00074 JNI.deleteSrvCallback(cppCallback);
00075 cppServiceServer = 0;
00076 }
00077 }