libqi-api  2.8.7.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
application.hpp
Go to the documentation of this file.
1 #pragma once
2 /*
3  * Copyright (c) 2012, 2013 Aldebaran Robotics. All rights reserved.
4  * Use of this source code is governed by a BSD-style license that can be
5  * found in the COPYING file.
6  */
7 
8 #ifndef _QI_APPLICATION_HPP_
9 # define _QI_APPLICATION_HPP_
10 
11 # include <functional>
12 # include <boost/program_options.hpp>
13 # include <vector>
14 # include <string>
15 # include <qi/api.hpp>
16 
17 namespace qi {
18 
32  {
33  public:
43  Application(int& argc, char** &argv, const std::string& name = "", const std::string& path = "");
53  QI_API_DEPRECATED_MSG(Use 'Application(int, char**, string, string)' instead)
54  Application(const std::string &name, int& argc, char** &argv);
60  ~Application();
61 
62  // non-copyable
63  Application(const Application&) = delete;
64  Application& operator=(const Application&) = delete;
65 
78  static void run();
82  static void stop();
83 
88  static const std::vector<std::string>& arguments();
94  static int argc();
99  static const char** argv();
104  static void setName(const std::string &name);
110  static std::string name();
117  static void setArguments(int argc, char** argv);
122  static void setArguments(const std::vector<std::string>& arguments);
123 
135  static void* loadModule(const std::string& name, int flags=-1);
140  static void unloadModule(void* handle);
145  static bool terminated();
150  static bool initialized();
151 
158  static const char* program();
159 
183  static const char* realProgram();
184 
190  static const char* _suggestedSdkPath();
191 
197  static bool atEnter(std::function<void()> func);
198 
204  static bool atExit(std::function<void()> func);
205 
212  static bool atRun(std::function<void()> func);
213 
220  static bool atStop(std::function<void()> func);
221 
232  static bool atSignal(std::function<void(int)> func, int signal);
233 
238  static boost::program_options::options_description& options();
239 
243  static std::string helpText();
244  };
245 }
246 
251 #define QI_AT_ENTER(func) \
252  static bool QI_UNIQ_DEF(_qi_atenter) QI_ATTR_UNUSED = ::qi::Application::atEnter(func);
253 
259 #define QI_AT_EXIT(func) \
260  static bool QI_UNIQ_DEF(_qi_atexit) QI_ATTR_UNUSED = ::qi::Application::atExit(func);
261 
262 //THIS IS INTERNAL
263 //API is not maintained for this function
264 //The user need to include <boost/program_options.hpp> and <boost/bind.hpp>
265 //Use like this:
266 //namespace {
267 // _QI_COMMAND_LINE_OPTIONS(
268 // "Name of category",
269 // (option1)
270 // (option2)
271 // )
272 //}
273 #define _QI_COMMAND_LINE_OPTIONS(desc, opts) \
274  static void QI_UNIQ_DEF(_qi_opt_func)() { \
275  namespace po = boost::program_options; \
276  po::options_description options(desc); \
277  { \
278  using namespace boost::program_options; \
279  options.add_options() opts; \
280  } \
281  ::qi::Application::options().add(options); \
282  } \
283  QI_AT_ENTER(boost::bind(&(QI_UNIQ_DEF(_qi_opt_func))))
284 
285 #endif // _QI_APPLICATION_HPP_
#define QI_API
Definition: api.hpp:33
dll import/export and compiler message
Class handling startup and teardown of an application.
Definition: application.hpp:31
#define QI_API_DEPRECATED_MSG(msg__)
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:55