cdeployer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Jul 3 15:30:32 CEST 2008 cdeployer.cpp
3 
4  cdeployer.cpp - description
5  -------------------
6  begin : Thu July 03 2008
7  copyright : (C) 2008 Peter Soetens
8  email : peter.soetens@fmtc.be
9 
10  ***************************************************************************
11  * This program is free software; you can redistribute it and/or *
12  * modify it under the terms of the GNU Lesser General Public *
13  * License as published by the Free Software Foundation; either *
14  * version 2.1 of the License, or (at your option) any later version. *
15  * *
16  * This program is distributed in the hope that it will be useful, *
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
19  * Lesser General Public License for more details. *
20  * *
21  * You should have received a copy of the GNU Lesser General Public *
22  * License along with this program; if not, write to the Free Software *
23  * Foundation, Inc., 59 Temple Place, *
24  * Suite 330, Boston, MA 02111-1307 USA *
25  ***************************************************************************/
26 
27 #include <rtt/rtt-config.h>
28 #ifdef OS_RT_MALLOC
29 // need access to all TLSF functions embedded in RTT
30 #define ORO_MEMORY_POOL
31 #include <rtt/os/tlsf/tlsf.h>
32 #endif
33 #include <rtt/os/main.h>
34 #include <rtt/RTT.hpp>
35 #include <rtt/Logger.hpp>
36 
39 #include <iostream>
40 #include <string>
41 #include "deployer-funcs.hpp"
42 
43 #ifdef ORO_BUILD_LOGGING
44 # ifndef OS_RT_MALLOC
45 # warning "Logging needs rtalloc!"
46 # endif
48 #include "logging/Category.hpp"
49 #endif
50 
51 using namespace RTT;
52 using namespace RTT::corba;
53 namespace po = boost::program_options;
54 
55 int main(int argc, char** argv)
56 {
57  std::string siteFile; // "" means use default in DeploymentComponent.cpp
58  std::vector<std::string> scriptFiles;
59  std::string name("Deployer");
60  bool requireNameService = false;
61  bool deploymentOnlyChecked = false;
62  int minNumberCPU = 0;
63  po::variables_map vm;
64  po::options_description taoOptions("Additional options after a '--' are passed through to TAO");
65  // we don't actually list any options for TAO ...
66 
67  po::options_description otherOptions;
68 
69 #ifdef ORO_BUILD_RTALLOC
70  OCL::memorySize rtallocMemorySize = ORO_DEFAULT_RTALLOC_SIZE;
71  po::options_description rtallocOptions = OCL::deployerRtallocOptions(rtallocMemorySize);
72  otherOptions.add(rtallocOptions);
73  OCL::TLSFMemoryPool memoryPool;
74 #endif
75 
76 #if defined(ORO_BUILD_LOGGING) && defined(OROSEM_LOG4CPP_LOGGING)
77  // to support RTT's logging to log4cpp
78  std::string rttLog4cppConfigFile;
79  po::options_description rttLog4cppOptions = OCL::deployerRttLog4cppOptions(rttLog4cppConfigFile);
80  otherOptions.add(rttLog4cppOptions);
81 #endif
82 
83  // as last set of options
84  otherOptions.add(taoOptions);
85 
86  // were we given non-deployer options? ie find "--"
87  int optIndex = 0;
88  bool found = false;
89 
90  while(!found && optIndex<argc)
91  {
92  found = (0 == strcmp("--", argv[optIndex]));
93  if(!found) optIndex++;
94  }
95 
96  if (found) {
97  argv[optIndex] = argv[0];
98  }
99 
100  // if extra options not found then process all command line options,
101  // otherwise process all options up to but not including "--"
102  int rc = OCL::deployerParseCmdLine(!found ? argc : optIndex, argv,
103  siteFile, scriptFiles, name, requireNameService, deploymentOnlyChecked,
104  minNumberCPU,
105  vm, &otherOptions);
106  if (0 != rc)
107  {
108  return rc;
109  }
110 
111  // check system capabilities
112  rc = OCL::enforceMinNumberCPU(minNumberCPU);
113  if (0 != rc)
114  {
115  return rc;
116  }
117 
118 #if defined(ORO_BUILD_LOGGING) && defined(OROSEM_LOG4CPP_LOGGING)
119  if (!OCL::deployerConfigureRttLog4cppCategory(rttLog4cppConfigFile))
120  {
121  return -1;
122  }
123 #endif
124 
125 #ifdef ORO_BUILD_RTALLOC
126  if (!memoryPool.initialize(rtallocMemorySize.size))
127  {
128  return -1;
129  }
130 #endif // ORO_BUILD_RTALLOC
131 
132 #ifdef ORO_BUILD_LOGGING
133  // use our log4cpp-derived categories to do real-time logging
136 #endif
137 
138  /******************** WARNING ***********************
139  * NO log(...) statements before __os_init() !!!!!
140  ***************************************************/
141 
142  // start Orocos _AFTER_ setting up log4cpp
143  if (0 == __os_init(argc - optIndex, &argv[optIndex]))
144  {
145 #ifdef ORO_BUILD_LOGGING
146  log(Info) << "OCL factory set for real-time logging" << endlog();
147 #endif
148  rc = -1; // prove otherwise
149  try {
150  // if TAO options not found then have TAO process just the program name,
151  // otherwise TAO processes the program name plus all options (potentially
152  // none) after "--"
153  TaskContextServer::InitOrb( argc - optIndex, &argv[optIndex] );
154 
155  // scope to force dc destruction prior to memory free and Orb shutdown
156  {
157  OCL::CorbaDeploymentComponent dc( name, siteFile );
158 
159  if (0 == TaskContextServer::Create( &dc, true, requireNameService ))
160  {
161  return -1;
162  }
163 
164  /* Only start the scripts after the Orb was created. Processing of
165  scripts stops after the first failed script, and -1 is returned.
166  Whether a script failed or all scripts succeeded, the CORBA
167  server will be run.
168  */
169  bool result = true;
170  for (std::vector<std::string>::const_iterator iter=scriptFiles.begin();
171  iter!=scriptFiles.end() && result;
172  ++iter)
173  {
174  if ( !(*iter).empty() )
175  {
176  if ( (*iter).rfind(".xml", std::string::npos) == (*iter).length() - 4 ||
177  (*iter).rfind(".cpf", std::string::npos) == (*iter).length() - 4) {
178  if ( deploymentOnlyChecked ) {
179  bool loadOk = true;
180  bool configureOk = true;
181  bool startOk = true;
182  if (!dc.kickStart2( (*iter), false, loadOk, configureOk, startOk )) {
183  result = false;
184  if (!loadOk) {
185  log(Error) << "Failed to load file: '"<< (*iter) <<"'." << endlog();
186  } else if (!configureOk) {
187  log(Error) << "Failed to configure file: '"<< (*iter) <<"'." << endlog();
188  }
189  (void)startOk; // unused - avoid compiler warning
190  }
191  // else leave result=true and continue
192  } else {
193  result = dc.kickStart( (*iter) ) && result;
194  }
195  continue;
196  }
197 
198  if ( (*iter).rfind(".ops", std::string::npos) == (*iter).length() - 4 ||
199  (*iter).rfind(".osd", std::string::npos) == (*iter).length() - 4 ||
200  (*iter).rfind(".lua", std::string::npos) == (*iter).length() - 4) {
201  result = dc.runScript( (*iter) ) && result;
202  continue;
203  }
204 
205  log(Error) << "Unknown extension of file: '"<< (*iter) <<"'. Must be xml, cpf for XML files or, ops, osd or lua for script files."<<endlog();
206  }
207  }
208  rc = (result ? 0 : -1);
209 
210  // Export the DeploymentComponent as CORBA server.
211  if ( !deploymentOnlyChecked ) {
213  }
214  }
215 
217 
219 
220  } catch( CORBA::Exception &e ) {
221  log(Error) << argv[0] <<" ORO_main : CORBA exception raised!" << Logger::nl;
222  log() << CORBA_EXCEPTION_INFO(e) << endlog();
223  } catch (...) {
224  // catch this so that we can destroy the TLSF memory correctly
225  log(Error) << "Uncaught exception." << endlog();
226  }
227 
228  // shutdown Orocos
229  __os_exit();
230  }
231  else
232  {
233  std::cerr << "Unable to start Orocos" << std::endl;
234  rc = -1;
235  }
236 
237 #ifdef ORO_BUILD_LOGGING
240 #endif
241 
242 #ifdef ORO_BUILD_RTALLOC
243  memoryPool.shutdown();
244 #endif
245 
246  return rc;
247 }
bool kickStart2(const std::string &configurationfile, const bool doStart, bool &loadOk, bool &configureOk, bool &startOk)
int __os_init(int argc, char **argv)
virtual void deleteAllCategories()
static void set_category_factory(creator_function_t creator_function)
static std::ostream & nl(std::ostream &__os)
#define CORBA_EXCEPTION_INFO(x)
int deployerParseCmdLine(int argc, char **argv, std::string &siteFile, std::vector< std::string > &scriptFiles, std::string &name, bool &requireNameService, bool &deploymentOnlyChecked, int &minNumberCPU, po::variables_map &vm, po::options_description *otherOptions)
static RTT_CORBA_API bool InitOrb(int argc, char *argv[], Seconds orb_timeout=0)
void __os_exit(void)
int main(int argc, char **argv)
Definition: cdeployer.cpp:55
static TaskContextServer * Create(TaskContext *tc, bool use_naming=true, bool require_name_service=false)
bool kickStart(const std::string &file_name)
static log4cpp::Category * createOCLCategory(const std::string &name, log4cpp::Category *parent, log4cpp::Priority::Value priority)
Definition: Category.cpp:138
static HierarchyMaintainer & getDefaultMaintainer()
bool runScript(const std::string &file_name)
static void ShutdownOrb(bool wait_for_completion=true)
static Logger & log()
int enforceMinNumberCPU(const int minNumberCPU)
static Logger::LogFunction endlog()


ocl
Author(s): OCL Development Team
autogenerated on Mon Mar 23 2020 04:47:19