libqi-api  2.4.3.28
 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 <boost/function.hpp>
12 # include <qi/api.hpp>
13 # include <vector>
14 
15 namespace qi {
16 
30  {
31  public:
41  Application(int& argc, char** &argv, const std::string& name = "", const std::string& path = "");
51  QI_API_DEPRECATED Application(const std::string &name, int& argc, char** &argv);
57  ~Application();
58 
71  static void run();
75  static void stop();
76 
81  static const std::vector<std::string>& arguments();
87  static int argc();
92  static const char** argv();
97  static void setName(const std::string &name);
103  static std::string name();
110  static void setArguments(int argc, char** argv);
115  static void setArguments(const std::vector<std::string>& arguments);
116 
128  static void* loadModule(const std::string& name, int flags=-1);
133  static void unloadModule(void* handle);
138  static bool terminated();
143  static bool initialized();
144 
151  static const char* program();
152 
176  static const char* realProgram();
177 
183  static const char* suggestedSdkPath();
184 
190  static bool atEnter(boost::function<void()> func);
196  static bool atExit(boost::function<void()> func);
203  static bool atStop(boost::function<void()> func);
214  static bool atSignal(boost::function<void(int)> func, int signal);
215  };
216 }
217 
222 #define QI_AT_ENTER(func) \
223  static bool QI_UNIQ_DEF(_qi_atenter) = ::qi::Application::atEnter(func);
224 
230 #define QI_AT_EXIT(func) \
231  static bool QI_UNIQ_DEF(_qi_atexit) = ::qi::Application::atExit(func);
232 
233 //THIS IS INTERNAL
234 //API is not maintained for this function
235 //The user need to include <boost/program_options.hpp> and <boost/bind.hpp>
236 //Use like this:
237 //namespace {
238 // _QI_COMMAND_LINE_OPTIONS(
239 // "Name of category",
240 // (option1)
241 // (option2)
242 // )
243 //}
244 #define _QI_COMMAND_LINE_OPTIONS(desc, opts) \
245  static void QI_UNIQ_DEF(_qi_opt_func)() { \
246  namespace po = boost::program_options; \
247  po::variables_map vm; \
248  po::command_line_parser p(::qi::Application::arguments()); \
249  po::options_description options(desc); \
250  { \
251  using namespace boost::program_options; \
252  options.add_options() opts; \
253  } \
254  po::parsed_options res = p.options(options) \
255  .allow_unregistered() \
256  .run(); \
257  po::store(res, vm); \
258  /* Invoke notify callbacks*/ \
259  po::notify(vm); \
260  { \
261  po::options_description descTmp; \
262  descTmp.add_options() \
263  ("help,h", ""); \
264  po::variables_map vmTmp; \
265  po::store(po::command_line_parser(qi::Application::arguments()) \
266  .options(descTmp).allow_unregistered().run(), vmTmp); \
267  if (vmTmp.count("help")) \
268  std::cout << options << std::endl; \
269  } \
270  std::vector<std::string> args \
271  = po::collect_unrecognized(res.options, po::include_positional); \
272  /* Set arguments to what was not used */ \
273  ::qi::Application::setArguments(args); \
274  } \
275  QI_AT_ENTER(boost::bind(&(QI_UNIQ_DEF(_qi_opt_func))))
276 
277 #endif // _QI_APPLICATION_HPP_
#define QI_API
Definition: api.hpp:34
dll import/export and compiler message
Class handling startup and teardown of an application.
Definition: application.hpp:29
#define QI_API_DEPRECATED
Compiler flags to mark a function as deprecated. It will generate a compiler warning.
Definition: macro.hpp:39