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