deployer-corba.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Jul 3 15:30:24 CEST 2008 deployer-corba.cpp
3 
4  deployer-corba.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 
40 #include <iostream>
41 #include <string>
42 #include "deployer-funcs.hpp"
43 
44 #ifdef ORO_BUILD_LOGGING
45 # ifndef OS_RT_MALLOC
46 # warning "Logging needs rtalloc!"
47 # endif
49 #include "logging/Category.hpp"
50 #endif
51 
52 using namespace RTT;
53 using namespace RTT::corba;
54 namespace po = boost::program_options;
55 
56 int main(int argc, char** argv)
57 {
58  std::string siteFile; // "" means use default in DeploymentComponent.cpp
59  std::vector<std::string> scriptFiles;
60  std::string name("Deployer");
61  bool requireNameService = false;
62  bool deploymentOnlyChecked = false;
63  int minNumberCPU = 0;
64  po::variables_map vm;
65  po::options_description taoOptions("Additional options after a '--' are passed through to TAO");
66  // we don't actually list any options for TAO ...
67 
68  po::options_description otherOptions;
69 
70 #ifdef ORO_BUILD_RTALLOC
71  OCL::memorySize rtallocMemorySize = ORO_DEFAULT_RTALLOC_SIZE;
72  po::options_description rtallocOptions = OCL::deployerRtallocOptions(rtallocMemorySize);
73  otherOptions.add(rtallocOptions);
74  OCL::TLSFMemoryPool memoryPool;
75 #endif
76 
77 #if defined(ORO_BUILD_LOGGING) && defined(OROSEM_LOG4CPP_LOGGING)
78  // to support RTT's logging to log4cpp
79  std::string rttLog4cppConfigFile;
80  po::options_description rttLog4cppOptions = OCL::deployerRttLog4cppOptions(rttLog4cppConfigFile);
81  otherOptions.add(rttLog4cppOptions);
82 #endif
83 
84  // as last set of options
85  otherOptions.add(taoOptions);
86 
87  // were we given non-deployer options? ie find "--"
88  int optIndex = 0;
89  bool found = false;
90 
91  while(!found && optIndex<argc)
92  {
93  found = (0 == strcmp("--", argv[optIndex]));
94  if(!found) optIndex++;
95  }
96 
97  if (found) {
98  argv[optIndex] = argv[0];
99  }
100 
101  // if extra options not found then process all command line options,
102  // otherwise process all options up to but not including "--"
103  int rc = OCL::deployerParseCmdLine(!found ? argc : optIndex, argv,
104  siteFile, scriptFiles, name, requireNameService, deploymentOnlyChecked,
105  minNumberCPU,
106  vm, &otherOptions);
107  if (0 != rc)
108  {
109  return rc;
110  }
111 
112  // check system capabilities
113  rc = OCL::enforceMinNumberCPU(minNumberCPU);
114  if (0 != rc)
115  {
116  return rc;
117  }
118 
119 #if defined(ORO_BUILD_LOGGING) && defined(OROSEM_LOG4CPP_LOGGING)
120  if (!OCL::deployerConfigureRttLog4cppCategory(rttLog4cppConfigFile))
121  {
122  return -1;
123  }
124 #endif
125 
126 #ifdef ORO_BUILD_RTALLOC
127  if (!memoryPool.initialize(rtallocMemorySize.size))
128  {
129  return -1;
130  }
131 #endif // ORO_BUILD_RTALLOC
132 
133 #ifdef ORO_BUILD_LOGGING
134  // use our log4cpp-derived categories to do real-time logging
137 #endif
138 
139  /******************** WARNING ***********************
140  * NO log(...) statements before __os_init() !!!!!
141  ***************************************************/
142 
143  // start Orocos _AFTER_ setting up log4cpp
144  if (0 == __os_init(argc - optIndex, &argv[optIndex]))
145  {
146 #ifdef ORO_BUILD_LOGGING
147  log(Info) << "OCL factory set for real-time logging" << endlog();
148 #endif
149  rc = -1; // prove otherwise
150  try {
151  // if TAO options not found then have TAO process just the program name,
152  // otherwise TAO processes the program name plus all options (potentially
153  // none) after "--"
154  TaskContextServer::InitOrb( argc - optIndex, &argv[optIndex] );
155 
156  // scope to force dc destruction prior to memory free and Orb shutdown
157  {
158  OCL::CorbaDeploymentComponent dc( name, siteFile );
159 
160  if (0 == TaskContextServer::Create( &dc, true, requireNameService ))
161  {
162  return -1;
163  }
164 
165  // The orb thread accepts incoming CORBA calls.
167 
168  /* Only start the scripts after the Orb was created. Processing of
169  scripts stops after the first failed script, and -1 is returned.
170  Whether a script failed or all scripts succeeded, in non-daemon
171  and non-checking mode the TaskBrowser will be run to allow
172  inspection if the input is a tty.
173  */
174  bool result = true;
175  for (std::vector<std::string>::const_iterator iter=scriptFiles.begin();
176  iter!=scriptFiles.end() && result;
177  ++iter)
178  {
179  if ( !(*iter).empty() )
180  {
181  if ( (*iter).rfind(".xml", std::string::npos) == (*iter).length() - 4 ||
182  (*iter).rfind(".cpf", std::string::npos) == (*iter).length() - 4) {
183  if ( deploymentOnlyChecked ) {
184  bool loadOk = true;
185  bool configureOk = true;
186  bool startOk = true;
187  if (!dc.kickStart2( (*iter), false, loadOk, configureOk, startOk )) {
188  result = false;
189  if (!loadOk) {
190  log(Error) << "Failed to load file: '"<< (*iter) <<"'." << endlog();
191  } else if (!configureOk) {
192  log(Error) << "Failed to configure file: '"<< (*iter) <<"'." << endlog();
193  }
194  (void)startOk; // unused - avoid compiler warning
195  }
196  // else leave result=true and continue
197  } else {
198  result = dc.kickStart( (*iter) ) && result;
199  }
200  continue;
201  }
202 
203  if ( (*iter).rfind(".ops", std::string::npos) == (*iter).length() - 4 ||
204  (*iter).rfind(".osd", std::string::npos) == (*iter).length() - 4 ||
205  (*iter).rfind(".lua", std::string::npos) == (*iter).length() - 4) {
206  result = dc.runScript( (*iter) ) && result;
207  continue;
208  }
209 
210  log(Error) << "Unknown extension of file: '"<< (*iter) <<"'. Must be xml, cpf for XML files or, ops, osd or lua for script files."<<endlog();
211  }
212  }
213  rc = (result ? 0 : -1);
214 
215  // We don't start an interactive console when we're a daemon
216  if ( !deploymentOnlyChecked && !vm.count("daemon") ) {
217  if (isatty(fileno(stdin))) {
218  OCL::TaskBrowser tb( &dc );
219  tb.loop();
220  } else {
221  dc.waitForInterrupt();
222  }
223 
224  // do it while CORBA is still up in case need to do anything remote.
225  dc.shutdownDeployment();
226  }
227  }
228 
230 
232 
233  } catch( CORBA::Exception &e ) {
234  log(Error) << argv[0] <<" ORO_main : CORBA exception raised!" << Logger::nl;
235  log() << CORBA_EXCEPTION_INFO(e) << endlog();
236  } catch (...) {
237  // catch this so that we can destroy the TLSF memory correctly
238  log(Error) << "Uncaught exception." << endlog();
239  }
240 
241  // shutdown Orocos
242  __os_exit();
243  }
244  else
245  {
246  std::cerr << "Unable to start Orocos" << std::endl;
247  rc = -1;
248  }
249 
250 #ifdef ORO_BUILD_LOGGING
253 #endif
254 
255 #ifdef ORO_BUILD_RTALLOC
256  memoryPool.shutdown();
257 #endif
258 
259  return rc;
260 }
void loop()
Call this method from ORO_main() to process keyboard input and thus startup the TaskBrowser.
bool kickStart2(const std::string &configurationfile, const bool doStart, bool &loadOk, bool &configureOk, bool &startOk)
This component allows a text client to browse the peers of a peer RTT::TaskContext and execute comman...
Definition: TaskBrowser.hpp:86
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)
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
int main(int argc, char **argv)
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