cdeployer.cpp
Go to the documentation of this file.
00001 /***************************************************************************
00002   tag: Peter Soetens  Thu Jul 3 15:30:32 CEST 2008  cdeployer.cpp
00003 
00004                         cdeployer.cpp -  description
00005                            -------------------
00006     begin                : Thu July 03 2008
00007     copyright            : (C) 2008 Peter Soetens
00008     email                : peter.soetens@fmtc.be
00009 
00010  ***************************************************************************
00011  *   This program is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This program is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this program; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place,                                    *
00024  *   Suite 330, Boston, MA  02111-1307  USA                                *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 
00029 #include <rtt/rtt-config.h>
00030 #ifdef OS_RT_MALLOC
00031 // need access to all TLSF functions embedded in RTT
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;      // "" means use default in DeploymentComponent.cpp
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 after a '--' are passed through to TAO");
00066         // we don't actually list any options for TAO ...
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     // to support RTT's logging to log4cpp
00078     std::string                 rttLog4cppConfigFile;
00079     po::options_description     rttLog4cppOptions = OCL::deployerRttLog4cppOptions(rttLog4cppConfigFile);
00080     otherOptions.add(rttLog4cppOptions);
00081 #endif
00082 
00083     // as last set of options
00084     otherOptions.add(taoOptions);
00085 
00086     // were we given TAO options? ie find "--"
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     // if TAO options not found then process all command line options,
00101     // otherwise process all options up to but not including "--"
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 #if     defined(ORO_BUILD_LOGGING) && defined(OROSEM_LOG4CPP_LOGGING)
00111     if (!OCL::deployerConfigureRttLog4cppCategory(rttLog4cppConfigFile))
00112     {
00113         return -1;
00114     }
00115 #endif
00116 
00117 #ifdef  ORO_BUILD_RTALLOC
00118     size_t                  memSize     = rtallocMemorySize.size;
00119     void*                   rtMem       = 0;
00120     if (0 < memSize)
00121     {
00122         // don't calloc() as is first thing TLSF does.
00123         rtMem = malloc(memSize);
00124         assert(rtMem);
00125         size_t freeMem = init_memory_pool(memSize, rtMem);
00126         if ((size_t)-1 == freeMem)
00127         {
00128             cerr << "Invalid memory pool size of " << memSize
00129                           << " bytes (TLSF has a several kilobyte overhead)." << endl;
00130             free(rtMem);
00131             return -1;
00132         }
00133         cout << "Real-time memory: " << freeMem << " bytes free of "
00134                   << memSize << " allocated." << endl;
00135     }
00136 #endif  // ORO_BUILD_RTALLOC
00137 
00138 #ifdef  ORO_BUILD_LOGGING
00139     log4cpp::HierarchyMaintainer::set_category_factory(
00140         OCL::logging::Category::createOCLCategory);
00141 #endif
00142 
00143     /******************** WARNING ***********************
00144      *   NO log(...) statements before __os_init() !!!!! 
00145      ***************************************************/
00146 
00147     // start Orocos _AFTER_ setting up log4cpp
00148         if (0 == __os_init(argc - taoIndex, &argv[taoIndex]))
00149     {
00150 #ifdef  ORO_BUILD_LOGGING
00151         log(Info) << "OCL factory set for real-time logging" << endlog();
00152 #endif
00153         // scope to force dc destruction prior to memory free
00154         {
00155             OCL::CorbaDeploymentComponent dc( name, siteFile );
00156 
00157             // if TAO options not found then have TAO process just the program name,
00158             // otherwise TAO processes the program name plus all options (potentially
00159             // none) after "--"
00160             TaskContextServer::InitOrb( argc - taoIndex, &argv[taoIndex] );
00161 
00162             if (0 == TaskContextServer::Create( &dc, true, requireNameService ))
00163             {
00164                 return -1;
00165             }
00166 
00167             for (std::vector<std::string>::const_iterator iter=scriptFiles.begin();
00168                  iter!=scriptFiles.end();
00169                  ++iter)
00170             {
00171                 if ( !(*iter).empty() )
00172                 {
00173                     if ( (*iter).rfind(".xml",string::npos) == (*iter).length() - 4 || (*iter).rfind(".cpf",string::npos) == (*iter).length() - 4) {
00174                         dc.kickStart( (*iter) );
00175                         continue;
00176                     } if ( (*iter).rfind(".ops",string::npos) == (*iter).length() - 4 || (*iter).rfind(".osd",string::npos) == (*iter).length() - 4) {
00177                         dc.runScript( (*iter) );
00178                         continue;
00179                     }
00180                     log(Error) << "Unknown extension of file: '"<< (*iter) <<"'. Must be xml, cpf for XML files or, ops or osd for script files."<<endlog();
00181                 }
00182             }
00183 
00184             // Export the DeploymentComponent as CORBA server.
00185             TaskContextServer::RunOrb();
00186 
00187             TaskContextServer::ShutdownOrb();
00188 
00189             TaskContextServer::DestroyOrb();
00190         }
00191 
00192         __os_exit();
00193         }
00194         else
00195         {
00196                 std::cerr << "Unable to start Orocos" << std::endl;
00197         return -1;
00198         }
00199 #ifdef  ORO_BUILD_LOGGING
00200     log4cpp::HierarchyMaintainer::getDefaultMaintainer().shutdown();
00201     log4cpp::HierarchyMaintainer::getDefaultMaintainer().deleteAllCategories();
00202 #endif
00203 
00204 #ifdef  ORO_BUILD_RTALLOC
00205     if (!rtMem)
00206     {
00207         destroy_memory_pool(rtMem);
00208         free(rtMem);
00209     }
00210 #endif  // ORO_BUILD_RTALLOC
00211 
00212     return 0;
00213 }


ocl
Author(s): OCL Development Team
autogenerated on Mon Oct 6 2014 03:16:36