Skip to content

Commit b4d7f38

Browse files
committed
Added NodeConfiguration to ConnectedNode and ComandLineLoader to NodeConfiguration.
Now possible to get command line remappings down into NodeMain from onStart
1 parent 753e16a commit b4d7f38

File tree

6 files changed

+54
-6
lines changed

6 files changed

+54
-6
lines changed

src/main/java/org/ros/RosRun.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public static void main(String[] argv) throws Exception {
4949
String nodeClassName = loader.getNodeClassName();
5050
System.out.println("Loading node class: " + loader.getNodeClassName());
5151
NodeConfiguration nodeConfiguration = loader.build();
52+
nodeConfiguration.setCommandLineLoader(loader);
5253

5354
NodeMain nodeMain = null;
5455
try {

src/main/java/org/ros/internal/loader/CommandLineLoader.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
package org.ros.internal.loader;
1818

19-
2019
import org.ros.CommandLineVariables;
2120
import org.ros.EnvironmentVariables;
2221

@@ -44,6 +43,14 @@
4443
* environment specification. When starting a node through RosRun, this class is used
4544
* to process the command line remappings.
4645
*
46+
* Remappings ":= on cmdl", get put in 'remappingArguments'. Those that are prefixed with "__" are put
47+
* into the speacialRemappings collection, those without into 'remappings' after taking Graph.nameOf of the remapped args.
48+
* Args on the cmdl without a remapping ":=" get put into nodeArguments.
49+
*
50+
* NOTE: If no constructor is detected during loadClass invocation,
51+
* A node with a static getInstance() returning a type of NodeMain will be invoked. If neither
52+
* an InstantiationException is thrown. This is an enhancement to node creation in original RosJava.
53+
*
4754
* @author kwc@willowgarage.com (Ken Conley)
4855
* @author damonkohler@google.com (Damon Kohler)
4956
*/
@@ -104,11 +111,27 @@ private void parseArgv() {
104111
public String getNodeClassName() {
105112
return nodeClassName;
106113
}
107-
114+
/**
115+
* Return a list of args on the cmdl that are not delimited by special := mapping modifier
116+
* @return
117+
*/
108118
public List<String> getNodeArguments() {
109119
return Collections.unmodifiableList(nodeArguments);
110120
}
111-
121+
/**
122+
* Return cmdl args with := but not __ prefix that have been translated to GraphName.of
123+
* @return
124+
*/
125+
public Map<GraphName, GraphName> getRemappings() {
126+
return Collections.unmodifiableMap(remappings);
127+
}
128+
/**
129+
* Return cmdl args with __ at prefix
130+
* @return
131+
*/
132+
public Map<String, String> getSpecialRemappings() {
133+
return Collections.unmodifiableMap(specialRemappings);
134+
}
112135
/**
113136
* Create NodeConfiguration according to ROS command-line and environment
114137
* specification.
@@ -124,6 +147,7 @@ public NodeConfiguration build() {
124147
if (specialRemappings.containsKey(CommandLineVariables.NODE_NAME)) {
125148
nodeConfiguration.setNodeName(specialRemappings.get(CommandLineVariables.NODE_NAME));
126149
}
150+
nodeConfiguration.setCommandLineLoader(this);
127151
return nodeConfiguration;
128152
}
129153

src/main/java/org/ros/internal/node/DefaultNode.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,11 @@ public InetSocketAddress getUri() {
427427
return slaveServer.getUri();
428428
}
429429

430-
430+
@Override
431+
public NodeConfiguration getNodeConfiguration() {
432+
return nodeConfiguration;
433+
}
434+
431435
@Override
432436
public MessageFactory getTopicMessageFactory() {
433437
return nodeConfiguration.getTopicMessageFactory();
@@ -554,4 +558,6 @@ public void onError(Node node, Throwable throwable) {
554558
}
555559
});
556560
}
561+
562+
557563
}

src/main/java/org/ros/node/ConnectedNode.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,6 @@ <T, S> ServiceClient<T, S> newServiceClient(String serviceName, String serviceTy
161161
* @return {@link ParameterTree} with {@link NameResolver} in this namespace.
162162
*/
163163
ParameterTree getParameterTree();
164+
165+
NodeConfiguration getNodeConfiguration();
164166
}

src/main/java/org/ros/node/NodeConfiguration.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package org.ros.node;
1818

19+
import org.ros.internal.loader.CommandLineLoader;
1920
import org.ros.internal.message.definition.MessageDefinitionReflectionProvider;
2021
import org.ros.address.AdvertiseAddress;
2122
import org.ros.address.AdvertiseAddressFactory;
@@ -38,7 +39,6 @@
3839
import java.io.File;
3940
import java.net.InetSocketAddress;
4041
import java.net.URI;
41-
4242
import java.util.List;
4343
import java.util.concurrent.ScheduledExecutorService;
4444

@@ -83,8 +83,10 @@ public class NodeConfiguration {
8383
private AdvertiseAddressFactory rpcAdvertiseAddressFactory;
8484
private ScheduledExecutorService scheduledExecutorService;
8585
private TimeProvider timeProvider;
86+
private CommandLineLoader commandLineLoader = null;
8687

87-
/**
88+
89+
/**
8890
* @param nodeConfiguration
8991
* the {@link NodeConfiguration} to copy
9092
* @return a copy of the supplied {@link NodeConfiguration}
@@ -107,6 +109,7 @@ public static NodeConfiguration copyOf(NodeConfiguration nodeConfiguration) {
107109
copy.rpcAdvertiseAddressFactory = nodeConfiguration.rpcAdvertiseAddressFactory;
108110
copy.scheduledExecutorService = nodeConfiguration.scheduledExecutorService;
109111
copy.timeProvider = nodeConfiguration.timeProvider;
112+
copy.commandLineLoader = nodeConfiguration.commandLineLoader;
110113
return copy;
111114
}
112115

@@ -200,7 +203,18 @@ public NodeConfiguration setParentResolver(NameResolver resolver) {
200203
public InetSocketAddress getMasterUri() {
201204
return masterUri;
202205
}
206+
207+
/**
208+
*
209+
* @return CommandLineLoader used to initiate node, if used
210+
*/
211+
public CommandLineLoader getCommandLineLoader() {
212+
return commandLineLoader;
213+
}
203214

215+
public void setCommandLineLoader(CommandLineLoader commandLineLoader) {
216+
this.commandLineLoader = commandLineLoader;
217+
}
204218
/**
205219
* @see <a
206220
* href="http://www.ros.org/wiki/ROS/EnvironmentVariables#ROS_MASTER_URI">ROS_MASTER_URI

src/main/java/org/ros/node/NodeMain.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,5 @@ public interface NodeMain extends NodeListener {
3939
* {@link NodeConfiguration}
4040
*/
4141
GraphName getDefaultNodeName();
42+
4243
}

0 commit comments

Comments
 (0)