process.hpp
// ---------------------------------------------------------------------
// pion: a Boost C++ framework for building lightweight HTTP interfaces
// ---------------------------------------------------------------------
// Copyright (C) 2007-2014 Splunk Inc. (https://github.com/splunk/pion)
//
// Distributed under the Boost Software License, Version 1.0.
// See http://www.boost.org/LICENSE_1_0.txt
//
#ifndef __PION_PROCESS_HEADER__
#define __PION_PROCESS_HEADER__
#include <string>
#include <boost/noncopyable.hpp>
#include <boost/thread/once.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
#include <pion/config.hpp>
// Dump file generation support on Windows
#ifdef _MSC_VER
#include <windows.h>
#include <tchar.h>
#include <DbgHelp.h>
// based on dbghelp.h
typedef BOOL (WINAPI *MINIDUMPWRITEDUMP)(HANDLE hProcess, DWORD dwPid, HANDLE hFile, MINIDUMP_TYPE DumpType,
CONST PMINIDUMP_EXCEPTION_INFORMATION ExceptionParam,
CONST PMINIDUMP_USER_STREAM_INFORMATION UserStreamParam,
CONST PMINIDUMP_CALLBACK_INFORMATION CallbackParam);
#endif
namespace pion { // begin namespace pion
class PION_API process :
private boost::noncopyable
{
public:
// default destructor
~process() {}
process(void) {}
static void shutdown(void);
static void wait_for_shutdown(void);
static void initialize(void);
static void daemonize(void);
#ifdef _MSC_VER
class dumpfile_init_exception : public std::exception
{
public:
dumpfile_init_exception(const std::string& cause) : m_cause(cause) {}
virtual const char* what() const { return m_cause.c_str(); }
protected:
std::string m_cause;
};
static void set_dumpfile_directory(const std::string& dir);
protected:
static LONG WINAPI unhandled_exception_filter(struct _EXCEPTION_POINTERS *pExceptionInfo);
static std::string generate_dumpfile_name();
#endif
protected:
struct config_type {
#ifdef _MSC_VER
config_type() : shutdown_now(false), h_dbghelp(NULL), p_dump_proc(NULL) {}
#else
config_type() : shutdown_now(false) {}
#endif
bool shutdown_now;
boost::condition shutdown_cond;
boost::mutex shutdown_mutex;
// Dump file generation support on Windows
#ifdef _MSC_VER
std::string dumpfile_dir;
HMODULE h_dbghelp;
MINIDUMPWRITEDUMP p_dump_proc;
#endif
};
static inline config_type& get_config(void) {
boost::call_once(process::create_config, m_instance_flag);
return *m_config_ptr;
}
private:
static void create_config(void);
static boost::once_flag m_instance_flag;
static config_type * m_config_ptr;
};
} // end namespace pion
#endif
pion::process::config_type::shutdown_now
bool shutdown_now
true if we should shutdown now
Definition: process.hpp:99
pion::process::config_type::config_type
config_type()
constructor just initializes native types
Definition: process.hpp:95
pion::process::config_type
data type for static/global process configuration information
Definition: process.hpp:90
pion::process::process
process(void)
default constructor
Definition: process.hpp:46
pion::process::config_type::shutdown_mutex
boost::mutex shutdown_mutex
used to protect the shutdown condition
Definition: process.hpp:105
pion::process
Definition: process.hpp:37
pion
Definition: admin_rights.hpp:19
pion::process::config_type::shutdown_cond
boost::condition shutdown_cond
triggered when it is time to shutdown
Definition: process.hpp:102
pion::process::get_config
static config_type & get_config(void)
returns a singleton instance of config_type
Definition: process.hpp:121