From 024ec0da9931700f25a89e8d80e02f555fe1310a Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Mon, 29 May 2017 18:47:41 -0500 Subject: [PATCH 1/4] Add support for required plugins at startup If no plugins are configured to be started in the config file, apps start up, register no plugins, and do nothing. This is almost guaranteed to be wrong behavior in all situations, so it should be easy to specify some plugins that should always be started. This commit makes this so. --- application.cpp | 18 +++++++++--------- include/appbase/application.hpp | 24 ++++++++++++++++-------- 2 files changed, 25 insertions(+), 17 deletions(-) diff --git a/application.cpp b/application.cpp index d6006794f..a1868e220 100644 --- a/application.cpp +++ b/application.cpp @@ -33,6 +33,11 @@ application::application() application::~application() { } +void application::startup() { + for (auto plugin : initialized_plugins) + plugin->startup(); +} + application& application::instance() { static application _app; return _app; @@ -70,9 +75,7 @@ void application::set_program_options() my->_app_options.add(app_cli_opts); } - -bool application::initialize( int argc, char** argv ) -{ +bool application::initialize_impl(int argc, char** argv, vector autostart_plugins) { set_program_options(); bpo::variables_map options; @@ -117,18 +120,15 @@ bool application::initialize( int argc, char** argv ) get_plugin(name).initialize(options); } } + for (auto plugin : autostart_plugins) + if (plugin != nullptr && plugin->get_state() == abstract_plugin::registered) + plugin->initialize(options); bpo::notify(options); return true; } -void application::startup() -{ - for(auto plug : initialized_plugins) - plug->startup(); -} - void application::shutdown() { for(auto ritr = running_plugins.rbegin(); ritr != running_plugins.rend(); ++ritr) { diff --git a/include/appbase/application.hpp b/include/appbase/application.hpp index 231148cd5..6b81844df 100644 --- a/include/appbase/application.hpp +++ b/include/appbase/application.hpp @@ -14,21 +14,27 @@ namespace appbase { ~application(); /** - * Looks for the --plugin commandline / config option and calls initialize on those plugins + * @brief Looks for the --plugin commandline / config option and calls initialize on those plugins * - * @return true if the application and plugins were initialized, false or exception on error + * @tparam Plugin List of plugins to initalize even if not mentioned by configuration. For plugins started by + * configuration settings or dependency resolution, this template has no effect. + * @return true if the application and plugins were initialized, false or exception on error */ - bool initialize(int argc, char** argv); - void startup(); - void shutdown(); + template + bool initialize(int argc, char** argv) { + return initialize_impl(argc, argv, {find_plugin()...}); + } + + void startup(); + void shutdown(); /** * Wait until quit(), SIGINT or SIGTERM and then shutdown */ - void exec(); - void quit(); + void exec(); + void quit(); - static application& instance(); + static application& instance(); abstract_plugin* find_plugin(const string& name)const; abstract_plugin& get_plugin(const string& name)const; @@ -66,6 +72,8 @@ namespace appbase { template friend class plugin; + bool initialize_impl(int argc, char** argv, vector autostart_plugins); + /** these notifications get called from the plugin when their state changes so that * the application can call shutdown in the reverse order. */ From 754b9d19783e008aa783a12465594f1fe2a49c29 Mon Sep 17 00:00:00 2001 From: Nathan Hourt Date: Wed, 31 May 2017 15:39:24 -0500 Subject: [PATCH 2/4] [IDE Support] Add headers to CMakeLists.txt By listing headers among the sources, we don't confuse cmake at all since it knows better than to compile those, but we do make life easier on IDEs with CMake support, since the IDE will now pick up the headers as more source code for the project. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index ffda29459..b1c256ca4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,6 +40,7 @@ endif() add_library( appbase application.cpp + ${HEADERS} ) target_link_libraries( appbase ${Boost_LIBRARIES}) From fe1035028d6d6cf142ea463ce7539c6e66e83545 Mon Sep 17 00:00:00 2001 From: Jonathan Giszczak Date: Mon, 13 Nov 2017 14:49:06 -0600 Subject: [PATCH 3/4] Version handling, required to resolve #664 --- application.cpp | 19 +++++++++++++++++-- include/appbase/application.hpp | 10 ++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/application.cpp b/application.cpp index 93e900dc8..369872527 100644 --- a/application.cpp +++ b/application.cpp @@ -22,7 +22,9 @@ class application_impl { options_description _app_options; options_description _cfg_options; - bfs::path _data_dir; + bfs::path _data_dir; + + string _version; }; application::application() @@ -32,6 +34,14 @@ application::application() application::~application() { } +void application::set_version(string version) { + my->_version = version; +} + +string application::version() const { + return my->_version; +} + void application::startup() { for (auto plugin : initialized_plugins) plugin->startup(); @@ -81,7 +91,12 @@ bool application::initialize_impl(int argc, char** argv, vector_app_options), options); if( options.count( "help" ) ) { - cout << my->_app_options << "\n"; + cout << my->_app_options << std::endl; + return false; + } + + if( options.count( "version" ) ) { + cout << my->_version << std::endl; return false; } diff --git a/include/appbase/application.hpp b/include/appbase/application.hpp index 985a608a4..e857de015 100644 --- a/include/appbase/application.hpp +++ b/include/appbase/application.hpp @@ -13,6 +13,16 @@ namespace appbase { public: ~application(); + /** @brief Sets version string + * + * @param version Version string output verbatim with -v/--version + */ + void set_version(string version); + /** @brief Gets version string + * + * @return Version string output with -v/--version + */ + string version() const; /** * @brief Looks for the --plugin commandline / config option and calls initialize on those plugins * From bf9a9ffe605056d32f1c741b80b78fe6773c821b Mon Sep 17 00:00:00 2001 From: Jonathan Giszczak Date: Tue, 14 Nov 2017 10:51:03 -0600 Subject: [PATCH 4/4] Add integer version number as well. --- application.cpp | 9 +++++++++ include/appbase/application.hpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/application.cpp b/application.cpp index 369872527..0f5e6a76b 100644 --- a/application.cpp +++ b/application.cpp @@ -25,6 +25,7 @@ class application_impl { bfs::path _data_dir; string _version; + uint64_t _version_int; }; application::application() @@ -38,10 +39,18 @@ void application::set_version(string version) { my->_version = version; } +void application::set_version(uint64_t version) { + my->_version_int = version; +} + string application::version() const { return my->_version; } +uint64_t application::version_int() const { + return my->_version_int; +} + void application::startup() { for (auto plugin : initialized_plugins) plugin->startup(); diff --git a/include/appbase/application.hpp b/include/appbase/application.hpp index e857de015..1d024f537 100644 --- a/include/appbase/application.hpp +++ b/include/appbase/application.hpp @@ -18,11 +18,21 @@ namespace appbase { * @param version Version string output verbatim with -v/--version */ void set_version(string version); + /** @overload + * + * @param version Integer version independent of the string output with -v/--version + */ + void set_version(uint64_t version); /** @brief Gets version string * * @return Version string output with -v/--version */ string version() const; + /** @brief Gets version integer + * + * @return Version integer independent of the string output with -v/--version + */ + uint64_t version_int() const; /** * @brief Looks for the --plugin commandline / config option and calls initialize on those plugins *