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