![]() |
Home | Libraries | People | FAQ | More |
Building an application with Boost.Application is a simple process, the basic roadmap steps are:
Table 1.1. Roadmap Steps
Step |
Optionally? |
Description |
---|---|---|
A |
NO |
Define a 'functor' class for your application with an application operator |
B |
NO |
Create a 'context' for application. An context can be a global_context (singleton) or local context |
C |
YES |
Add desired 'aspects' to application context |
D |
YES |
Define a 'callback' for 'handler aspects' type. e.g.: stop, pause, resume |
E |
YES |
Define new 'apects', and add it to application context |
F |
YES |
Customize some ready to use 'apects' |
G |
YES |
Customize 'SIGNALS' of application |
H |
NO |
Launch an application using some ready to use mode. ('common' or 'server' application) |
I |
YES |
In case of 'Windows Service' (Server mode on Windows), use example code to setup service |
J |
YES |
Use 'aspects' available in the context (that user add on step 'C' or 'E') |
A basic sample of server application can be:
class myapp // [[a]] { public:
myapp(application::context& context) : context_(context) { }
int operator()() // [[a]] { // Do some thing // [[k]] context_.find<application::wait_for_termination_request>()->wait(); return 0; } // [[d]]
bool stop() { // Do some thing return true; // return true to stop, false to ignore } private:
application::context& context_; }; int main(int argc, char *argv[]) {
application::context app_context; // [[b]]
application::auto_handler<myapp> app(app_context); // [[a]] // my server aspects // [[c]]
app_context.insert<application::path>( boost::make_shared<application::path_default_behaviour>(argc, argv)); // [[c]]
app_context.insert<application::args>( boost::make_shared<application::args>(argc, argv)); // [[h]]
return application::launch<application::server>(app, app_context); }
Define a 'functor' myapp class for our application |
|
Define the constructor that will receive a application context |
|
Define a application operator using 'param' signature |
|
Optionally, define a 'stop callback' handler, using 'param' signature |
|
Application context to hold aspects |
|
Create a local 'context' for application that will hold our aspects |
|
Instatntiate our application using auto_handler, the 'stop' method will be automatically handled |
|
Add 'path aspect' to application context |
|
Add 'args aspect' to application context |
|
Launch an application using server application mode |
![]() |
Note |
---|---|
The 'application context' can be defined in 2 ways. |