Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Application Roadmap

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:

1class myapp // [[a]]
{
public:

   2myapp(application::context& context)
      : context_(context)
   {
   }

   3int operator()() // [[a]]
   {
      // Do some thing

      // [[k]]
      context_.find<application::wait_for_termination_request>()->wait();

      return 0;
   }

   // [[d]]
   4bool stop()
   {
      // Do some thing
      return true; // return true to stop, false to ignore
   }

private:

   5application::context& context_;
};

int main(int argc, char *argv[])
{

   6application::context app_context; // [[b]]

   7application::auto_handler<myapp> app(app_context); // [[a]]

   // my server aspects

   // [[c]]
   8app_context.insert<application::path>(
      boost::make_shared<application::path_default_behaviour>(argc, argv));

   // [[c]]
   9app_context.insert<application::args>(
      boost::make_shared<application::args>(argc, argv));

   // [[h]]
   10return application::launch<application::server>(app, app_context);
}

1

Define a 'functor' myapp class for our application

2

Define the constructor that will receive a application context

3

Define a application operator using 'param' signature

4

Optionally, define a 'stop callback' handler, using 'param' signature

5

Application context to hold aspects

6

Create a local 'context' for application that will hold our aspects

7

Instatntiate our application using auto_handler, the 'stop' method will be automatically handled

8

Add 'path aspect' to application context

9

Add 'args aspect' to application context

10

Launch an application using server application mode

[Note] Note

The 'application context' can be defined in 2 ways.

1. 'global_context' based version (that don't receive a 'context' as parameter on constructor).
2. 'local' based version (that receive a 'context' of application as parameter on constructor, our case here.).


PrevUpHomeNext