TeleKyb.cpp
Go to the documentation of this file.
00001 /*
00002  * TeleKyb.cpp
00003  *
00004  *  Created on: Oct 17, 2011
00005  *      Author: mriedel
00006  */
00007 
00008 #include <telekyb_base/TeleKyb.hpp>
00009 #include <telekyb_base/Options/RawOptionsContainer.hpp>
00010 #include <telekyb_base/Options/CommonOptions.hpp>
00011 #include <telekyb_base/ROS/ROSOptionController.hpp>
00012 #include <telekyb_base/ROS/ROSModule.hpp>
00013 
00014 #include <telekyb_base/Base/BaseSingleton.hpp>
00015 
00016 #include <ros/init.h>
00017 #include <ros/console.h>
00018 
00019 // boost
00020 #include <boost/lexical_cast.hpp>
00021 
00022 namespace TELEKYB_NAMESPACE {
00023 
00024 bool TeleKyb::initialized = false;
00025 
00026 void TeleKyb::init(int argc, char* argv[], const std::string& name, uint32_t options)
00027 {
00028         // all calls from here on need ros::init.
00029         ros::init(argc, argv, name, options);
00030 
00031         // if we wanted to parse out ros
00032         //std::vector<std::string> commandLineArgs;
00033         //ros::removeROSArgs(argc,argv,commandLineArgs);
00034 
00035         //ros::start();
00036         telekyb::RawOptionsContainer::parseCommandLine(argc, argv, true);
00037         // init Common options.
00038         CommonOptions& co = CommonOptions::Instance();
00039         // set the non-anonymous nodeName.
00040         co.setNodeName(name);
00041 
00042         // read ConfigFile
00043         if (!co.tConfigFile->isOnInitialValue()) {
00044                 telekyb::RawOptionsContainer::parseFile(co.tConfigFile->getValue(), false);
00045         }
00046 
00047         // read CommonOptions again. // only update Initial Values
00048         co.updateFromRawOptions(true);
00049 
00050         // Intital Options are all read
00051 
00052         // print Options?
00053         if (co.tPrintOptions->getValue()) {
00054                 BaseOption::printOptions = true;
00055                 co.printOptions();
00056         }
00057 
00058 
00060         // Create ROSModule Singleton
00061         if (ROSModule::HasInstance()) {
00062                 ROS_FATAL("Trying to create Singleton ROSModule, but it already exits!");
00063                 //ROS_BREAK();
00064                 ros::shutdown();
00065         }
00066 
00067         // we already checked that tRobotID has been set!
00068         ROSModule::Instance();
00069 
00070 
00071         // Create ROSOptionController Singleton
00072         ROSOptionController::Instance();
00073 
00074         // set initalized
00075         initialized = true;
00076 }
00077 
00078 bool TeleKyb::isInitialized()
00079 {
00080         // Initialized.
00081         return initialized;
00082 }
00083 
00084 void TeleKyb::shutdown()
00085 {
00086         //ROSOptionController& oc = ROSOptionController::Instance();
00087         //oc.deleteAllFromParameterServer();
00088 
00089         //Options and Classes with Options have to be shutdown first
00090         CommonOptions::ShutDownInstance();
00091         ROSModule::ShutDownInstance();
00092 
00093         ROSOptionController::ShutDownInstance();
00094 
00095         // delete all Singletons -> above Singletons should be move to new class.
00096         BaseSingleton::deleteAllSingletons();
00097 
00098         initialized = false;
00099 }
00100 
00101 } /* namespace telekyb */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


telekyb_base
Author(s): Dr. Antonio Franchi and Martin Riedel
autogenerated on Mon Nov 11 2013 11:12:34