Class handling startup and teardown of an application.
More...
#include <application.hpp>
List of all members.
Public Member Functions |
| Application (int &argc, char **&argv) |
| Application constructor. Must be the first thing called by main().
|
| Application (const std::string &name, int &argc, char **&argv) |
| ~Application () |
| Application destructor. It executes atExit() callbacks.
|
Static Public Member Functions |
static void | run () |
| Wait until the end of the program.
|
static void | stop () |
static const std::vector
< std::string > & | arguments () |
| Get arguments of the program as an std::vector of std::string.
|
static int | argc () |
| Get argument counter of the program.
|
static const char ** | argv () |
| Get string arguments of the program (including program name).
|
static void | setName (const std::string &name) |
| Set application name.
|
static std::string | name () |
| Get application name.
|
static void | setArguments (int argc, char **argv) |
| Set arguments of the program with argc as argument counter and argv as argument values.
|
static void | setArguments (const std::vector< std::string > &arguments) |
| Set arguments ot the program as an std::vector of std::string.
|
static void * | loadModule (const std::string &name, int flags=-1) |
| Load a module into the current process.
|
static void | unloadModule (void *handle) |
| Unload a module from the current process.
|
static bool | terminated () |
static bool | initialized () |
| Check whether the Application instance was initialized or not.
|
static const char * | program () |
| Return the current program full path.
|
static bool | atEnter (boost::function< void()> func) |
| Register a function to be executed at Application creation.
|
static bool | atExit (boost::function< void()> func) |
| Register a function to be executed at Application destruction.
|
static bool | atStop (boost::function< void()> func) |
| Register a function to be executed when stop() is called. The functions are executed sequentially before run() returns.
|
static bool | atSignal (boost::function< void(int)> func, int signal) |
| Register a function to be executed when a signal occurs.
|
Detailed Description
Class handling startup and teardown of an application.
* The :cpp:class:`qi::Application` class is designed to ease
* startup and teardown of an executable.
*
* All executables using qi classes should create an instance of
* :cpp:class:`qi::Application` on the stack of the main() function.
*
- Examples:
- qipath_example.cpp.
Definition at line 17 of file application.hpp.
Constructor & Destructor Documentation
Application constructor. Must be the first thing called by main().
- Parameters:
-
argc | Argument counter of the program. |
argv | Arguments of the program (given to main). |
- Exceptions:
-
std::logic_error | When the constructor is called twice. |
Member Function Documentation
Get argument counter of the program.
- Returns:
- Argument counter of the program if Application was initialized, -1 otherwise.
Get arguments of the program as an std::vector of std::string.
Get string arguments of the program (including program name).
- Returns:
- Arguments of the program if Application was initialized, 0 otherwise.
Register a function to be executed at Application creation.
- Parameters:
-
- Returns:
- True if registering succeeded, false otherwise.
Register a function to be executed at Application destruction.
- Parameters:
-
func | Callback function called at Application destruction. |
- Returns:
- True if registering succeeded, false otherwise.
Register a function to be executed when a signal occurs.
- Parameters:
-
func | Callback function called on signal. |
signal | Signal number. |
- Returns:
- True if registering succeeded, false otherwise.
The handler is executed in a thread, not from within the signal handler, so there is no restriction on what can be done by your handler function, except that it should return reasonably quickly.
Register a function to be executed when stop() is called. The functions are executed sequentially before run() returns.
- Parameters:
-
func | Callback function called when stop() is called. |
- Returns:
- True if registering succeeded, false otherwise.
Check whether the Application instance was initialized or not.
- Returns:
- True if it was initialized, false otherwise.
Load a module into the current process.
- Parameters:
-
name | The module path and name. If no extension is used, the correct extension for a library on the current platform is used. |
flags | Extra flags to pass to the dlopen function. |
- Returns:
- A handle, to be used by qi::os::dlsym() or unloadModule().
* The module can execute code when loaded by using :cpp:macro:`QI_AT_ENTER`.
*
Get application name.
- Returns:
- A string with the application name, empty string if setName isn't call.
Return the current program full path.
- Returns:
- full path to the current running program
* Computed using specific OS API:
*
* - Apple : _NSGetExecutablePath
* - Linux : reading "/proc/self/exe"
* - Windows: GetModuleFileName
*
* If the former API fail it will try to guess the value from argv[0].
* For this method to work :cpp:func:`qi::Application(int&, char**&)` should
* have been called in your main().
*
Wait until the end of the program.
* Wait until one of those conditions becomes true:
* - stop() is called.
* - TERM or QUIT signal is received.
* - the Application instance is destroyed, which means main() is exiting.
*
* Run can be called by multiple threads simultaneously.
*
Set arguments of the program with argc as argument counter and argv as argument values.
- Parameters:
-
argc | Argument counter of the program. |
argv | Arguments of the program (given to main). |
Set arguments ot the program as an std::vector of std::string.
- Parameters:
-
arguments | Sets arguments with a vector of strings. |
Set application name.
- Parameters:
-
name | The application's name. |
Unload a module from the current process.
- Parameters:
-
handle | Handle on the loaded module. |
The documentation for this class was generated from the following files: