Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049 package roboearth.wp5;
00050
00051 import roboearth.wp5.module.ActionRecipeHandler;
00052 import roboearth.wp5.module.BinaryFileHandler;
00053 import roboearth.wp5.module.EnvironmentHandler;
00054 import roboearth.wp5.module.MapExtractorHandler;
00055 import roboearth.wp5.module.ObjectModelHandler;
00056 import ros.NodeHandle;
00057 import ros.Ros;
00058
00066 public class ReCommCore {
00067
00068 public static boolean checkArguments(String[] args) {
00069
00070 boolean ok = true;
00071
00072 boolean showUsage = false;
00073 boolean debug = false;
00074
00075 for (String s : args) {
00076 if (s.startsWith("__")) {
00077 continue;
00078 }
00079
00080 if (s.equalsIgnoreCase("--debug")) {
00081 debug = true;
00082 } else {
00083 showUsage = true;
00084 break;
00085 }
00086 }
00087
00088 if (showUsage) {
00089
00090 System.out.println("\nUsage:\n" +
00091 "re_comm accepts exactly one optional argument, which enables " +
00092 "extensive logging to screen: --debug\n");
00093 ok = false;
00094
00095 } else if (debug) {
00096
00097
00098 java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST);
00099 java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST);
00100 System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
00101 System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
00102 System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
00103 System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
00104 System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug");
00105
00106 System.out.println("\nINFO: Enabled extensive logging to screen.\n");
00107
00108 } else {
00109
00110 System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog");
00111
00112 }
00113
00114 return ok;
00115
00116 }
00117
00118 public static Ros init() {
00119
00120
00121 Ros ros = Ros.getInstance();
00122 ros.init("re_comm_handler");
00123
00124
00125 NodeHandle n = ros.createNodeHandle();
00126
00127
00128 try {
00129
00130 new ObjectModelHandler(ros, n);
00131 new BinaryFileHandler(ros, n);
00132 new ActionRecipeHandler(ros, n);
00133 new EnvironmentHandler(ros, n);
00134 new MapExtractorHandler(ros, n);
00135
00136 } catch (Exception e) {
00137
00138 ros.logFatal("Fatal error occurred. Shutting down!");
00139
00140 if (n != null) {
00141 n.shutdown();
00142 }
00143
00144 e.printStackTrace();
00145 return null;
00146
00147 }
00148
00149 return ros;
00150
00151 }
00152
00157 public static void main(String[] args) {
00158
00159 if (!checkArguments(args)) {
00160 return;
00161 }
00162
00163 Ros ros = init();
00164 if (ros != null) {
00165 ros.spin();
00166 }
00167
00168 }
00169
00170 }