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 #include <rtt/rtt-config.h>
00029 #ifdef OS_RT_MALLOC
00030
00031 #define ORO_MEMORY_POOL
00032 #include <rtt/os/tlsf/tlsf.h>
00033 #endif
00034 #include <rtt/os/main.h>
00035 #include <rtt/RTT.hpp>
00036
00037 #include <taskbrowser/TaskBrowser.hpp>
00038 #include <deployment/CorbaDeploymentComponent.hpp>
00039 #include <rtt/transports/corba/TaskContextServer.hpp>
00040 #include <iostream>
00041 #include "deployer-funcs.hpp"
00042
00043 #include <rtt/transports/corba/corba.h>
00044
00045 #ifdef ORO_BUILD_LOGGING
00046 # ifndef OS_RT_MALLOC
00047 # warning "Logging needs rtalloc!"
00048 # endif
00049 #include <log4cpp/HierarchyMaintainer.hh>
00050 #include "logging/Category.hpp"
00051 #endif
00052
00053 using namespace std;
00054 using namespace RTT;
00055 using namespace RTT::corba;
00056 namespace po = boost::program_options;
00057
00058 int main(int argc, char** argv)
00059 {
00060 std::string siteFile;
00061 std::vector<std::string> scriptFiles;
00062 std::string name("Deployer");
00063 bool requireNameService = false;
00064 po::variables_map vm;
00065 po::options_description taoOptions("Additional options can also be passed to TAO");
00066
00067
00068 po::options_description otherOptions;
00069
00070 #ifdef ORO_BUILD_RTALLOC
00071 OCL::memorySize rtallocMemorySize = ORO_DEFAULT_RTALLOC_SIZE;
00072 po::options_description rtallocOptions = OCL::deployerRtallocOptions(rtallocMemorySize);
00073 otherOptions.add(rtallocOptions);
00074 #endif
00075
00076 #if defined(ORO_BUILD_LOGGING) && defined(OROSEM_LOG4CPP_LOGGING)
00077
00078 std::string rttLog4cppConfigFile;
00079 po::options_description rttLog4cppOptions = OCL::deployerRttLog4cppOptions(rttLog4cppConfigFile);
00080 otherOptions.add(rttLog4cppOptions);
00081 #endif
00082
00083
00084 otherOptions.add(taoOptions);
00085
00086
00087 int taoIndex = 0;
00088 bool found = false;
00089
00090 while(!found && taoIndex<argc)
00091 {
00092 found = (0 == strcmp("--", argv[taoIndex]));
00093 if(!found) taoIndex++;
00094 }
00095
00096 if (found) {
00097 argv[taoIndex] = argv[0];
00098 }
00099
00100
00101
00102 int rc = OCL::deployerParseCmdLine(!found ? argc : taoIndex, argv,
00103 siteFile, scriptFiles, name, requireNameService,
00104 vm, &otherOptions);
00105 if (0 != rc)
00106 {
00107 return rc;
00108 }
00109
00110
00111 #if defined(ORO_BUILD_LOGGING) && defined(OROSEM_LOG4CPP_LOGGING)
00112 if (!OCL::deployerConfigureRttLog4cppCategory(rttLog4cppConfigFile))
00113 {
00114 return -1;
00115 }
00116 #endif
00117
00118 #ifdef ORO_BUILD_RTALLOC
00119 size_t memSize = rtallocMemorySize.size;
00120 void* rtMem = 0;
00121 if (0 < memSize)
00122 {
00123
00124 rtMem = malloc(memSize);
00125 assert(rtMem);
00126 size_t freeMem = init_memory_pool(memSize, rtMem);
00127 if ((size_t)-1 == freeMem)
00128 {
00129 cerr << "Invalid memory pool size of " << memSize
00130 << " bytes (TLSF has a several kilobyte overhead)." << endl;
00131 free(rtMem);
00132 return -1;
00133 }
00134 cout << "Real-time memory: " << freeMem << " bytes free of "
00135 << memSize << " allocated." << endl;
00136 }
00137 #endif // ORO_BUILD_RTALLOC
00138
00139 #ifdef ORO_BUILD_LOGGING
00140
00141 log4cpp::HierarchyMaintainer::set_category_factory(
00142 OCL::logging::Category::createOCLCategory);
00143 #endif
00144
00145
00146 if (0 == __os_init(argc - taoIndex, &argv[taoIndex]))
00147 {
00148 #ifdef ORO_BUILD_LOGGING
00149 log(Info) << "OCL factory set for real-time logging" << endlog();
00150 #endif
00151 rc = -1;
00152 try {
00153
00154
00155
00156 TaskContextServer::InitOrb( argc - taoIndex, &argv[taoIndex] );
00157
00158 OCL::CorbaDeploymentComponent dc( name, siteFile );
00159
00160 if (0 == TaskContextServer::Create( &dc, true, requireNameService ))
00161 {
00162 return -1;
00163 }
00164
00165
00166 TaskContextServer::ThreadOrb();
00167
00168
00169 for (std::vector<std::string>::const_iterator iter=scriptFiles.begin();
00170 iter!=scriptFiles.end();
00171 ++iter)
00172 {
00173 if ( !(*iter).empty() )
00174 {
00175 if ( (*iter).rfind(".xml",string::npos) == (*iter).length() - 4 || (*iter).rfind(".cpf",string::npos) == (*iter).length() - 4) {
00176 dc.kickStart( (*iter) );
00177 continue;
00178 } if ( (*iter).rfind(".ops",string::npos) == (*iter).length() - 4 || (*iter).rfind(".osd",string::npos) == (*iter).length() - 4) {
00179 dc.runScript( (*iter) );
00180 continue;
00181 }
00182 log(Error) << "Unknown extension of file: '"<< (*iter) <<"'. Must be xml, cpf for XML files or, ops or osd for script files."<<endlog();
00183 }
00184 }
00185
00186 if ( !vm.count("daemon") ) {
00187 OCL::TaskBrowser tb( &dc );
00188 tb.loop();
00189
00190
00191 dc.shutdownDeployment();
00192 }
00193
00194 TaskContextServer::ShutdownOrb();
00195
00196 TaskContextServer::DestroyOrb();
00197
00198 rc = 0;
00199
00200 } catch( CORBA::Exception &e ) {
00201 log(Error) << argv[0] <<" ORO_main : CORBA exception raised!" << Logger::nl;
00202 log() << CORBA_EXCEPTION_INFO(e) << endlog();
00203 } catch (...) {
00204
00205 log(Error) << "Uncaught exception." << endlog();
00206 }
00207
00208
00209 __os_exit();
00210 }
00211 else
00212 {
00213 std::cerr << "Unable to start Orocos" << std::endl;
00214 rc = -1;
00215 }
00216
00217 #ifdef ORO_BUILD_RTALLOC
00218 if (!rtMem)
00219 {
00220 destroy_memory_pool(rtMem);
00221 free(rtMem);
00222 }
00223 #endif // ORO_BUILD_RTALLOC
00224
00225 return rc;
00226 }