From 1e6e11bf7830c7356191a8dd70c2615fe44643ef Mon Sep 17 00:00:00 2001 From: "brian.kim" Date: Sun, 18 Jul 2021 15:05:21 +0000 Subject: [PATCH] support asio standalone (#3) --- .gitignore | 135 ++++++++++++++++++ include/boost/application/asio_wrapper.hpp | 34 +++++ .../aspects/limit_single_instance.hpp | 14 +- include/boost/application/aspects/path.hpp | 30 ++-- .../boost/application/aspects/selfpipe.hpp | 6 +- include/boost/application/auto_app.hpp | 8 +- .../boost/application/common_application.hpp | 2 +- include/boost/application/config.hpp | 26 ++++ include/boost/application/context.hpp | 33 +++-- .../detail/ensure_single_instance.hpp | 6 +- .../detail/posix/common_application_impl.hpp | 2 +- .../posix/limit_single_instance_impl.hpp | 2 +- .../application/detail/posix/path_impl.hpp | 53 ++++--- .../detail/posix/server_application_impl.hpp | 8 +- .../windows/common_application_impl.hpp | 2 +- .../windows/limit_single_instance_impl.hpp | 2 +- .../application/detail/windows/path_impl.hpp | 6 +- .../windows/server_application_impl.hpp | 4 +- include/boost/application/launch.hpp | 14 +- .../boost/application/server_application.hpp | 2 +- include/boost/application/signal_binder.hpp | 114 +++++++++++++-- include/boost/application/system_error.hpp | 14 +- 22 files changed, 415 insertions(+), 102 deletions(-) create mode 100644 .gitignore create mode 100644 include/boost/application/asio_wrapper.hpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..a44e16f --- /dev/null +++ b/.gitignore @@ -0,0 +1,135 @@ +# project +buildnumber +src/version.h +build/** +build-debug/** +build-release/** +nbproject/** +run/** +*.log** +*.xml +*nbproject* +*.swp +/version.toml +cmake/FindCustom** +.vscode +*.bak + +## Directory-based project format: +deploy/** +cmake-build*/** +cmake-rapid*/** +.idea/ +**/.idea/ +*/.idea +*/.idea/** +*.swp +tests/log/** +vendor/lib/** +vendor/pkg/** +vendor/bin/** +vendor-old/** +vendor-old/**/* +opt/** +dist-**/ + +# C++ +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# C +# Object files +*.o +*.ko +*.obj +*.elf + +# Precompiled Headers +*.gch +*.pch + +# Libraries +*.lib +*.a +*.la +*.lo + +# Shared objects (inc. Windows DLLs) +*.dll +*.so +*.so.* +*.dylib + +# Executables +*.exe +*.out +*.app +*.i*86 +*.x86_64 +*.hex + +# Debug files +*.dSYM/ + +# MAC OS X +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + + +# Linux +*~ + +# KDE directory preferences +.directory + +# Linux trash folder which might appear on any partition or disk +.Trash-* diff --git a/include/boost/application/asio_wrapper.hpp b/include/boost/application/asio_wrapper.hpp new file mode 100644 index 0000000..b341d6c --- /dev/null +++ b/include/boost/application/asio_wrapper.hpp @@ -0,0 +1,34 @@ +#ifndef BOOST_APPLICATION_ASIO_WRAPPER_HPP +#define BOOST_APPLICATION_ASIO_WRAPPER_HPP + +#ifdef ASIO_STANDALONE +#include +#include +#include +#include +#else +#include +#include +#include +#endif + +namespace boost { namespace application { + +#ifdef ASIO_STANDALONE + +using aio = asio::io_context; +using error_code_t = asio::error_code; +using system_error_t = asio::system_error; +namespace fs = std::filesystem; + +#else + +using aio = boost::asio::io_context; +using error_code_t = boost::system::error_code; +using system_error_t = boost::system::system_error; +namespace fs = boost::filesystem; +#endif + +}} // boost::application + +#endif diff --git a/include/boost/application/aspects/limit_single_instance.hpp b/include/boost/application/aspects/limit_single_instance.hpp index 1a69879..8d6ed87 100644 --- a/include/boost/application/aspects/limit_single_instance.hpp +++ b/include/boost/application/aspects/limit_single_instance.hpp @@ -56,7 +56,7 @@ namespace boost { namespace application { * running on current operating system. * */ - virtual bool lock(boost::system::error_code &ec) = 0; + virtual bool lock(error_code_t& ec) = 0; virtual bool lock() = 0; virtual bool is_another_instance_running() = 0; @@ -132,7 +132,7 @@ namespace boost { namespace application { } /*! - * Creates a system mutex, the ec ( boost::system::error_code& ec) + * Creates a system mutex, the ec ( error_code_t& ec) * will be set to the result of the operation, they should be * tested for errors. * @@ -144,7 +144,7 @@ namespace boost { namespace application { * running on current operating system. * */ - bool lock(boost::system::error_code &ec) + bool lock(error_code_t& ec) { std::string instance_id = to_upper_copy(boost::lexical_cast(uuid_)); @@ -178,7 +178,7 @@ namespace boost { namespace application { * */ bool lock() { - boost::system::error_code ec; + error_code_t ec; bool result = lock(ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( @@ -260,7 +260,7 @@ namespace boost { namespace application { {} /*! - * Creates a system mutex, the ec ( boost::system::error_code& ec) + * Creates a system mutex, the ec ( error_code_t& ec) * will be set to the result of the operation, they should be * tested for errors. * @@ -272,7 +272,7 @@ namespace boost { namespace application { * running on current operating system. * */ - bool lock(boost::system::error_code &ec) { + bool lock(error_code_t& ec) { return impl_->lock(uuid_, ec); } @@ -286,7 +286,7 @@ namespace boost { namespace application { * */ bool lock() { - boost::system::error_code ec; + error_code_t ec; bool result = lock(ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( diff --git a/include/boost/application/aspects/path.hpp b/include/boost/application/aspects/path.hpp index dec9550..8cd7052 100644 --- a/include/boost/application/aspects/path.hpp +++ b/include/boost/application/aspects/path.hpp @@ -28,77 +28,77 @@ namespace boost { namespace application { public: path() : impl_(new detail::default_path_impl) {} - filesystem::path current_path(void) + fs::path current_path(void) { return impl_->current_path(); } - filesystem::path location(boost::system::error_code &ec) + fs::path location(error_code_t& ec) { return impl_->location(ec); } - filesystem::path location() + fs::path location() { return impl_->location(); } - filesystem::path executable_path_name(boost::system::error_code &ec) + fs::path executable_path_name(error_code_t& ec) { return impl_->location(ec); } - filesystem::path executable_path_name() + fs::path executable_path_name() { return impl_->location(); } - filesystem::path executable_path(boost::system::error_code &ec) + fs::path executable_path(error_code_t& ec) { return location(ec).parent_path(); } - filesystem::path executable_path() + fs::path executable_path() { return impl_->location().parent_path(); } - filesystem::path executable_full_name(boost::system::error_code &ec) + fs::path executable_full_name(error_code_t& ec) { return impl_->location(ec).filename(); } - filesystem::path executable_full_name(void) + fs::path executable_full_name(void) { return impl_->location().filename(); } - filesystem::path executable_name(boost::system::error_code &ec) + fs::path executable_name(error_code_t& ec) { return impl_->location(ec).stem(); } - filesystem::path executable_name(void) + fs::path executable_name(void) { return impl_->location().stem(); } - filesystem::path home_path(void) + fs::path home_path(void) { return impl_->home_path(); } - filesystem::path config_path(void) + fs::path config_path(void) { return impl_->config_path(); } - filesystem::path app_data_path(void) + fs::path app_data_path(void) { return impl_->app_data_path(); } - filesystem::path temp_path(void) + fs::path temp_path(void) { return impl_->temp_path(); } diff --git a/include/boost/application/aspects/selfpipe.hpp b/include/boost/application/aspects/selfpipe.hpp index b945a62..5f155d4 100644 --- a/include/boost/application/aspects/selfpipe.hpp +++ b/include/boost/application/aspects/selfpipe.hpp @@ -44,7 +44,7 @@ namespace boost { namespace application { selfpipe() { - boost::system::error_code ec; + error_code_t ec; setup(ec); @@ -52,7 +52,7 @@ namespace boost { namespace application { "selfpipe() failed", ec); } - selfpipe(boost::system::error_code &ec) + selfpipe(error_code_t& ec) { setup(ec); } @@ -64,7 +64,7 @@ namespace boost { namespace application { protected: - void setup(boost::system::error_code &ec) + void setup(error_code_t& ec) { if (pipe(fd_) == -1) { diff --git a/include/boost/application/auto_app.hpp b/include/boost/application/auto_app.hpp index ec30690..059a86f 100644 --- a/include/boost/application/auto_app.hpp +++ b/include/boost/application/auto_app.hpp @@ -80,7 +80,7 @@ namespace boost { namespace application { static int start() { - system::error_code ec; int ret = 0; + error_code_t ec; int ret = 0; ret = auto_app::start(ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( @@ -119,7 +119,7 @@ namespace boost { namespace application { static int start(uuids::uuid& appid) { - system::error_code ec; int ret = 0; + error_code_t ec; int ret = 0; ret = auto_app::start(appid, ec); @@ -156,7 +156,7 @@ namespace boost { namespace application { static int start(int argc, character_types::char_type *argv[]) { - system::error_code ec; int ret = 0; + error_code_t ec; int ret = 0; ret = auto_app::start(argc, argv, ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( @@ -200,7 +200,7 @@ namespace boost { namespace application { static int start(int argc, character_types::char_type *argv[], uuids::uuid& appid) { - system::error_code ec; int ret = 0; + error_code_t ec; int ret = 0; ret = auto_app::start(argc, argv, appid, ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( diff --git a/include/boost/application/common_application.hpp b/include/boost/application/common_application.hpp index 84919e6..d87c3ae 100644 --- a/include/boost/application/common_application.hpp +++ b/include/boost/application/common_application.hpp @@ -87,7 +87,7 @@ namespace boost { namespace application { template common(Application& myapp, SignalManager &sm, application::context &context, - boost::system::error_code& ec) + error_code_t& ec) : impl_(new common_application_impl( boost::bind(&Application::operator(), &myapp), sm, context, ec)) { diff --git a/include/boost/application/config.hpp b/include/boost/application/config.hpp index de4454b..c20c8bb 100644 --- a/include/boost/application/config.hpp +++ b/include/boost/application/config.hpp @@ -29,6 +29,7 @@ #include #include +#include #include #include @@ -183,12 +184,21 @@ // THROW your own EXCEPTION #if defined(BOOST_APPLICATION_TROWN_MY_OWN_EXCEPTION) +#ifdef ASIO_STANDALONE +#define BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR(what) \ + BOOST_APPLICATION_TROWN_MY_OWN_EXCEPTION( \ + what " : " + ::asio::error_code( \ + last_error(), \ + ::asio::system_category()).message(), \ + last_error()) +#else #define BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR(what) \ BOOST_APPLICATION_TROWN_MY_OWN_EXCEPTION( \ what " : " + boost::system::error_code( \ last_error(), \ boost::system::system_category()).message(), \ last_error()) +#endif #define BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC(what, ec) \ BOOST_APPLICATION_TROWN_MY_OWN_EXCEPTION( \ @@ -199,18 +209,34 @@ // use this version if you have not recovered the 'c' ie right after the error. // this version recovery 'ec' internaly. +#ifdef ASIO_STANDALONE +#define BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR(what) \ + BOOST_APPLICATION_THROW(system_error_t( \ + error_code_t(last_error(), \ + ::asio::system_category()), \ + BOOST_APPLICATION_SOURCE_LOCATION what)) +#else #define BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR(what) \ BOOST_APPLICATION_THROW(boost::system::system_error( \ boost::system::error_code(last_error(), \ boost::system::system_category()), \ BOOST_APPLICATION_SOURCE_LOCATION what)) +#endif // use this version when you already have the value of 'ec', ie you already // called 'last_error'. +#ifdef ASIO_STANDALONE +#define BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC(what, ec) \ + BOOST_APPLICATION_THROW(::asio::system_error( \ + ec, BOOST_APPLICATION_SOURCE_LOCATION what)) + +#else #define BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC(what, ec) \ BOOST_APPLICATION_THROW(boost::system::system_error( \ ec, BOOST_APPLICATION_SOURCE_LOCATION what)) #endif +#endif + #endif // BOOST_APPLICATION_CONFIG_HPP diff --git a/include/boost/application/context.hpp b/include/boost/application/context.hpp index e3dad7d..c4ca251 100644 --- a/include/boost/application/context.hpp +++ b/include/boost/application/context.hpp @@ -98,7 +98,7 @@ namespace boost { namespace application { public: static inline csbl::shared_ptr create() { - boost::system::error_code ec; + error_code_t ec; create(ec); if(ec) @@ -107,14 +107,19 @@ namespace boost { namespace application { return instance_t::ptr; } - static inline csbl::shared_ptr create(boost::system::error_code &ec) BOOST_NOEXCEPT { + static inline csbl::shared_ptr create(error_code_t& ec) BOOST_NOEXCEPT { boost::lock_guard u_guard(instance_t::lock); ec.clear(); if(already_created()) { - ec = boost::system::error_code( + ec = error_code_t( +#ifdef ASIO_STANDALONE + static_cast(std::errc::file_exists), + std::generic_category() +#else boost::system::errc::file_exists, boost::system::generic_category() +#endif ); return csbl::shared_ptr(); @@ -125,21 +130,26 @@ namespace boost { namespace application { } static inline void destroy() { - boost::system::error_code ec; + error_code_t ec; destroy(ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC("no global context to destroy", ec); } - static inline void destroy(boost::system::error_code &ec) BOOST_NOEXCEPT { + static inline void destroy(error_code_t& ec) BOOST_NOEXCEPT { boost::lock_guard u_guard(instance_t::lock); ec.clear(); if(!already_created()) { - ec = boost::system::error_code( + ec = error_code_t( +#ifdef ASIO_STANDALONE + static_cast(std::errc::bad_file_descriptor), + std::generic_category() +#else boost::system::errc::bad_file_descriptor, boost::system::generic_category() +#endif ); return; } @@ -148,7 +158,7 @@ namespace boost { namespace application { } static inline csbl::shared_ptr get() { - boost::system::error_code ec; + error_code_t ec; csbl::shared_ptr cxt =get(ec); if(ec) @@ -157,14 +167,19 @@ namespace boost { namespace application { return cxt; } - static inline csbl::shared_ptr get(boost::system::error_code &ec) BOOST_NOEXCEPT { + static inline csbl::shared_ptr get(error_code_t& ec) BOOST_NOEXCEPT { boost::shared_lock_guard s_guard(instance_t::lock); ec.clear(); if(!already_created()) { - ec = boost::system::error_code( + ec = error_code_t( +#ifdef ASIO_STANDALONE + static_cast(std::errc::bad_file_descriptor), + std::generic_category() +#else boost::system::errc::bad_file_descriptor, boost::system::generic_category() +#endif ); return csbl::shared_ptr(); } diff --git a/include/boost/application/detail/ensure_single_instance.hpp b/include/boost/application/detail/ensure_single_instance.hpp index cb5b146..27b6934 100644 --- a/include/boost/application/detail/ensure_single_instance.hpp +++ b/include/boost/application/detail/ensure_single_instance.hpp @@ -27,7 +27,7 @@ namespace boost { namespace application { namespace detail { // returns true to indicate that application needs exit. inline bool check(context &cxt, - boost::system::error_code& ec) + error_code_t& ec) { csbl::shared_ptr ol = cxt.find(); @@ -65,7 +65,7 @@ namespace boost { namespace application { namespace detail { } template struct ensure_single_instance { - bool operator()(T &cxt, boost::system::error_code& ec) + bool operator()(T &cxt, error_code_t& ec) { return check(cxt, ec); } @@ -74,7 +74,7 @@ namespace boost { namespace application { namespace detail { template <> struct ensure_single_instance< global_context_ptr > { bool operator()(global_context_ptr cxt, - boost::system::error_code& ec) + error_code_t& ec) { return check(*cxt.get(), ec); } diff --git a/include/boost/application/detail/posix/common_application_impl.hpp b/include/boost/application/detail/posix/common_application_impl.hpp index f790e1d..2bb6802 100644 --- a/include/boost/application/detail/posix/common_application_impl.hpp +++ b/include/boost/application/detail/posix/common_application_impl.hpp @@ -41,7 +41,7 @@ namespace boost { namespace application { common_application_impl_(const mainop &main, signal_binder &sb, application::context &context, - boost::system::error_code& ec) + error_code_t& ec) : application_impl(context) , main_(main) { diff --git a/include/boost/application/detail/posix/limit_single_instance_impl.hpp b/include/boost/application/detail/posix/limit_single_instance_impl.hpp index c6f8e07..8203407 100644 --- a/include/boost/application/detail/posix/limit_single_instance_impl.hpp +++ b/include/boost/application/detail/posix/limit_single_instance_impl.hpp @@ -53,7 +53,7 @@ namespace boost { namespace application { // If the thread acquires ownership of the mutex, // returns true, if the another thread has ownership // of the mutex, returns false. - bool lock(const uuids::uuid& instance_id, boost::system::error_code &ec) + bool lock(const uuids::uuid& instance_id, error_code_t& ec) { name_ = boost::to_upper_copy(boost::lexical_cast(instance_id)); diff --git a/include/boost/application/detail/posix/path_impl.hpp b/include/boost/application/detail/posix/path_impl.hpp index bf16d95..0b64fe5 100644 --- a/include/boost/application/detail/posix/path_impl.hpp +++ b/include/boost/application/detail/posix/path_impl.hpp @@ -8,7 +8,11 @@ #define BOOST_APPLICATION_DETAIL_POSIX_PATH_FROM_ME_HPP #include -#include +#ifdef ASIO_STANDALONE +# include +#else +# include +#endif #include #include @@ -23,62 +27,69 @@ namespace boost { namespace application { namespace detail { class default_path_impl { - filesystem::path full_path_; + fs::path full_path_; - boost::filesystem::path path_from_me(boost::system::error_code &ec) { - return boost::filesystem::read_symlink("/proc/self/exe", ec); + fs::path path_from_me(error_code_t& ec) { + return fs::read_symlink("/proc/self/exe", ec); } - boost::filesystem::path getenv(const char* env_name) + fs::path getenv(const char* env_name) { const char* res = ::getenv(env_name); - return res ? res : boost::filesystem::path(); + return res ? res : fs::path(); } public: - filesystem::path current_path(void) + fs::path current_path(void) { - return filesystem::current_path(); + return fs::current_path(); } - const filesystem::path& location(boost::system::error_code &ec) + const fs::path& location(error_code_t& ec) { if(!full_path_.empty()) return full_path_; - boost::filesystem::path full_path + fs::path full_path = path_from_me(ec); if(ec) - full_path_ = boost::filesystem::path(); + full_path_ = fs::path(); full_path_ = full_path; return full_path_; } - const filesystem::path& location() + const fs::path& location() { if(!full_path_.empty()) return full_path_; - boost::system::error_code ec; + error_code_t ec; full_path_ = location(ec); if (ec) { +#ifdef ASIO_STANDALONE + boost::throw_exception( + std::system_error( + ec, "location() failed" + )); +#else boost::throw_exception( boost::system::system_error( ec, "location() failed" )); +#endif } return full_path_; } - inline boost::filesystem::path home_path() + inline fs::path home_path() { - boost::filesystem::path path = getenv("HOME"); + fs::path path = getenv("HOME"); if(path.empty()) { struct passwd* pwd = getpwuid(getuid()); @@ -89,9 +100,9 @@ namespace boost { namespace application { namespace detail { return path; } - inline boost::filesystem::path app_data_path() + inline fs::path app_data_path() { - boost::filesystem::path path = getenv("XDG_DATA_HOME"); + fs::path path = getenv("XDG_DATA_HOME"); if(path.empty()) { #if BOOST_OS_MACOS return home_path() / "Library/Preferences/"; @@ -102,10 +113,10 @@ namespace boost { namespace application { namespace detail { return path; } - inline boost::filesystem::path config_path() + inline fs::path config_path() { - boost::filesystem::path path = getenv("XDG_CONFIG_HOME"); + fs::path path = getenv("XDG_CONFIG_HOME"); if(path.empty()) { #if BOOST_OS_MACOS return home_path() / "Library/Preferences/"; @@ -116,9 +127,9 @@ namespace boost { namespace application { namespace detail { return path; } - inline boost::filesystem::path temp_path() + inline fs::path temp_path() { - boost::filesystem::path path = getenv("TMPDIR"); + fs::path path = getenv("TMPDIR"); if(path.empty()) return "/tmp"; // Fallback if TMPDIR not available return path; diff --git a/include/boost/application/detail/posix/server_application_impl.hpp b/include/boost/application/detail/posix/server_application_impl.hpp index 568f172..6bb6fe4 100644 --- a/include/boost/application/detail/posix/server_application_impl.hpp +++ b/include/boost/application/detail/posix/server_application_impl.hpp @@ -83,7 +83,7 @@ namespace boost { namespace application { typedef std::basic_string string_type; server_application_impl_(const mainop &main, signal_binder &sb, - application::context &context, boost::system::error_code& ec) + application::context &context, error_code_t& ec) : application_impl(context) , main_(main) { @@ -124,7 +124,7 @@ namespace boost { namespace application { // redirect_fds(): redirect stdin, stdout, and stderr to /dev/NULL */ - void redirect_fds(boost::system::error_code &ec) + void redirect_fds(error_code_t& ec) { (void) close(0); (void) close(1); @@ -165,7 +165,7 @@ namespace boost { namespace application { return status; } - int daemon(int nochdir, int noclose, boost::system::error_code &ec) + int daemon(int nochdir, int noclose, error_code_t& ec) { int status = 0; @@ -221,7 +221,7 @@ namespace boost { namespace application { // penalty that it incurs is the time and memory required to duplicate the // parent's page tables, and to create a unique task structure for the child. - pid_t daemonize(boost::system::error_code &ec) + pid_t daemonize(error_code_t& ec) { // ignore terminal stop signals #ifdef SIGTTOU diff --git a/include/boost/application/detail/windows/common_application_impl.hpp b/include/boost/application/detail/windows/common_application_impl.hpp index 215556f..f9841f0 100644 --- a/include/boost/application/detail/windows/common_application_impl.hpp +++ b/include/boost/application/detail/windows/common_application_impl.hpp @@ -41,7 +41,7 @@ namespace boost { namespace application { common_application_impl_(const mainop &main_op, signal_binder &sb, application::context &context, - boost::system::error_code& ec) + error_code_t& ec) : application_impl(context) , main_(main_op) { diff --git a/include/boost/application/detail/windows/limit_single_instance_impl.hpp b/include/boost/application/detail/windows/limit_single_instance_impl.hpp index f47fab4..d51a2c3 100644 --- a/include/boost/application/detail/windows/limit_single_instance_impl.hpp +++ b/include/boost/application/detail/windows/limit_single_instance_impl.hpp @@ -44,7 +44,7 @@ namespace boost { namespace application { release(); } - bool lock(const uuids::uuid& instance_id, boost::system::error_code &ec) + bool lock(const uuids::uuid& instance_id, error_code_t& ec) { // Make sure that you use a name that is unique for this application otherwise // two apps may think they are the same if they are using same name for diff --git a/include/boost/application/detail/windows/path_impl.hpp b/include/boost/application/detail/windows/path_impl.hpp index a343c61..484dcc5 100644 --- a/include/boost/application/detail/windows/path_impl.hpp +++ b/include/boost/application/detail/windows/path_impl.hpp @@ -31,7 +31,7 @@ namespace boost { namespace application { namespace detail { { filesystem::path full_path_; - static boost::filesystem::path path_from_me(boost::system::error_code &ec) { + static boost::filesystem::path path_from_me(error_code_t& ec) { boost::filesystem::path ret; // A handle to the loaded module whose path is being requested. @@ -110,7 +110,7 @@ namespace boost { namespace application { namespace detail { return filesystem::current_path(); } - const filesystem::path& location(boost::system::error_code &ec) + const filesystem::path& location(error_code_t& ec) { if ( full_path_.empty( ) ) { @@ -123,7 +123,7 @@ namespace boost { namespace application { namespace detail { { if ( full_path_.empty( ) ) { - boost::system::error_code ec; + error_code_t ec; full_path_ = location( ec ); diff --git a/include/boost/application/detail/windows/server_application_impl.hpp b/include/boost/application/detail/windows/server_application_impl.hpp index 9664900..7a84a65 100644 --- a/include/boost/application/detail/windows/server_application_impl.hpp +++ b/include/boost/application/detail/windows/server_application_impl.hpp @@ -59,7 +59,7 @@ namespace boost { namespace application { typedef std::basic_string string_type; server_application_impl_(const mainop &main_op, signal_binder &sb, - application::context &context, boost::system::error_code& ec) + application::context &context, error_code_t& ec) : application_impl(context) , main_(main_op) , launch_thread_(0) @@ -89,7 +89,7 @@ namespace boost { namespace application { protected: - void initialize(boost::system::error_code& ec) + void initialize(error_code_t& ec) { if(instance_ == 0) instance_ = this; diff --git a/include/boost/application/launch.hpp b/include/boost/application/launch.hpp index ea1d4e1..b07ba36 100644 --- a/include/boost/application/launch.hpp +++ b/include/boost/application/launch.hpp @@ -44,7 +44,7 @@ namespace boost { namespace application { // receive a boost::system::error_code variable 'ec' launch versions /*! - * Creates a application, the ec ( boost::system::error_code& ec) + * Creates a application, the ec ( error_code_t& ec) * will be set to the result of the operation, they should be * tested for errors. * @@ -70,7 +70,7 @@ namespace boost { namespace application { template inline int launch(Application& app, CustomType& ct, Context &cxt, - system::error_code& ec) { + error_code_t& ec) { // the ensure_single_instance tell us to exit? bool we_need_exit = detail::ensure_single_instance()(cxt, ec); @@ -91,12 +91,12 @@ namespace boost { namespace application { template inline int launch(Application& app, CustomType& ct, global_context_ptr cxt, - system::error_code& ec) { + error_code_t& ec) { return launch(app, ct, *cxt.get(), ec); } /*! - * Creates a application, the ec ( boost::system::error_code& ec) + * Creates a application, the ec ( error_code_t& ec) * will be set to the result of the operation, they should be * tested for errors. * @@ -116,7 +116,7 @@ namespace boost { namespace application { * */ template - inline int launch(Application& app, Context &cxt, system::error_code& ec) { + inline int launch(Application& app, Context &cxt, error_code_t& ec) { signal_manager ct(cxt, ec); // our default custom type if(ec) return 0; @@ -154,7 +154,7 @@ namespace boost { namespace application { template inline int launch(Application& app, CustomType& ct, Context &cxt) { - system::error_code ec; int ret = 0; + error_code_t ec; int ret = 0; ret = launch(app, ct, cxt, ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( @@ -186,7 +186,7 @@ namespace boost { namespace application { */ template inline int launch(Application& app, Context &cxt) { - system::error_code ec; int ret = 0; + error_code_t ec; int ret = 0; ret = launch(app, cxt, ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( diff --git a/include/boost/application/server_application.hpp b/include/boost/application/server_application.hpp index 7e76772..c599b16 100644 --- a/include/boost/application/server_application.hpp +++ b/include/boost/application/server_application.hpp @@ -85,7 +85,7 @@ namespace boost { namespace application { */ template server(Application& myapp, SignalManager &sm, - application::context &context, boost::system::error_code& ec) { + application::context &context, error_code_t& ec) { // default aspects patterns added to this kind of application if(!context.find()) diff --git a/include/boost/application/signal_binder.hpp b/include/boost/application/signal_binder.hpp index a8add1d..381648d 100644 --- a/include/boost/application/signal_binder.hpp +++ b/include/boost/application/signal_binder.hpp @@ -54,18 +54,30 @@ namespace boost { namespace application { : signals_(io_service_) , context_(cxt) { signals_.async_wait( +#ifdef ASIO_STANDALONE + std::bind(&signal_binder::signal_handler, this, + std::placeholders::_1, + std::placeholders::_2)); +#else boost::bind(&signal_binder::signal_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::signal_number)); +#endif } explicit signal_binder(global_context_ptr cxt) : signals_(io_service_) , context_(*cxt.get()) { signals_.async_wait( +#ifdef ASIO_STANDALONE + std::bind(&signal_binder::signal_handler, this, + std::placeholders::_1, + std::placeholders::_2)); +#else boost::bind(&signal_binder::signal_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::signal_number)); +#endif } virtual ~signal_binder() { @@ -86,13 +98,23 @@ namespace boost { namespace application { * arrives. * */ +#ifdef ASIO_STANDALONE void bind(int signal_number, const handler<>& h) { - boost::system::error_code ec; + asio::error_code ec; bind(signal_number, h, handler<>(), ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( "bind() failed", ec); } +#else + void bind(int signal_number, const handler<>& h) { + error_code_t ec; + bind(signal_number, h, handler<>(), ec); + + if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( + "bind() failed", ec); + } +#endif /*! * Bind/tie a standard SIGNAL to a handler callback, and define @@ -107,15 +129,25 @@ namespace boost { namespace application { * first handler return true; * */ +#ifdef ASIO_STANDALONE void bind(int signal_number, const handler<>& h1, const handler<>& h2) { - boost::system::error_code ec; + asio::error_code ec; bind(signal_number, h1, h2, ec); if(ec) BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( "bind() failed", ec); } +#else + void bind(int signal_number, const handler<>& h1, const handler<>& h2) { + error_code_t ec; + bind(signal_number, h1, h2, ec); + if(ec) + BOOST_APPLICATION_THROW_LAST_SYSTEM_ERROR_USING_MY_EC( + "bind() failed", ec); + } +#endif /*! * Bind/tie a standard SIGNAL to a handler callback. 'ec' version. * @@ -125,10 +157,17 @@ namespace boost { namespace application { * arrives. * */ +#ifdef ASIO_STANDALONE + void bind(int signal_number, const handler<>& h, + asio::error_code& ec) { + bind(signal_number, h, handler<>(), ec); + } +#else void bind(int signal_number, const handler<>& h, - boost::system::error_code& ec) { + error_code_t& ec) { bind(signal_number, h, handler<>(), ec); } +#endif /*! * Bind/tie a standard SIGNAL to a handler callback, and define @@ -143,12 +182,19 @@ namespace boost { namespace application { * first handler return true; * */ - void bind(int signal_number, const handler<>& h1, const handler<>& h2, - boost::system::error_code& ec) { +#ifdef ASIO_STANDALONE + void bind(int signal_number, const handler<>& h1, const handler<>& h2, + asio::error_code& ec) { signals_.add(signal_number, ec); handler_map_[signal_number] = std::make_pair(h1, h2); } - +#else + void bind(int signal_number, const handler<>& h1, const handler<>& h2, + error_code_t& ec) { + signals_.add(signal_number, ec); + handler_map_[signal_number] = std::make_pair(h1, h2); + } +#endif /*! * Unbind/untie a standard SIGNAL. * @@ -156,7 +202,11 @@ namespace boost { namespace application { * */ void unbind(int signal_number) { - boost::system::error_code ec; +#ifdef ASIO_STANDALONE + asio::error_code ec; +#else + error_code_t ec; +#endif unbind(signal_number, ec); if(ec) @@ -170,7 +220,11 @@ namespace boost { namespace application { * \param signal_number The signal constant, e.g.: SIGUSR2, SIGINT. * */ - void unbind(int signal_number, boost::system::error_code& ec) { +#ifdef ASIO_STANDALONE + void unbind(int signal_number, asio::error_code& ec) { +#else + void unbind(int signal_number, error_code_t& ec) { +#endif if(handler_map_.cend() != handler_map_.find(signal_number)) { // replace @@ -200,20 +254,35 @@ namespace boost { namespace application { io_service_.run(); } - void signal_handler(const boost::system::error_code& ec, +#ifdef ASIO_STANDALONE + void signal_handler(const asio::error_code& ec, + int signal_number) { +#else + void signal_handler(const error_code_t& ec, int signal_number) { +#endif spawn(ec, signal_number); // triggers again signals_.async_wait( +#ifdef ASIO_STANDALONE + std::bind(&signal_binder::signal_handler, this, + std::placeholders::_1, + std::placeholders::_2)); +#else boost::bind(&signal_binder::signal_handler, this, boost::asio::placeholders::error, boost::asio::placeholders::signal_number)); +#endif } protected: - void spawn(const boost::system::error_code& ec, int signal_number) { +#ifdef ASIO_STANDALONE + void spawn(const asio::error_code& ec, int signal_number) { +#else + void spawn(const error_code_t& ec, int signal_number) { +#endif if (ec) return; @@ -238,9 +307,13 @@ namespace boost { namespace application { // if first handler returns true, the second handler are called csbl::unordered_map, handler<> > > handler_map_; +#ifdef ASIO_STANDALONE + ::asio::io_service io_service_; + ::asio::signal_set signals_; +#else asio::io_service io_service_; asio::signal_set signals_; - +#endif csbl::shared_ptr io_service_thread_; protected: @@ -260,8 +333,13 @@ namespace boost { namespace application { { public: +#ifdef ASIO_STANDALONE + signal_manager(application::context &context, + asio::error_code& ec) +#else signal_manager(application::context &context, - boost::system::error_code& ec) + error_code_t& ec) +#endif : signal_binder(context) { register_signals(ec); @@ -270,7 +348,11 @@ namespace boost { namespace application { signal_manager(application::context &context) : signal_binder(context) { - boost::system::error_code ec; +#ifdef ASIO_STANDALONE + asio::error_code ec; +#else + error_code_t ec; +#endif register_signals(ec); @@ -298,7 +380,11 @@ namespace boost { namespace application { // parameter context version - virtual void register_signals(boost::system::error_code& ec) +#ifdef ASIO_STANDALONE + virtual void register_signals(asio::error_code& ec) +#else + virtual void register_signals(error_code_t& ec) +#endif { csbl::shared_ptr th = setup_termination_behaviour(); diff --git a/include/boost/application/system_error.hpp b/include/boost/application/system_error.hpp index 2a657da..5d7bdb4 100644 --- a/include/boost/application/system_error.hpp +++ b/include/boost/application/system_error.hpp @@ -7,10 +7,8 @@ #ifndef BOOST_APPLICATION_SYSTEM_ERROR_HPP #define BOOST_APPLICATION_SYSTEM_ERROR_HPP +#include #include -#include -#include -#include #if defined(BOOST_POSIX_API) # include @@ -56,11 +54,19 @@ namespace boost { namespace application { * function (System Error). * */ - inline system::error_code last_error_code() BOOST_NOEXCEPT +#ifdef ASIO_STANDALONE + inline error_code_t last_error_code() BOOST_NOEXCEPT + { + return ::asio::error_code(last_error(), + asio::system_category()); + } +#else + inline error_code_t last_error_code() BOOST_NOEXCEPT { return boost::system::error_code(last_error(), boost::system::system_category()); } +#endif }}// boost::application