Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Application Apects

A central concept on Boost.Application is the 'aspects' that can be added to application context.

Boost.Application provide a wide class of ready-to-use 'aspects' and user is free to customize or define anyone that he needs, basically we can classify the ready-to-use aspects in 2 groups:

Table 1.2. Simple or Common that can be any class

Aspect Name

Aspect Contract Class

Aspect Final Class

Aspect Functionality

args

args

args (same class)

Provide functionality for handling arguments of the application

path

path

path_default_behaviour

Provide functionality for handling paths of the application

run_mode

run_mode

run_mode (same class)

Provide information of application running mode (common or server)

status

status

status (same class)

Provide information about current satatus of application (sopped, running or paused)

wait_for_termination_request

wait_for_termination_request

wait_for_termination_request_default_behaviour

Provide functionality for wait for task completion


Table 1.3. Handler, that has a callback associated to it

Aspect Name

Aspect Contract Class

Aspect Final Class

Aspect Functionality

pause_handler

pause_handler

pause_handler_default_behaviour

When 'pause' event is detected, fire a user defined callback

resume_handler

resume_handler

resume_handler_default_behaviour

When 'resume' event is detected, fire a user defined callback

termination_handler

termination_handler

termination_handler_default_behaviour

When 'stop' signal/event is detected, fire a user defined callback

limit_single_instance

limit_single_instance

limit_single_instance_default_behaviour

When single instance feature is enabled, fire a user defined callback to handle it


To know how customize an Aspect, refer to 'Customize Aspects'

[Note] Note

Note that that the application launch<mode> tie 'run_mode' and 'status' aspects to application context in automatic way.

For sample, the following code show the use of 'path' aspect.

class myapp
{
public:

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

   // param
   int operator()()
   {
      std::cout << "Test" << std::endl;

	    1boost::shared_ptr<application::path> path
         = context_.find<application::path>();

      std::cout << "executable_path      : " << path->executable_path()      << std::endl;
      std::cout << "current_path         : " << path->current_path()         << std::endl;
      std::cout << "executable_name      : " << path->executable_name()      << std::endl;
      std::cout << "executable_full_name : " << path->executable_full_name() << std::endl;
      std::cout << "executable_path_name : " << path->executable_path_name() << std::endl;

      // e.g.: "executable_path      : E:\project.boost.app.v4\libs\application\vc11ide\Debug"
      // e.g.: "current_path         : E:\project.boost.app.v4\libs\application\vc11ide"
      // e.g.: "executable_name      : path"
      // e.g.: "executable_full_name : path.exe"
      // e.g.: "executable_path_name : E:\project.boost.app.v4\libs\application\vc11ide\Debug\path.exe"

      return 0;
   }

private:
   application::context& context_;

};

// main

int main(int argc, char *argv[])
{
   application::context app_context;
   myapp app(app_context);

   2app_context.insert<application::path>(
     boost::make_shared<application::path_default_behaviour>(argc, argv));

   return application::launch<application::common>(app, app_context);
}

1

Use 'path' aspect on your logic

2

Add 'path' aspect to context pool of application, it will be available for future use


PrevUpHomeNext