Boost C++ Libraries Home Libraries People FAQ More

Next

Chapter 1. Boost.Application

Renato Forti

Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

Table of Contents

Motivation
Design overview
Suported Application Types
Common Application
Server Application
Application Roadmap
Application Context
Application Apects
Using Application Handlers
Handling errors
Throws an 'system_error' version.
Set 'error_code' on error version.
Tutorial
Common Application
Server Application
Customization
Customize Aspects
Customize Signals/Handlers
Other Features
Single Instance Feature
Windows specifics
Setup for Windows Service
Multi-Service Process
Unicode on Services
POSIX specifics
Self-pipe
F.A.Q.
Is Boost.Application thread-safe?
How Unicode (Windows) is hadled?
Can I customize a application SIGNALS?
Can I customize a library provided aspects?
Can I build another aspects to application?
Can I build another application mode? What is needed?
I have found a bug, how do I notify?
Dependencies
Supported compilers and platforms
Examples
Reference
Core Reference
Application Modes Reference
Aspects Reference
Bibliography
TODO/Future Releases
TODO
Future Releases
Revision History
Acknowledgements
[Caution] Caution

This is not yet an official Boost C++ library. It wasn't reviewed and can't be downloaded from www.boost.org. This beta is available to boost community to know real interest and get comments for refinement.The intention is to submit library to formal review, if community think that it is interesting!

[Note] Note

Starting with version 0.4.10 the plug-in module has been moved to a new library, called Boost.DLL (Plugin).

Refer to Boost.DLL

Sometimes we need run application for long time (e.g. Server Application), we need a mechanism to extend this application on runtime, and we need some facilities to access paths, ensure single instance instantiation on system, manage and catch signals and so on.

This work is recurrent each time that we need build and deploy an application for particular system, and the way to do this, change a lot on each of these systems.

For instance on Windows side we have 'services' and on Unix (POSIX) side we have 'daemons' that are used to build long-running executable applications (e.g. server) and these two APIs have no similarity. Thus, in this scenarios, is so much difficult to developer have your application running on Windows or on POSIX as server without a lot of work. The work is harder if we need run same application in both systems.

Other problem raise when user want provide a way to extend your application using a plug-in mechanism. Like Service/Daemon, the shared modules (DSO) manipulation changes a lot on Windows and POSIX.

Obtain simple thing like paths, arguments, manipulate signal, can be annoying, since it also don't has a common interface to do this on both systems.

Boost.Application library aims to make significantly easier for the developer has your application runs in cross-platform (POSIX/Windows) environment. Boost.Application provides a application environment, or start point to any people that want a basic infrastructure to build an system application on Windows or Unix Variants (e.g. Solaris, Linux, MacOS).

The Boost.Application uses behaviours modeled using 'aspects' concept proposed by 'Vicente J. Botet Escriba', that allow easy extension and customization of library components. The application modes uses these components internally to achieve the user desirable behaviours.

Boost.Application provide many usefull ready-to-use features, e.g:

  • Run application as Windows Service;
  • Run application as UNIX/POSIX Daemon;
  • Plugin extension system;
  • Process(executable) Single instance Instantiation support;
  • Application SIGNAL/Callbacks customization;

Here's a simple example of how to construct a application with Boost.Application:

#include <iostream>
#include <boost/application.hpp>

using namespace boost;

1class myapp
{
public:

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

   3int operator()()
   {

      4application::csbl::shared_ptr<application::args> myargs
         = context_.find<application::args>();

      if (myargs)
      {
         const std::vector<std::string> &arg_vector = myargs->arg_vector();

         // only print args on screen
         for(std::vector<std::string>::const_iterator it = arg_vector.begin();
            it != arg_vector.end(); ++it) {
            std::cout << *it << std::endl;
         }
      }

      5// code your application

      return 0;
   }

private:

   6application::context& context_;

};

// main

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

   8myapp app(app_context);

   9app_context.insert<application::args>(
      application::csbl::make_shared<application::args>(argc, argv));

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

1

Define application functor class

2

Define the constructor that will receive a application context

3

Define the application operator

4

Make use of an'aspect'

5

Add other application logic

6

Application context to hold aspects

7

Create a context application aspect pool

8

Instantiate your application

9

Add an aspect for future use. An 'aspect' can be customized, or new aspects can be created

10

Start the application on the desired mode (common, server)

Refer to "road map" to know all required/optional steps to build a complete application using Boost.Application. To high level design overview, refer to '"design overview"'

[Caution] Caution

This documentatuion is in "Work in Progress" status. DOWNLOAD THE LIB

Last revised: October 07, 2014 at 14:13:45 GMT


Next