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