Skip to content

Commit

Permalink
Added NodeConfiguration to ConnectedNode and ComandLineLoader to Node…
Browse files Browse the repository at this point in the history
…Configuration.

Now possible to get command line remappings down into NodeMain from onStart
  • Loading branch information
neocoretechs committed Sep 13, 2015
1 parent 753e16a commit b4d7f38
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/ros/RosRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static void main(String[] argv) throws Exception {
String nodeClassName = loader.getNodeClassName();
System.out.println("Loading node class: " + loader.getNodeClassName());
NodeConfiguration nodeConfiguration = loader.build();
nodeConfiguration.setCommandLineLoader(loader);

NodeMain nodeMain = null;
try {
Expand Down
30 changes: 27 additions & 3 deletions src/main/java/org/ros/internal/loader/CommandLineLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.ros.internal.loader;


import org.ros.CommandLineVariables;
import org.ros.EnvironmentVariables;

Expand Down Expand Up @@ -44,6 +43,14 @@
* environment specification. When starting a node through RosRun, this class is used
* to process the command line remappings.
*
* Remappings ":= on cmdl", get put in 'remappingArguments'. Those that are prefixed with "__" are put
* into the speacialRemappings collection, those without into 'remappings' after taking Graph.nameOf of the remapped args.
* Args on the cmdl without a remapping ":=" get put into nodeArguments.
*
* NOTE: If no constructor is detected during loadClass invocation,
* A node with a static getInstance() returning a type of NodeMain will be invoked. If neither
* an InstantiationException is thrown. This is an enhancement to node creation in original RosJava.
*
* @author [email protected] (Ken Conley)
* @author [email protected] (Damon Kohler)
*/
Expand Down Expand Up @@ -104,11 +111,27 @@ private void parseArgv() {
public String getNodeClassName() {
return nodeClassName;
}

/**
* Return a list of args on the cmdl that are not delimited by special := mapping modifier
* @return
*/
public List<String> getNodeArguments() {
return Collections.unmodifiableList(nodeArguments);
}

/**
* Return cmdl args with := but not __ prefix that have been translated to GraphName.of
* @return
*/
public Map<GraphName, GraphName> getRemappings() {
return Collections.unmodifiableMap(remappings);
}
/**
* Return cmdl args with __ at prefix
* @return
*/
public Map<String, String> getSpecialRemappings() {
return Collections.unmodifiableMap(specialRemappings);
}
/**
* Create NodeConfiguration according to ROS command-line and environment
* specification.
Expand All @@ -124,6 +147,7 @@ public NodeConfiguration build() {
if (specialRemappings.containsKey(CommandLineVariables.NODE_NAME)) {
nodeConfiguration.setNodeName(specialRemappings.get(CommandLineVariables.NODE_NAME));
}
nodeConfiguration.setCommandLineLoader(this);
return nodeConfiguration;
}

Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/ros/internal/node/DefaultNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,11 @@ public InetSocketAddress getUri() {
return slaveServer.getUri();
}


@Override
public NodeConfiguration getNodeConfiguration() {
return nodeConfiguration;
}

@Override
public MessageFactory getTopicMessageFactory() {
return nodeConfiguration.getTopicMessageFactory();
Expand Down Expand Up @@ -554,4 +558,6 @@ public void onError(Node node, Throwable throwable) {
}
});
}


}
2 changes: 2 additions & 0 deletions src/main/java/org/ros/node/ConnectedNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,6 @@ <T, S> ServiceClient<T, S> newServiceClient(String serviceName, String serviceTy
* @return {@link ParameterTree} with {@link NameResolver} in this namespace.
*/
ParameterTree getParameterTree();

NodeConfiguration getNodeConfiguration();
}
18 changes: 16 additions & 2 deletions src/main/java/org/ros/node/NodeConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.ros.node;

import org.ros.internal.loader.CommandLineLoader;
import org.ros.internal.message.definition.MessageDefinitionReflectionProvider;
import org.ros.address.AdvertiseAddress;
import org.ros.address.AdvertiseAddressFactory;
Expand All @@ -38,7 +39,6 @@
import java.io.File;
import java.net.InetSocketAddress;
import java.net.URI;

import java.util.List;
import java.util.concurrent.ScheduledExecutorService;

Expand Down Expand Up @@ -83,8 +83,10 @@ public class NodeConfiguration {
private AdvertiseAddressFactory rpcAdvertiseAddressFactory;
private ScheduledExecutorService scheduledExecutorService;
private TimeProvider timeProvider;
private CommandLineLoader commandLineLoader = null;

/**

/**
* @param nodeConfiguration
* the {@link NodeConfiguration} to copy
* @return a copy of the supplied {@link NodeConfiguration}
Expand All @@ -107,6 +109,7 @@ public static NodeConfiguration copyOf(NodeConfiguration nodeConfiguration) {
copy.rpcAdvertiseAddressFactory = nodeConfiguration.rpcAdvertiseAddressFactory;
copy.scheduledExecutorService = nodeConfiguration.scheduledExecutorService;
copy.timeProvider = nodeConfiguration.timeProvider;
copy.commandLineLoader = nodeConfiguration.commandLineLoader;
return copy;
}

Expand Down Expand Up @@ -200,7 +203,18 @@ public NodeConfiguration setParentResolver(NameResolver resolver) {
public InetSocketAddress getMasterUri() {
return masterUri;
}

/**
*
* @return CommandLineLoader used to initiate node, if used
*/
public CommandLineLoader getCommandLineLoader() {
return commandLineLoader;
}

public void setCommandLineLoader(CommandLineLoader commandLineLoader) {
this.commandLineLoader = commandLineLoader;
}
/**
* @see <a
* href="http://www.ros.org/wiki/ROS/EnvironmentVariables#ROS_MASTER_URI">ROS_MASTER_URI
Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/ros/node/NodeMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ public interface NodeMain extends NodeListener {
* {@link NodeConfiguration}
*/
GraphName getDefaultNodeName();

}

0 comments on commit b4d7f38

Please sign in to comment.