~ubuntu-branches/debian/sid/pion/sid

« back to all changes in this revision

Viewing changes to include/pion/process.hpp

  • Committer: Package Import Robot
  • Author(s): Roberto C. Sanchez
  • Date: 2013-07-06 18:04:35 UTC
  • Revision ID: package-import@ubuntu.com-20130706180435-kejjzc1qpyz3qv6c
Tags: upstream-5.0.1+dfsg
ImportĀ upstreamĀ versionĀ 5.0.1+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// ---------------------------------------------------------------------
 
2
// pion:  a Boost C++ framework for building lightweight HTTP interfaces
 
3
// ---------------------------------------------------------------------
 
4
// Copyright (C) 2007-2012 Cloudmeter, Inc.  (http://www.cloudmeter.com)
 
5
//
 
6
// Distributed under the Boost Software License, Version 1.0.
 
7
// See http://www.boost.org/LICENSE_1_0.txt
 
8
//
 
9
 
 
10
#ifndef __PION_PROCESS_HEADER__
 
11
#define __PION_PROCESS_HEADER__
 
12
 
 
13
#include <string>
 
14
#include <boost/noncopyable.hpp>
 
15
#include <boost/thread/once.hpp>
 
16
#include <boost/thread/mutex.hpp>
 
17
#include <boost/thread/condition.hpp>
 
18
#include <pion/config.hpp>
 
19
 
 
20
 
 
21
namespace pion {    // begin namespace pion
 
22
 
 
23
///
 
24
/// process: class for managing process/service related functions
 
25
///
 
26
class PION_API process :
 
27
    private boost::noncopyable
 
28
{
 
29
public:
 
30
 
 
31
    // default destructor
 
32
    ~process() {}
 
33
    
 
34
    /// default constructor
 
35
    process(void) {}
 
36
    
 
37
    /// signals the shutdown condition
 
38
    static void shutdown(void);
 
39
    
 
40
    /// blocks until the shutdown condition has been signaled
 
41
    static void wait_for_shutdown(void);
 
42
 
 
43
    /// sets up basic signal handling for the process
 
44
    static void initialize(void);
 
45
    
 
46
    /// fork process and run as a background daemon
 
47
    static void daemonize(void);
 
48
 
 
49
 
 
50
protected:
 
51
 
 
52
    /// data type for static/global process configuration information
 
53
    struct config_type {
 
54
        /// constructor just initializes native types
 
55
        config_type() : shutdown_now(false) {}
 
56
    
 
57
        /// true if we should shutdown now
 
58
        bool                    shutdown_now;
 
59
        
 
60
        /// triggered when it is time to shutdown
 
61
        boost::condition        shutdown_cond;
 
62
 
 
63
        /// used to protect the shutdown condition
 
64
        boost::mutex            shutdown_mutex;
 
65
    };
 
66
 
 
67
    
 
68
    /// returns a singleton instance of config_type
 
69
    static inline config_type& get_config(void) {
 
70
        boost::call_once(process::create_config, m_instance_flag);
 
71
        return *m_config_ptr;
 
72
    }
 
73
 
 
74
 
 
75
private:
 
76
 
 
77
    /// creates the config_type singleton
 
78
    static void create_config(void);
 
79
 
 
80
    
 
81
    /// used to ensure thread safety of the config_type singleton
 
82
    static boost::once_flag             m_instance_flag;
 
83
 
 
84
    /// pointer to the config_type singleton
 
85
    static config_type *          m_config_ptr;
 
86
};
 
87
 
 
88
 
 
89
}   // end namespace pion
 
90
 
 
91
#endif