ReCommCore.java
Go to the documentation of this file.
00001 /* \file ReCommCore.java
00002  * \brief Main class for the re_comm_core package
00003  *
00004  * The main class for the re_comm_core package.
00005  * 
00006  * This file is part of the RoboEarth ROS re_comm_core package.
00007  * 
00008  * It was originally created for <a href="http://www.roboearth.org/">RoboEarth</a>.
00009  * The research leading to these results has received funding from the 
00010  * European Union Seventh Framework Programme FP7/2007-2013 
00011  * under grant agreement no248942 RoboEarth.
00012  *
00013  * Copyright (C) 2010 by 
00014  * <a href=" mailto:perzylo@cs.tum.edu">Alexander Perzylo</a>
00015  * Technische Universitaet Muenchen
00016  * 
00017  * Redistribution and use in source and binary forms, with or without
00018  * modification, are permitted provided that the following conditions are met:
00019  * 
00020  *    <UL>
00021  *     <LI> Redistributions of source code must retain the above copyright
00022  *       notice, this list of conditions and the following disclaimer.
00023  *     <LI> Redistributions in binary form must reproduce the above copyright
00024  *       notice, this list of conditions and the following disclaimer in the
00025  *       documentation and/or other materials provided with the distribution.
00026  *     <LI> Neither the name of Willow Garage, Inc. nor the names of its
00027  *       contributors may be used to endorse or promote products derived from
00028  *       this software without specific prior written permission.
00029  *    </UL>
00030  * 
00031  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00032  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00033  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00034  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00035  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00036  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00037  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00038  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00039  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00040  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00041  * POSSIBILITY OF SUCH DAMAGE.
00042  *
00043  * \author Alexander Perzylo
00044  * \version 1.0
00045  * \date 2010
00046  * \image html http://www.roboearth.org/sites/default/files/RoboEarth.org_logo.gif
00047  * \image latex http://www.roboearth.org/sites/default/files/RoboEarth.org_logo.gif
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("__")) { // ignore arguments added by roslaunch
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                         // Setting log level for HttpClient
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                 // Initialize rosjava 
00121                 Ros ros = Ros.getInstance();
00122                 ros.init("re_comm_handler");
00123 
00124                 // Create a NodeHandle
00125                 NodeHandle n = ros.createNodeHandle();
00126 
00127                 // Load modules providing specific functionalities 
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 }


re_comm_core
Author(s): Alexander Perzylo
autogenerated on Sun Jan 5 2014 11:29:33