bin/deployer.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  tag: Peter Soetens Thu Jul 3 15:30:14 CEST 2008 deployer.cpp
3 
4  deployer.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 
37 #ifndef RTT_SCRIPT_PROGRAM
38 #define USE_TASKBROWSER
39 #endif
40 
41 #ifdef USE_TASKBROWSER
43 #endif
45 #include <iostream>
46 #include <string>
47 #include "deployer-funcs.hpp"
48 
49 #ifdef ORO_BUILD_LOGGING
50 # ifndef OS_RT_MALLOC
51 # warning "Logging needs rtalloc!"
52 # endif
54 #include "logging/Category.hpp"
55 #endif
56 
57 using namespace RTT;
58 namespace po = boost::program_options;
59 
60 int main(int argc, char** argv)
61 {
62  std::string siteFile; // "" means use default in DeploymentComponent.cpp
63  std::vector<std::string> scriptFiles;
64  std::string name("Deployer");
65  bool requireNameService = false; // not used
66  bool deploymentOnlyChecked = false;
67  int minNumberCPU = 0;
68  po::variables_map vm;
69  po::options_description otherOptions;
70 
71 #ifdef ORO_BUILD_RTALLOC
72  OCL::memorySize rtallocMemorySize = ORO_DEFAULT_RTALLOC_SIZE;
73  po::options_description rtallocOptions = OCL::deployerRtallocOptions(rtallocMemorySize);
74  otherOptions.add(rtallocOptions);
75  OCL::TLSFMemoryPool memoryPool;
76 #endif
77 
78 #if defined(ORO_BUILD_LOGGING) && defined(OROSEM_LOG4CPP_LOGGING)
79  // to support RTT's logging to log4cpp
80  std::string rttLog4cppConfigFile;
81  po::options_description rttLog4cppOptions = OCL::deployerRttLog4cppOptions(rttLog4cppConfigFile);
82  otherOptions.add(rttLog4cppOptions);
83 #endif
84 
85  // were we given non-deployer options? ie find "--"
86  int optIndex = 0;
87  bool found = false;
88 
89  while(!found && optIndex<argc)
90  {
91  found = (0 == strcmp("--", argv[optIndex]));
92  if(!found) optIndex++;
93  }
94 
95  if (found) {
96  argv[optIndex] = argv[0];
97  }
98 
99  // if extra options not found then process all command line options,
100  // otherwise process all options up to but not including "--"
101  int rc = OCL::deployerParseCmdLine(!found ? argc : optIndex, argv,
102  siteFile, scriptFiles, name, requireNameService, deploymentOnlyChecked,
103  minNumberCPU,
104  vm, &otherOptions);
105  if (0 != rc)
106  {
107  return rc;
108  }
109 
110  // check system capabilities
111  rc = OCL::enforceMinNumberCPU(minNumberCPU);
112  if (0 != rc)
113  {
114  return rc;
115  }
116 
117 #if defined(ORO_BUILD_LOGGING) && defined(OROSEM_LOG4CPP_LOGGING)
118  if (!OCL::deployerConfigureRttLog4cppCategory(rttLog4cppConfigFile))
119  {
120  return -1;
121  }
122 #endif
123 
124 #ifdef ORO_BUILD_RTALLOC
125  if (!memoryPool.initialize(rtallocMemorySize.size))
126  {
127  return -1;
128  }
129 #endif // ORO_BUILD_RTALLOC
130 
131 #ifdef ORO_BUILD_LOGGING
132  // use our log4cpp-derived categories to do real-time logging
135 #endif
136 
137  /******************** WARNING ***********************
138  * NO log(...) statements before __os_init() !!!!!
139  ***************************************************/
140 
141  // start Orocos _AFTER_ setting up log4cpp
142  if (0 == __os_init(argc - optIndex, &argv[optIndex]))
143  {
144 #ifdef ORO_BUILD_LOGGING
145  log(Info) << "OCL factory set for real-time logging" << endlog();
146 #endif
147  rc = -1; // prove otherwise
148  // scope to force dc destruction prior to memory free
149  {
150  OCL::DeploymentComponent dc( name, siteFile );
151 
152  /* Only start the scripts after the Orb was created. Processing of
153  scripts stops after the first failed script, and -1 is returned.
154  Whether a script failed or all scripts succeeded, in non-daemon
155  and non-checking mode the TaskBrowser will be run to allow
156  inspection if the input is a tty.
157  */
158  bool result = true;
159  for (std::vector<std::string>::const_iterator iter=scriptFiles.begin();
160  iter!=scriptFiles.end() && result;
161  ++iter)
162  {
163  if ( !(*iter).empty() )
164  {
165  if ( (*iter).rfind(".xml", std::string::npos) == (*iter).length() - 4 ||
166  (*iter).rfind(".cpf", std::string::npos) == (*iter).length() - 4) {
167  if ( deploymentOnlyChecked ) {
168  bool loadOk = true;
169  bool configureOk = true;
170  bool startOk = true;
171  if (!dc.kickStart2( (*iter), false, loadOk, configureOk, startOk )) {
172  result = false;
173  if (!loadOk) {
174  log(Error) << "Failed to load file: '"<< (*iter) <<"'." << endlog();
175  } else if (!configureOk) {
176  log(Error) << "Failed to configure file: '"<< (*iter) <<"'." << endlog();
177  }
178  (void)startOk; // unused - avoid compiler warning
179  }
180  // else leave result=true and continue
181  } else {
182  result = dc.kickStart( (*iter) ) && result;
183  }
184  continue;
185  }
186 
187  if ( (*iter).rfind(".ops", std::string::npos) == (*iter).length() - 4 ||
188  (*iter).rfind(".osd", std::string::npos) == (*iter).length() - 4 ||
189  (*iter).rfind(".lua", std::string::npos) == (*iter).length() - 4) {
190  result = dc.runScript( (*iter) ) && result;
191  continue;
192  }
193 
194  log(Error) << "Unknown extension of file: '"<< (*iter) <<"'. Must be xml, cpf for XML files or, ops, osd or lua for script files."<<endlog();
195  }
196  }
197  rc = (result ? 0 : -1);
198 
199 #ifdef USE_TASKBROWSER
200  // We don't start an interactive console when we're a daemon
201  if ( !deploymentOnlyChecked && !vm.count("daemon") ) {
202  if (isatty(fileno(stdin))) {
203  OCL::TaskBrowser tb( &dc );
204  tb.loop();
205  } else {
206  dc.waitForInterrupt();
207  }
208 
209  dc.shutdownDeployment();
210  }
211 #endif
212  }
213 
214  // shutdown Orocos
215  __os_exit();
216  }
217  else
218  {
219  std::cerr << "Unable to start Orocos" << std::endl;
220  rc = -1;
221  }
222 
223 #ifdef ORO_BUILD_LOGGING
226 #endif
227 
228 #ifdef ORO_BUILD_RTALLOC
229  memoryPool.shutdown();
230 #endif
231 
232  return rc;
233 }
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)
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)
void __os_exit(void)
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 Logger & log()
int main(int argc, char **argv)
int enforceMinNumberCPU(const int minNumberCPU)
static Logger::LogFunction endlog()


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