Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
damonkohler committed Mar 6, 2012
2 parents 2cf3920 + 3b7019e commit 92fd915
Show file tree
Hide file tree
Showing 15 changed files with 1,216 additions and 656 deletions.
861 changes: 443 additions & 418 deletions rosjava/src/main/java/org/ros/internal/node/DefaultNode.java

Large diffs are not rendered by default.

396 changes: 225 additions & 171 deletions rosjava/src/main/java/org/ros/internal/node/client/MasterClient.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/*
* Copyright (C) 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package org.ros.internal.node.response;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;

import org.ros.master.client.SystemState;
import org.ros.master.client.TopicSystemState;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;

/**
* A {@link ResultFactory} to take an object and turn it into a
* {@link SystemState} instance.
*
* @author Keith M. Hughes
*/
public class SystemStateResultFactory implements ResultFactory<SystemState> {

@Override
public SystemState newFromValue(Object value) {
Object[] vals = (Object[]) value;

Map<String, Set<String>> publisherMap = getPublishers(vals[0]);
Map<String, Set<String>> subscriberMap = getSubscribers(vals[1]);

Map<String, TopicSystemState> topics = Maps.newHashMap();

for (Entry<String, Set<String>> publisherData : publisherMap.entrySet()) {
String topicName = publisherData.getKey();

Set<String> subscriberNodes = subscriberMap.remove(topicName);

// Return empty lists if no subscribers
if (subscriberNodes == null) {
subscriberNodes = Sets.newHashSet();
}

topics.put(topicName,
new TopicSystemState(topicName, publisherData.getValue(),
subscriberNodes));
}

for (Entry<String, Set<String>> subscriberData : subscriberMap
.entrySet()) {
// At this point there are no publishers with the same topic name
HashSet<String> noPublishers = Sets.newHashSet();
String topicName = subscriberData.getKey();
topics.put(topicName, new TopicSystemState(topicName,
noPublishers, subscriberData.getValue()));
}

// TODO(keith): Get service state in here.

return new SystemState(topics.values());
}

/**
* Extract out the publisher data.
*
* @param pubvals
* the list of lists containing both a topic name and a list of
* publisher nodes for that topic
*
* @return a mapping from topic name to the set of publishers for that topic
*/
private Map<String, Set<String>> getPublishers(Object pubPairs) {
Map<String, Set<String>> topicToPublishers = Maps.newHashMap();

for (Object topicData : Arrays.asList((Object[]) pubPairs)) {
String topicName = (String) ((Object[]) topicData)[0];

Set<String> publishers =Sets.newHashSet();
Object[] publisherData = (Object[])((Object[]) topicData)[1];
for (Object publisher : publisherData) {
publishers.add(publisher.toString());
}

topicToPublishers.put(topicName, publishers);
}

return topicToPublishers;
}

/**
* Extract out the subscriber data.
*
* @param subPairs
* the list of lists containing both a topic name and a list of
* subscriber nodes for that topic
*
* @return a mapping from topic name to the set of subscribers for that
* topic
*/
private Map<String, Set<String>> getSubscribers(Object subPairs) {
Map<String, Set<String>> topicToSubscribers = Maps.newHashMap();

for (Object topicData : Arrays.asList((Object[]) subPairs)) {
String topicName = (String) ((Object[]) topicData)[0];

Set<String> subscribers =Sets.newHashSet();
Object[] subscriberData = (Object[])((Object[]) topicData)[1];
for (Object subscriber : subscriberData) {
subscribers.add(subscriber.toString());
}

topicToSubscribers.put(topicName, subscribers);
}

return topicToSubscribers;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,24 @@
import com.google.common.collect.Lists;

/**
* A {@link ResultFactory} to take an object and turn it into a list of
* {@link TopicDefinition} instances.
*
* @author [email protected] (Damon Kohler)
*/
public class TopicDefinitionListResultFactory implements ResultFactory<List<TopicDefinition>> {
public class TopicDefinitionListResultFactory implements
ResultFactory<List<TopicDefinition>> {

@Override
public List<TopicDefinition> newFromValue(Object value) {
List<TopicDefinition> descriptions = Lists.newArrayList();
List<Object> topics = Arrays.asList((Object[]) value);
for (Object topic : topics) {
String name = (String) ((Object[]) topic)[0];
String type = (String) ((Object[]) topic)[1];
descriptions.add(TopicDefinition.newFromTopicName(new GraphName(name), MessageDefinition
.newFromTypeName(type)));
}
return descriptions;
}
@Override
public List<TopicDefinition> newFromValue(Object value) {
List<TopicDefinition> descriptions = Lists.newArrayList();
List<Object> topics = Arrays.asList((Object[]) value);
for (Object topic : topics) {
String name = (String) ((Object[]) topic)[0];
String type = (String) ((Object[]) topic)[1];
descriptions.add(TopicDefinition.newFromTopicName(new GraphName(
name), MessageDefinition.newFromTypeName(type)));
}
return descriptions;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (C) 2012 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/

package org.ros.internal.node.response;

import java.util.List;

import org.ros.master.client.TopicType;

import com.google.common.collect.Lists;

/**
* A {@link ResultFactory} to take an object and turn it into a list of
* {@link TopicType} instances.
*
* @author Keith M. Hughes
*/
public class TopicTypeListResultFactory implements
ResultFactory<List<TopicType>> {

@Override
public List<TopicType> newFromValue(Object value) {
List<TopicType> topics = Lists.newArrayList();

for (Object pair : (Object[]) value) {
topics.add(new TopicType((String) ((Object[]) pair)[0],
(String) ((Object[]) pair)[1]));
}

return topics;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,23 @@
import com.google.common.collect.Lists;

/**
* A {@link ResultFactory} to take an object and turn it into a list of URLIs.
*
* @author [email protected] (Damon Kohler)
*/
public class UriListResultFactory implements ResultFactory<List<URI>> {

@Override
public List<URI> newFromValue(Object value) {
List<Object> values = Arrays.asList((Object[]) value);
List<URI> uris = Lists.newArrayList();
for (Object uri : values) {
try {
uris.add(new URI((String) uri));
} catch (URISyntaxException e) {
throw new RosRuntimeException(e);
}
}
return uris;
}
@Override
public List<URI> newFromValue(Object value) {
List<Object> values = Arrays.asList((Object[]) value);
List<URI> uris = Lists.newArrayList();
for (Object uri : values) {
try {
uris.add(new URI((String) uri));
} catch (URISyntaxException e) {
throw new RosRuntimeException(e);
}
}
return uris;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

package org.ros.internal.node.server.master;

import com.google.common.collect.Maps;
import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.ros.internal.node.service.ServiceIdentifier;
import org.ros.internal.node.topic.Topic;
import org.ros.master.client.TopicSystemState;
import org.ros.namespace.GraphName;
import org.ros.node.service.ServiceServer;

import java.net.URI;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;
import com.google.common.collect.Maps;

/**
* Manages all registration logic for the {@link MasterServer}.
Expand All @@ -54,7 +54,7 @@ public class MasterRegistrationManagerImpl {
private final Map<GraphName, ServiceRegistrationInfo> services;

/**
* A {@link Map} from {@link Topic} name to the {@link TopicRegistrationInfo}
* A {@link Map} from {@link TopicSystemState} name to the {@link TopicRegistrationInfo}
* about the topic.
*/
private final Map<GraphName, TopicRegistrationInfo> topics;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@

package org.ros.internal.node.server.master;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;
import java.net.URI;
import java.util.Collection;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Expand All @@ -27,23 +28,22 @@
import org.ros.internal.node.server.NodeIdentifier;
import org.ros.internal.node.server.SlaveServer;
import org.ros.internal.node.server.XmlRpcServer;
import org.ros.internal.node.topic.Topic;
import org.ros.internal.node.xmlrpc.MasterXmlRpcEndpointImpl;
import org.ros.master.client.TopicSystemState;
import org.ros.message.Service;
import org.ros.namespace.GraphName;
import org.ros.node.Node;
import org.ros.node.service.ServiceServer;
import org.ros.node.topic.Publisher;
import org.ros.node.topic.Subscriber;

import java.net.URI;
import java.util.Collection;
import java.util.List;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Lists;

/**
* The {@link MasterServer} provides naming and registration services to the
* rest of the {@link Node}s in the ROS system. It tracks {@link Publisher}s and
* {@link Subscriber}s to {@link Topic}s as well as {@link ServiceServer}s. The
* {@link Subscriber}s to {@link TopicSystemState}s as well as {@link ServiceServer}s. The
* role of the {@link MasterServer} is to enable individual ROS {@link Node}s to
* locate one another. Once these {@link Node}s have located each other they
* communicate with each other peer-to-peer.
Expand Down Expand Up @@ -180,15 +180,15 @@ public boolean unregisterSubscriber(GraphName nodeName, URI subscriberSlaveUri,
}

/**
* Register the caller as a {@link Publisher} the {@link Topic}.
* Register the caller as a {@link Publisher} the {@link TopicSystemState}.
*
* @param publisherIdentifier
* identifier for the {@link Publisher}
* @param topicMessageType
* the message type of the {@link Topic}
* the message type of the {@link TopicSystemState}
*
* @return a {@link List} of the current {@link Subscriber}s to the
* {@link Publisher}'s {@link Topic} in the form of XML-RPC
* {@link Publisher}'s {@link TopicSystemState} in the form of XML-RPC
* {@link URI}s for each {@link Subscriber}'s {@link SlaveServer}
*/
public List<URI> registerPublisher(GraphName nodeName, URI nodeSlaveUri, GraphName topicName,
Expand Down Expand Up @@ -298,7 +298,7 @@ public URI lookupNode(GraphName nodeName) {
}

/**
* Get a {@link List} of all {@link Topic} message types.
* Get a {@link List} of all {@link TopicSystemState} message types.
*
* @param calledId
* the {@link Node} name of the caller
Expand Down Expand Up @@ -440,10 +440,10 @@ public URI lookupService(GraphName serviceName) {
* @param caller
* name of the caller
* @param subgraph
* subgraph containing the requested {@link Topic}s, relative to
* subgraph containing the requested {@link TopicSystemState}s, relative to
* caller
* @return a {@link List} of {@link List}s where the nested {@link List}s
* contain, in order, the {@link Topic} name and {@link Topic} message
* contain, in order, the {@link TopicSystemState} name and {@link TopicSystemState} message
* type
*/
public List<Object> getPublishedTopics(GraphName caller, GraphName subgraph) {
Expand Down
Loading

0 comments on commit 92fd915

Please sign in to comment.