Skip to content

Commit

Permalink
rename Message of service
Browse files Browse the repository at this point in the history
  • Loading branch information
Theosakamg committed Jun 27, 2017
1 parent 078ca01 commit 1e6047b
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 159 deletions.
1 change: 1 addition & 0 deletions rcljava/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/bin/
.classpath
/.settings/
4 changes: 2 additions & 2 deletions rcljava/include/rcljava/org_ros2_rcljava_RCLJava.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,10 @@ JNIEXPORT jobject JNICALL Java_org_ros2_rcljava_RCLJava_nativeTakeResponse
/*
* Class: org_ros2_rcljava_RCLJava
* Method: nativeConvertQoSProfileToHandle
* Signature: (IIII)J
* Signature: (IIIIZ)J
*/
JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_RCLJava_nativeConvertQoSProfileToHandle
(JNIEnv *, jclass, jint, jint, jint, jint);
(JNIEnv *, jclass, jint, jint, jint, jint, jboolean);

/*
* Class: org_ros2_rcljava_RCLJava
Expand Down
2 changes: 1 addition & 1 deletion rcljava/include/rcljava/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ template<typename T>
T *
makeInstance()
{
return (T *)malloc(sizeof(T));
return static_cast<T *>(malloc(sizeof(T)));
}

/*
Expand Down
11 changes: 7 additions & 4 deletions rcljava/src/main/cpp/org_ros2_rcljava_RCLJava.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -486,15 +486,18 @@ JNIEXPORT jlong JNICALL Java_org_ros2_rcljava_RCLJava_nativeConvertQoSProfileToH
jint history,
jint depth,
jint reliability,
jint durability)
jint durability,
jboolean avoid_ros_namespace_conventions)
{
rmw_qos_profile_t * qos_profile =
static_cast<rmw_qos_profile_t *>(malloc(sizeof(rmw_qos_profile_t)));
rmw_qos_profile_t * qos_profile = makeInstance<rmw_qos_profile_t>();

qos_profile->history = static_cast<rmw_qos_history_policy_t>(history);
qos_profile->depth = depth;
qos_profile->reliability = static_cast<rmw_qos_reliability_policy_t>(reliability);
qos_profile->durability = static_cast<rmw_qos_durability_policy_t>(durability);
return reinterpret_cast<jlong>(qos_profile);
qos_profile->avoid_ros_namespace_conventions = avoid_ros_namespace_conventions;

return instance2Handle(qos_profile);
}

JNIEXPORT void JNICALL Java_org_ros2_rcljava_RCLJava_nativeDisposeQoSProfile(
Expand Down
23 changes: 14 additions & 9 deletions rcljava/src/main/java/org/ros2/rcljava/RCLJava.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ public static native Object nativeTakeResponse(
long responseToJavaConverterHandle,
Object responseMessage);
private static native long nativeConvertQoSProfileToHandle(
int history, int depth, int reliability, int durability);
int history, int depth, int reliability, int durability, boolean avoidRos);
private static native void nativeDisposeQoSProfile(
long qosProfileHandle);

Expand Down Expand Up @@ -321,7 +321,7 @@ public static Node createNode(final String namespace, final String defaultName)
*
* @param node
*/
@SuppressWarnings({ "unchecked", "rawtypes", "resource" })
@SuppressWarnings({ "resource", "unchecked" })
public static void spinOnce(final Node node) {
if (!RCLJava.initialized) {
throw new NotInitializedException();
Expand Down Expand Up @@ -363,7 +363,7 @@ public static void spinOnce(final Node node) {
}

for (Client<?> client : node.getClients()) {
NativeClient nativeClient = (NativeClient) client;
NativeClient<?> nativeClient = (NativeClient<?>) client;
RCLJava.nativeWaitSetAddClient(waitSetHandle, nativeClient.getClientHandle());
}

Expand All @@ -372,13 +372,17 @@ public static void spinOnce(final Node node) {
RCLJava.nativeWaitSetFini(waitSetHandle);

// Take all components.
for (Subscription subscription : node.getSubscriptions()) {
NativeSubscription<?> nativeSubscription = (NativeSubscription<?>) subscription;
for (Subscription<? extends Message> subscription : node.getSubscriptions()) {

Subscription<Message> safeSubscription = (Subscription<Message>) subscription;
NativeSubscription<Message> nativeSubscription = (NativeSubscription<Message>) subscription;

Message message = RCLJava.nativeTake(
nativeSubscription.getSubscriptionHandle(),
nativeSubscription.getMessageType());

if (message != null) {
subscription.getCallback().dispatch(message);
safeSubscription.getCallback().dispatch(message);
}
}

Expand All @@ -389,7 +393,7 @@ public static void spinOnce(final Node node) {
}
}

for (Service service : node.getServices()) {
for (@SuppressWarnings("rawtypes") Service service : node.getServices()) {
long requestFromJavaConverterHandle = service.getRequestFromJavaConverterHandle();
long requestToJavaConverterHandle = service.getRequestToJavaConverterHandle();
long responseFromJavaConverterHandle = service.getResponseFromJavaConverterHandle();
Expand Down Expand Up @@ -426,7 +430,7 @@ public static void spinOnce(final Node node) {
}

for (Client<?> client : node.getClients()) {
NativeClient nativeClient = (NativeClient) client;
NativeClient<?> nativeClient = (NativeClient<?>) client;
long responseFromJavaConverterHandle = nativeClient.getResponseFromJavaConverterHandle();
long responseToJavaConverterHandle = nativeClient.getResponseToJavaConverterHandle();

Expand Down Expand Up @@ -620,10 +624,11 @@ public static long convertQoSProfileToHandle(final QoSProfile qosProfile) {
int depth = qosProfile.getDepth();
int reliability = qosProfile.getReliability().getValue();
int durability = qosProfile.getDurability().getValue();
boolean avoidRos = qosProfile.getAvoidRosNamespaceConventions();

RCLJava.logger.debug("Convert QosProfile...");

return RCLJava.nativeConvertQoSProfileToHandle(history, depth, reliability, durability);
return RCLJava.nativeConvertQoSProfileToHandle(history, depth, reliability, durability, avoidRos);
}

/**
Expand Down
29 changes: 17 additions & 12 deletions rcljava/src/main/java/org/ros2/rcljava/node/NativeNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map.Entry;
Expand All @@ -37,6 +36,7 @@
import org.ros2.rcljava.RCLJava;
import org.ros2.rcljava.exception.NotImplementedException;
import org.ros2.rcljava.internal.message.Message;
import org.ros2.rcljava.internal.service.MessageService;
import org.ros2.rcljava.namespace.GraphName;
import org.ros2.rcljava.node.parameter.ParameterCallback;
import org.ros2.rcljava.node.parameter.ParameterService;
Expand Down Expand Up @@ -89,17 +89,17 @@ public class NativeNode implements Node, java.lang.AutoCloseable {
/**
* All the @{link Subscription}s that have been created through this instance.
*/
private final Queue<Subscription<? extends org.ros2.rcljava.internal.message.Message>> subscriptions;
private final Queue<Subscription<? extends Message>> subscriptions;

/**
* All the @{link Publisher}s that have been created through this instance.
*/
private final Queue<Publisher<? extends org.ros2.rcljava.internal.message.Message>> publishers;
private final Queue<Publisher<? extends Message>> publishers;

/**
* All the @{link Service}s that have been created through this instance.
*/
private final Queue<Service<? extends org.ros2.rcljava.internal.service.Service>> services;
private final Queue<Service<? extends MessageService>> services;

/**
* All the @{link Client}s that have been created through this instance.
Expand Down Expand Up @@ -212,7 +212,7 @@ public NativeNode(final long nodeHandle,final String nameSpace, final String nod
this.subscriptions = new LinkedBlockingQueue<Subscription<?>>();
this.publishers = new LinkedBlockingQueue<Publisher<?>>();
this.clients = new LinkedBlockingQueue<Client<?>>();
this.services = new LinkedBlockingQueue<Service<? extends org.ros2.rcljava.internal.service.Service>>();
this.services = new LinkedBlockingQueue<Service<? extends MessageService>>();
this.timers = new LinkedBlockingQueue<WallTimer>();
this.parameters = new HashMap<String, ParameterVariant<?>>();

Expand Down Expand Up @@ -484,7 +484,7 @@ public <T extends org.ros2.rcljava.internal.message.Message> Subscription<T> cre
* @throws NoSuchMethodException
*/
@Override
public <T extends org.ros2.rcljava.internal.service.Service> Client<T> createClient(
public <T extends MessageService> Client<T> createClient(
final Class<T> serviceType,
final String serviceName,
final QoSProfile qosProfile) throws Exception {
Expand Down Expand Up @@ -551,7 +551,7 @@ public <T extends org.ros2.rcljava.internal.service.Service> Client<T> createCli
* @throws Exception
*/
@Override
public <T extends org.ros2.rcljava.internal.service.Service> Client<T> createClient(
public <T extends MessageService> Client<T> createClient(
final Class<T> serviceType,
final String serviceName) throws Exception {
return this.createClient(serviceType, serviceName, QoSProfile.SERVICES_DEFAULT);
Expand All @@ -567,9 +567,8 @@ public <T extends org.ros2.rcljava.internal.service.Service> Client<T> createCli
* @param qos The quality of service profile to pass on to the rmw implementation.
* @return Service instance of the service.
*/
@SuppressWarnings("unchecked")
@Override
public <T extends org.ros2.rcljava.internal.service.Service> Service<T> createService(
public <T extends MessageService> Service<T> createService(
final Class<T> serviceType,
final String serviceName,
final ServiceCallback<?, ?> callback,
Expand All @@ -589,6 +588,7 @@ public <T extends org.ros2.rcljava.internal.service.Service> Service<T> createSe
// long serviceHandle = Node.nativeCreateServiceHandle(this.nodeHandle, message, service, qos);
// Service<T> srv = new Service<T>(this.nodeHandle, serviceHandle, service);

@SuppressWarnings("unchecked")
Class<? extends Message> requestType = (Class<? extends Message>)serviceType.getField("RequestType").get(null);

Method requestFromJavaConverterMethod = requestType.getDeclaredMethod("getFromJavaConverter", (Class<?> []) null);
Expand All @@ -597,6 +597,7 @@ public <T extends org.ros2.rcljava.internal.service.Service> Service<T> createSe
Method requestToJavaConverterMethod = requestType.getDeclaredMethod("getToJavaConverter", (Class<?> []) null);
long requestToJavaConverterHandle = (Long)requestToJavaConverterMethod.invoke(null, (Object []) null);

@SuppressWarnings("unchecked")
Class<? extends Message> responseType = (Class<? extends Message>)serviceType.getField("ResponseType").get(null);

Method responseFromJavaConverterMethod = responseType.getDeclaredMethod("getFromJavaConverter", (Class<?> []) null);
Expand Down Expand Up @@ -635,7 +636,7 @@ public <T extends org.ros2.rcljava.internal.service.Service> Service<T> createSe
* @return Service instance of the service.
*/
@Override
public <T extends org.ros2.rcljava.internal.service.Service> Service<T> createService(
public <T extends MessageService> Service<T> createService(
final Class<T> serviceType,
final String serviceName,
final ServiceCallback<?, ?> callback) throws Exception {
Expand All @@ -647,8 +648,12 @@ public <T extends org.ros2.rcljava.internal.service.Service> Service<T> createSe
public List<SetParametersResult> setParameters(final List<ParameterVariant<?>> parameters) {
List<SetParametersResult> results = new ArrayList<SetParametersResult>();

ArrayList<ParameterVariant<?>> container = new ArrayList<ParameterVariant<?>>(1);
for (ParameterVariant<?> parameterVariantRequest : parameters) {
SetParametersResult result = this.setParametersAtomically(new ArrayList<ParameterVariant<?>>(Arrays.asList(parameterVariantRequest)));
container.clear();
container.add(parameterVariantRequest);

SetParametersResult result = this.setParametersAtomically(container);
results.add(result);
}

Expand Down Expand Up @@ -893,7 +898,7 @@ public final Queue<Client<?>> getClients() {
* @return ArrayList of Services
*/
@Override
public final Queue<Service<? extends org.ros2.rcljava.internal.service.Service>> getServices() {
public final Queue<Service<? extends MessageService>> getServices() {
return this.services;
}

Expand Down
22 changes: 12 additions & 10 deletions rcljava/src/main/java/org/ros2/rcljava/node/Node.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import builtin_interfaces.msg.Time;

import org.ros2.rcljava.Log;
import org.ros2.rcljava.internal.message.Message;
import org.ros2.rcljava.internal.service.MessageService;
import org.ros2.rcljava.node.parameter.ParameterVariant;
import org.ros2.rcljava.node.service.Client;
import org.ros2.rcljava.node.service.Service;
Expand Down Expand Up @@ -64,7 +66,7 @@ public interface Node {
* @param qos The quality of service profile to pass on to the rmw implementation.
* @return Publisher instance of the created publisher.
*/
<T extends org.ros2.rcljava.internal.message.Message> Publisher<T> createPublisher(Class<T> message, String topic, QoSProfile qos);
<T extends Message> Publisher<T> createPublisher(Class<T> message, String topic, QoSProfile qos);

/**
* Create and return a Publisher. (Retro-compatibility)
Expand All @@ -74,7 +76,7 @@ public interface Node {
* @param topic The topic for this publisher to publish on.
* @return Publisher instance of the created publisher.
*/
<T extends org.ros2.rcljava.internal.message.Message> Publisher<T> createPublisher(Class<T> message, String topic);
<T extends Message> Publisher<T> createPublisher(Class<T> message, String topic);

/**
* Create and return a Subscription.
Expand All @@ -86,7 +88,7 @@ public interface Node {
* @param qos The quality of service profile to pass on to the rmw implementation.
* @return Subscription instance of the created subscription.
*/
<T extends org.ros2.rcljava.internal.message.Message> Subscription<T> createSubscription(Class<T> message, String topic, SubscriptionCallback<T> callback, QoSProfile qos);
<T extends Message> Subscription<T> createSubscription(Class<T> message, String topic, SubscriptionCallback<T> callback, QoSProfile qos);

/**
* Create and return a Subscription. (Retro-compatibility)
Expand All @@ -97,7 +99,7 @@ public interface Node {
* @param callback The user-defined callback function.
* @return Subscription instance of the created subscription.
*/
<T extends org.ros2.rcljava.internal.message.Message> Subscription<T> createSubscription(Class<T> message, String topic, SubscriptionCallback<T> callback);
<T extends Message> Subscription<T> createSubscription(Class<T> message, String topic, SubscriptionCallback<T> callback);

/**
* Create and return a Client.
Expand All @@ -108,7 +110,7 @@ public interface Node {
* @param qos The quality of service profile to pass on to the rmw implementation.
* @return Client instance of the service.
*/
<T extends org.ros2.rcljava.internal.service.Service> Client<T> createClient(Class<T> message, String service, QoSProfile qos) throws Exception;
<T extends MessageService> Client<T> createClient(Class<T> message, String service, QoSProfile qos) throws Exception;

/**
* Create and return a Client. (Retro-compatibility)
Expand All @@ -118,7 +120,7 @@ public interface Node {
* @param service The service to subscribe on.
* @return Client instance of the service.
*/
<T extends org.ros2.rcljava.internal.service.Service> Client<T> createClient(Class<T> message, String service) throws Exception ;
<T extends MessageService> Client<T> createClient(Class<T> message, String service) throws Exception ;

/**
* Create and return a Service.
Expand All @@ -130,7 +132,7 @@ public interface Node {
* @param qos The quality of service profile to pass on to the rmw implementation.
* @return Service instance of the service.
*/
<T extends org.ros2.rcljava.internal.service.Service> Service<T> createService(final Class<T> serviceType,
<T extends MessageService> Service<T> createService(final Class<T> serviceType,
final String serviceName,
final ServiceCallback<?, ?> callback,
final QoSProfile qos) throws Exception;
Expand All @@ -144,7 +146,7 @@ <T extends org.ros2.rcljava.internal.service.Service> Service<T> createService(f
* @param callback The user-defined callback function.
* @return Service instance of the service.
*/
<T extends org.ros2.rcljava.internal.service.Service> Service<T> createService(final Class<T> serviceType,
<T extends MessageService> Service<T> createService(final Class<T> serviceType,
final String serviceName,
final ServiceCallback<?, ?> callback) throws Exception;

Expand Down Expand Up @@ -246,13 +248,13 @@ <T extends org.ros2.rcljava.internal.service.Service> Service<T> createService(f
* Get list of Clients.
* @return ArrayList of Clients
*/
Queue<Client<? extends org.ros2.rcljava.internal.service.Service>> getClients();
Queue<Client<? extends MessageService>> getClients();

/**
* Get list of Services.
* @return ArrayList of Services
*/
Queue<Service<? extends org.ros2.rcljava.internal.service.Service>> getServices();
Queue<Service<? extends MessageService>> getServices();

/**
* @return All the @{link WallTimer}s that were created by this instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
import java.util.concurrent.Future;

import org.ros2.rcljava.internal.message.Message;
import org.ros2.rcljava.internal.service.Service;
import org.ros2.rcljava.internal.service.MessageService;

public interface Client<T extends Service> {
public interface Client<T extends MessageService> {

/**
* Query Service.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@
import org.ros2.rcljava.RCLJava;
import org.ros2.rcljava.exception.NotImplementedException;
import org.ros2.rcljava.internal.message.Message;
import org.ros2.rcljava.internal.service.MessageService;
import org.ros2.rcljava.node.Node;

/**
* Service Client.
*
* @param <T> Service Type.
*/
public class NativeClient<T extends org.ros2.rcljava.internal.service.Service>
public class NativeClient<T extends MessageService>
implements Client<T>, java.lang.AutoCloseable {

// Loading JNI library.
Expand Down Expand Up @@ -122,10 +123,10 @@ public final <U extends Message, V extends Message> Future<V> sendRequest(final
}
}

@SuppressWarnings("unchecked")
public final <V extends Message> void handleResponse(final RMWRequestId header,final V response) {
synchronized(pendingRequests) {
long sequenceNumber = header.sequenceNumber;
@SuppressWarnings("unchecked")
RCLFuture<V> future = (RCLFuture<V>) pendingRequests.remove(sequenceNumber);
future.set(response);
}
Expand Down

0 comments on commit 1e6047b

Please sign in to comment.