Application takes care of the initialisation and termination of the program.
Global Classes
class qi::Application
Functions (class qi::Application)
Global Macros
Application
is meant to be instantiated in the main function. It provides a
run
function that keeps the application running until the user asks for
termination (usually through CTRL-C), which is useful when implementing a
service.
Application
‘s destructor blocks until there is no more work scheduled in the
eventloop and all sockets are closed.
It also parses arguments, see qi application arguments.
See also
You rarely need to use this class, see ApplicationSession
.
#include <qi/application.hpp>
int main(int argc, char* argv[])
{
qi::Application app(argc, argv);
// do things
app.run();
}
Class handling startup and teardown of an application. More...
#include <qi/application.hpp>
qi::ApplicationSession
Application
(int& argc, char**& argv, const std::string& name, const std::string& path)Application
(const std::string& name, int& argc, char**& argv)~Application
()run
()stop
()arguments
()argc
()argv
()setName
(const std::string& name)name
()setArguments
(int argc, char** argv)setArguments
(const std::vector<std::string>& arguments)loadModule
(const std::string& name, int flags)unloadModule
(void* handle)terminated
()initialized
()program
()realProgram
()_suggestedSdkPath
()atEnter
(std::function<void()> func)atExit
(std::function<void()> func)atRun
(std::function<void()> func)atStop
(std::function<void()> func)atSignal
(std::function<void(int)> func, int signal)The qi::Application
class is designed to ease
startup and teardown of an executable.
All executables using qi classes should create an instance of
qi::Application
on the stack of the main() function.
qi::Application::
run
()¶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.
qi::Application::
stop
()¶Stop the application. Call all atStop handlers.
qi::Application::
arguments
()¶Brief: Get arguments of the program as an std::vector of std::string.
Returns: | List of arguments of the program. |
---|
qi::Application::
argc
()¶Brief: Get argument counter of the program.
Returns: | Argument counter of the program if Application was initialized, -1 otherwise. |
---|
qi::Application::
argv
()¶Brief: Get string arguments of the program (including program name).
Returns: | Arguments of the program if Application was initialized, 0 otherwise. |
---|
qi::Application::
setName
(const std::string& name)¶Brief: Set application name.
Parameters: |
|
---|
qi::Application::
name
()¶Brief: Get application name.
Returns: | A string with the application name, empty string if setName isn’t call. |
---|
qi::Application::
setArguments
(int argc, char** argv)¶Brief: Set arguments of the program with argc as argument counter and argv as argument values.
Parameters: |
|
---|
qi::Application::
setArguments
(const std::vector<std::string>& arguments)¶Brief: Set arguments ot the program as an std::vector of std::string.
Parameters: |
|
---|
qi::Application::
loadModule
(const std::string& name, int flags = -1)¶Brief: Load a module into the current process.
Parameters: |
|
---|---|
Returns: | A handle, to be used by qi::os::dlsym() or unloadModule(). |
The module can execute code when loaded by using QI_AT_ENTER
.
qi::Application::
unloadModule
(void* handle)¶Brief: Unload a module from the current process.
Parameters: |
|
---|
qi::Application::
terminated
()¶Brief: Check whether the Application instance is terminated or not.
Returns: | True if it is stop, false otherwise. |
---|
qi::Application::
initialized
()¶Brief: Check whether the Application instance was initialized or not.
Returns: | True if it was initialized, false otherwise. |
---|
qi::Application::
program
()¶Brief: Return the current program full path according to argv[0].
Returns: | full path to the current running program, symbolic links are not resolved. |
---|
qi::Application::
realProgram
()¶Brief: Return the current program full path.
Returns: | full path to the current running program, symbolic links are resolved. |
---|
When using this function from a Python application for example on gentoo, it will return something like /usr/bin/python2.7 (because python is a symlink to python-wrapper which will exec() /usr/bin/python2.7). On the other hand, program() will return the full path to the script run by the Python interpreter.
Computed using specific OS API:
If the former API fail it will try to guess the value from argv[0].
For this method to work qi::Application(int&, char**&)
should
have been called in your main().
qi::Application::
_suggestedSdkPath
()¶Used internally, you should not need this.
qi::Application::
atEnter
(std::function<void()> func)¶Brief: Register a function to be executed at Application creation.
Parameters: |
|
---|---|
Returns: | True if registering succeeded, false otherwise. |
qi::Application::
atExit
(std::function<void()> func)¶Brief: Register a function to be executed at Application destruction.
Parameters: |
|
---|---|
Returns: | True if registering succeeded, false otherwise. |
qi::Application::
atRun
(std::function<void()> func)¶Brief: Register a function to be executed when run() is called. The functions are executed sequentially at the beginning of run().
Parameters: |
|
---|---|
Returns: | True if registering succeeded, false otherwise. |
qi::Application::
atStop
(std::function<void()> func)¶Brief: Register a function to be executed when stop() is called. The functions are executed sequentially before run() returns.
Parameters: |
|
---|---|
Returns: | True if registering succeeded, false otherwise. |
qi::Application::
atSignal
(std::function<void(int)> func, int signal)¶Brief: Register a function to be executed when a signal occurs.
Parameters: |
|
---|---|
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.
qi::Application::
Application
(int& argc, char**& argv, const std::string& name = "", const std::string& path = "")¶Brief: Application constructor. Must be the first thing called by main().
Parameters: |
|
---|
qi::Application::
Application
(const std::string& name, int& argc, char**& argv)¶Brief: Application constructor. Must be the first thing called by main().
Parameters: |
|
---|
DeprecatedUse Application(int&, char**&, const std::string&, const std::string&)
qi::Application::
~Application
()¶QI_AT_ENTER(func)
¶func
The handler that must be called at enter.
QI_AT_EXIT(func)
¶func
The handler that must be called at exit.