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 if (!dc.loadComponents( (*iter) )) {
00183 result = false;
00184 log(Error) << "Failed to load file: '"<< (*iter) <<"'." << endlog();
00185 } else if (!dc.configureComponents()) {
00186 result = false;
00187 log(Error) << "Failed to configure file: '"<< (*iter) <<"'." << endlog();
00188 }
00189
00190 } else {
00191 result = dc.kickStart( (*iter) );
00192 }
00193 continue;
00194 }
00195
00196 if ( (*iter).rfind(".ops",std::string::npos) == (*iter).length() - 4 ||
00197 (*iter).rfind(".osd",std::string::npos) == (*iter).length() - 4 ||
00198 (*iter).rfind(".lua",std::string::npos) == (*iter).length() - 4) {
00199 result = dc.runScript( (*iter) ) && result;
00200 continue;
00201 }
00202 log(Error) << "Unknown extension of file: '"<< (*iter) <<"'. Must be xml, cpf for XML files or, ops, osd or lua for script files."<<endlog();
00203 }
00204 }
00205 rc = (result ? 0 : -1);
00206 #ifdef USE_TASKBROWSER
00207
00208 if ( !deploymentOnlyChecked && !vm.count("daemon") ) {
00209 OCL::TaskBrowser tb( &dc );
00210
00211 tb.loop();
00212
00213 dc.shutdownDeployment();
00214 }
00215 #endif
00216 }
00217 #ifdef ORO_BUILD_RTALLOC
00218 if (0 != rtMem)
00219 {
00220
00221 log(Debug) << "TLSF bytes allocated=" << memSize
00222 << " overhead=" << (memSize - freeMem)
00223 << " max-used=" << get_max_size(rtMem)
00224 << " currently-used=" << get_used_size(rtMem)
00225 << " still-allocated=" << (get_used_size(rtMem) - (memSize - freeMem))
00226 << endlog();
00227 }
00228 #endif
00229
00230 __os_exit();
00231 }
00232 else
00233 {
00234 std::cerr << "Unable to start Orocos" << std::endl;
00235 rc = -1;
00236 }
00237
00238 #ifdef ORO_BUILD_LOGGING
00239 log4cpp::HierarchyMaintainer::getDefaultMaintainer().shutdown();
00240 log4cpp::HierarchyMaintainer::getDefaultMaintainer().deleteAllCategories();
00241 #endif
00242
00243 #ifdef ORO_BUILD_RTALLOC
00244 if (0 != rtMem)
00245 {
00246 std::cout << "TLSF bytes allocated=" << memSize
00247 << " overhead=" << (memSize - freeMem)
00248 << " max-used=" << get_max_size(rtMem)
00249 << " currently-used=" << get_used_size(rtMem)
00250 << " still-allocated=" << (get_used_size(rtMem) - (memSize - freeMem))
00251 << "\n";
00252
00253 destroy_memory_pool(rtMem);
00254 free(rtMem);
00255 }
00256 #endif
00257
00258 return rc;
00259 }