RobotNameResolver.java
Go to the documentation of this file.
00001 package com.github.rosjava.android_apps.application_management;
00002 
00003 import android.util.Log;
00004 
00005 import org.ros.master.client.MasterStateClient;
00006 import org.ros.master.client.SystemState;
00007 import org.ros.master.client.TopicSystemState;
00008 import org.ros.namespace.GraphName;
00009 import org.ros.namespace.NameResolver;
00010 import org.ros.node.AbstractNodeMain;
00011 import org.ros.node.ConnectedNode;
00012 import org.ros.exception.RosRuntimeException;
00013 
00014 public class RobotNameResolver extends AbstractNodeMain {
00015 
00016         private RobotDescription currentRobot;
00017         private NameResolver applicationNamespaceResolver;
00018         private NameResolver robotNameResolver;
00019         private GraphName name;
00020         private GraphName applicationNamespace;
00021         private ConnectedNode connectedNode;
00022     private boolean resolved = false;
00023 
00024         public RobotNameResolver() {
00025         }
00026 
00027         public void setRobot(RobotDescription currentRobot) {
00028                 this.currentRobot = currentRobot;
00029         }
00030 
00031         @Override
00032         public GraphName getDefaultNodeName() {
00033                 return null;
00034         }
00035 
00036         public void setRobotName(String name) {
00037                 this.name = GraphName.of(name);
00038         }
00039         
00040         public void resetRobotName(String name) {
00041                 robotNameResolver = connectedNode.getResolver().newChild(name);
00042         }
00043 
00044 
00045         public NameResolver getAppNameSpace() {
00046                 return applicationNamespaceResolver;
00047         }
00048 
00049     public NameResolver getRobotNameSpace() {
00050                 return robotNameResolver;
00051         }
00052 
00060     public void waitForResolver() {
00061         while (!resolved) {
00062             try {
00063                 Thread.sleep(100);
00064             } catch (Exception e) {
00065                 Log.w("RobotRemocon", "robot name waitForResolver caught an arbitrary exception");
00066             }
00067         }
00068     }
00069 
00070         @Override
00081         public void onStart(final ConnectedNode connectedNode) {
00082                 this.connectedNode = connectedNode;
00083         if (currentRobot != null) {
00084             name = GraphName.of(currentRobot.getRobotName());
00085         } else {
00086             // This is duplicated in PlatformInfoServiceClient and could be better stored somewhere, but it's not much.
00087             MasterStateClient masterClient = new MasterStateClient(this.connectedNode, this.connectedNode.getMasterUri());
00088             SystemState systemState = masterClient.getSystemState();
00089             for (TopicSystemState topic : systemState.getTopics()) {
00090                 String name = topic.getTopicName();
00091                 GraphName graph_name = GraphName.of(name);
00092                 if ( graph_name.getBasename().toString().equals("app_list") ) {
00093                     this.name = graph_name.getParent().toRelative();
00094                     Log.i("ApplicationManagement", "configuring a robot namespace resolver [" + this.name + "]");
00095                     break;
00096                 }
00097             }
00098         }
00099         applicationNamespace = name.join(GraphName.of("application"));  // hard coded, might we need to change this?
00100         applicationNamespaceResolver = connectedNode.getResolver().newChild(applicationNamespace);
00101         robotNameResolver = connectedNode.getResolver().newChild(name);
00102         resolved = true;
00103         }
00104 }


android_apps
Author(s): Daniel Stonier , Kazuto Murase
autogenerated on Fri Aug 28 2015 10:04:40