Skip to content

Commit 4c513d7

Browse files
committed
Service model integration. Serializing handshake.
1 parent b92b81d commit 4c513d7

File tree

7 files changed

+32
-67
lines changed

7 files changed

+32
-67
lines changed

src/main/java/org/ros/internal/node/client/MasterClient.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ public Response<Integer> unregisterPublisher(PublisherIdentifier publisherIdenti
191191
* the name of the {@link SlaveServer} to lookup
192192
* @return the {@link URI} of the {@link SlaveServer} with the given name
193193
*/
194-
public Response<URI> lookupNode(GraphName slaveName, String nodeName) {
194+
public Response<InetSocketAddress> lookupNode(GraphName slaveName, String nodeName) {
195195
return Response.fromListChecked(rpcEndpoint.lookupNode(slaveName.toString(), nodeName),
196196
new UriResultFactory());
197197
}
@@ -216,7 +216,7 @@ public Response<InetSocketAddress> getUri(GraphName slaveName) {
216216
*/
217217
public Response<InetSocketAddress> lookupService(GraphName callerName, String serviceName) {
218218
return Response.fromListCheckedFailure(
219-
rpcEndpoint.lookupService(callerName.toString(), serviceName), new InetSocketAddressResultFactory());
219+
rpcEndpoint.lookupService(callerName.toString(), serviceName), new UriResultFactory());
220220
}
221221

222222
/**

src/main/java/org/ros/internal/node/client/SlaveClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public List<Object> getBusInfo() {
4444
throw new UnsupportedOperationException();
4545
}
4646

47-
public Response<URI> getMasterUri() {
47+
public Response<InetSocketAddress> getMasterUri() {
4848
return Response.fromListChecked(rpcEndpoint.getMasterUri(nodeName.toString()), new UriResultFactory());
4949
}
5050

src/main/java/org/ros/internal/node/response/UriListResultFactory.java

Lines changed: 10 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,26 @@
1-
/*
2-
* Copyright (C) 2011 Google Inc.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
15-
*/
16-
171
package org.ros.internal.node.response;
182

19-
import java.net.URI;
20-
import java.net.URISyntaxException;
3+
import java.net.InetSocketAddress;
214
import java.util.ArrayList;
225
import java.util.Arrays;
236
import java.util.List;
247

25-
import org.ros.exception.RosRuntimeException;
26-
27-
288
/**
29-
* A {@link ResultFactory} to take an object and turn it into a list of URLIs.
9+
* A {@link ResultFactory} to take an object and turn it into a list of InetSocketAddressess.
3010
*
31-
* @author damonkohler@google.com (Damon Kohler)
11+
* @author Jonathan Groff (C) NeoCoreTechs 2020
3212
*/
33-
public class UriListResultFactory implements ResultFactory<List<URI>> {
13+
public class UriListResultFactory implements ResultFactory<List<InetSocketAddress>> {
3414

3515
@Override
36-
public List<URI> newFromValue(Object value) {
16+
public List<InetSocketAddress> newFromValue(Object value) {
3717
List<Object> values = Arrays.asList((Object[]) value);
38-
List<URI> uris = new ArrayList<URI>();
18+
List<InetSocketAddress> uris = new ArrayList<InetSocketAddress>();
19+
UriResultFactory factory = new UriResultFactory();
3920
for (Object uri : values) {
40-
try {
41-
uris.add(new URI((String) uri));
42-
} catch (URISyntaxException e) {
43-
throw new RosRuntimeException(e);
44-
}
21+
InetSocketAddress socket = factory.newFromValue(uri);
22+
if(socket != null)
23+
uris.add(socket);
4524
}
4625
return uris;
4726
}
Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,22 @@
1-
/*
2-
* Copyright (C) 2011 Google Inc.
3-
*
4-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
5-
* use this file except in compliance with the License. You may obtain a copy of
6-
* the License at
7-
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
10-
* Unless required by applicable law or agreed to in writing, software
11-
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12-
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13-
* License for the specific language governing permissions and limitations under
14-
* the License.
15-
*/
16-
171
package org.ros.internal.node.response;
182

19-
import java.net.URI;
20-
import java.net.URISyntaxException;
21-
22-
import org.ros.exception.RosRuntimeException;
23-
3+
import java.net.InetSocketAddress;
4+
//import java.net.URI;
245
/**
25-
* @author damonkohler@google.com (Damon Kohler)
6+
* @author Jonathan Groff (C) NeocoreTechs 2020
267
*/
27-
public class UriResultFactory implements ResultFactory<URI> {
8+
public class UriResultFactory implements ResultFactory<InetSocketAddress> {
289

2910
@Override
30-
public URI newFromValue(Object value) {
31-
try {
32-
return new URI((String) value);
33-
} catch (URISyntaxException e) {
34-
throw new RosRuntimeException(e);
35-
}
11+
public InetSocketAddress newFromValue(Object value) {
12+
int strt = ((String)value).indexOf("/");
13+
int end = ((String)value).indexOf(":");
14+
if(strt == -1 || end == -1) {
15+
System.out.println("Format of address of descritor incorrect, got "+value+", expected <hostname>/<n.n.n.n:port>");
16+
return null;
17+
}
18+
String host = ((String)value).substring(strt+1, end);
19+
Integer port = Integer.parseInt(((String)value).substring(end+1));
20+
return new InetSocketAddress(host, port);
3621
}
3722
}

src/main/java/org/ros/internal/node/service/ServiceRequestHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private void handleSuccess(final ChannelHandlerContext ctx, ServiceServerRespons
5454
ByteBuffer resbuf = messageBufferPool.acquire();
5555
Utility.serialize(response, resbuf);
5656
try {
57-
ctx.write(resbuf);
57+
ctx.write(resbuf.array());
5858
} catch (IOException e) {
5959
throw new RosRuntimeException(e);
6060
}
@@ -67,7 +67,7 @@ private void handleError(final ChannelHandlerContext ctx, ServiceServerResponse
6767
response.setMessage(encodedMessage);
6868
Utility.serialize(response, responseBuffer);
6969
try {
70-
ctx.write(responseBuffer);
70+
ctx.write(responseBuffer.array());
7171
} catch (IOException e) {
7272
throw new RosRuntimeException(e);
7373
}

src/main/java/org/ros/master/client/MasterStateClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public MasterStateClient(Node caller, InetSocketAddress masterUri) throws IOExce
6262
* @return the {@link URI} of the {@link Node} with the given name
6363
*/
6464
public URI lookupNode(String nodeName) {
65-
Response<URI> response = masterClient.lookupNode(caller.getName(), nodeName);
65+
Response<InetSocketAddress> response = masterClient.lookupNode(caller.getName(), nodeName);
6666
return response.getResult();
6767
}
6868

src/test/java/org/ros/internal/node/MasterSlaveIntegrationTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
import java.io.IOException;
3939
import java.net.InetAddress;
40+
import java.net.InetSocketAddress;
4041
import java.net.URI;
4142
import java.net.UnknownHostException;
4243
import java.util.concurrent.Executors;
@@ -98,7 +99,7 @@ public void tearDown() {
9899

99100
@Test
100101
public void testGetMasterUri() {
101-
Response<URI> response = slaveClient.getMasterUri();
102+
Response<InetSocketAddress> response = slaveClient.getMasterUri();
102103
assertEquals(masterServer.getUri(), response.getResult());
103104
}
104105

0 commit comments

Comments
 (0)