forked from rosjava/rosjava_core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
1,216 additions
and
656 deletions.
There are no files selected for viewing
861 changes: 443 additions & 418 deletions
861
rosjava/src/main/java/org/ros/internal/node/DefaultNode.java
Large diffs are not rendered by default.
Oops, something went wrong.
396 changes: 225 additions & 171 deletions
396
rosjava/src/main/java/org/ros/internal/node/client/MasterClient.java
Large diffs are not rendered by default.
Oops, something went wrong.
131 changes: 131 additions & 0 deletions
131
rosjava/src/main/java/org/ros/internal/node/response/SystemStateResultFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
rosjava/src/main/java/org/ros/internal/node/response/TopicTypeListResultFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.