From ed4f646cb662cb86b30d9fab1012054968d8a273 Mon Sep 17 00:00:00 2001 From: ejossev Date: Mon, 21 Jan 2019 14:12:25 +0100 Subject: [PATCH 01/17] initial version of the configuration manager --- CMakeDoxyfile.in | 5 + CMakeDoxygenDefaults.cmake | 20 +++- libraries/CMakeLists.txt | 1 + libraries/appbase/application.cpp | 94 +++++++++++-------- .../appbase/include/appbase/application.hpp | 1 + libraries/config/CMakeLists.txt | 38 ++++++++ .../condenser_api/condenser_api_plugin.cpp | 2 +- libraries/plugins/chain/chain_plugin.cpp | 5 +- libraries/plugins/p2p/p2p_plugin.cpp | 4 +- programs/sophiatxd/CMakeLists.txt | 2 + programs/sophiatxd/main.cpp | 5 + 11 files changed, 128 insertions(+), 49 deletions(-) create mode 100644 libraries/config/CMakeLists.txt diff --git a/CMakeDoxyfile.in b/CMakeDoxyfile.in index 255fec08..688769fa 100644 --- a/CMakeDoxyfile.in +++ b/CMakeDoxyfile.in @@ -11,6 +11,7 @@ OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT_DIRECTORY@ CREATE_SUBDIRS = @DOXYGEN_CREATE_SUBDIRS@ ALLOW_UNICODE_NAMES = @DOXYGEN_ALLOW_UNICODE_NAMES@ OUTPUT_LANGUAGE = @DOXYGEN_OUTPUT_LANGUAGE@ +OUTPUT_TEXT_DIRECTION = @DOXYGEN_OUTPUT_TEXT_DIRECTION@ BRIEF_MEMBER_DESC = @DOXYGEN_BRIEF_MEMBER_DESC@ REPEAT_BRIEF = @DOXYGEN_REPEAT_BRIEF@ ABBREVIATE_BRIEF = @DOXYGEN_ABBREVIATE_BRIEF@ @@ -32,6 +33,7 @@ OPTIMIZE_OUTPUT_FOR_C = @DOXYGEN_OPTIMIZE_OUTPUT_FOR_C@ OPTIMIZE_OUTPUT_JAVA = @DOXYGEN_OPTIMIZE_OUTPUT_JAVA@ OPTIMIZE_FOR_FORTRAN = @DOXYGEN_OPTIMIZE_FOR_FORTRAN@ OPTIMIZE_OUTPUT_VHDL = @DOXYGEN_OPTIMIZE_OUTPUT_VHDL@ +OPTIMIZE_OUTPUT_SLICE = @DOXYGEN_OPTIMIZE_OUTPUT_SLICE@ EXTENSION_MAPPING = @DOXYGEN_EXTENSION_MAPPING@ MARKDOWN_SUPPORT = @DOXYGEN_MARKDOWN_SUPPORT@ TOC_INCLUDE_HEADINGS = @DOXYGEN_TOC_INCLUDE_HEADINGS@ @@ -181,6 +183,7 @@ GENERATE_LATEX = @DOXYGEN_GENERATE_LATEX@ LATEX_OUTPUT = @DOXYGEN_LATEX_OUTPUT@ LATEX_CMD_NAME = @DOXYGEN_LATEX_CMD_NAME@ MAKEINDEX_CMD_NAME = @DOXYGEN_MAKEINDEX_CMD_NAME@ +LATEX_MAKEINDEX_CMD = @DOXYGEN_LATEX_MAKEINDEX_CMD@ COMPACT_LATEX = @DOXYGEN_COMPACT_LATEX@ PAPER_TYPE = @DOXYGEN_PAPER_TYPE@ EXTRA_PACKAGES = @DOXYGEN_EXTRA_PACKAGES@ @@ -195,6 +198,7 @@ LATEX_HIDE_INDICES = @DOXYGEN_LATEX_HIDE_INDICES@ LATEX_SOURCE_CODE = @DOXYGEN_LATEX_SOURCE_CODE@ LATEX_BIB_STYLE = @DOXYGEN_LATEX_BIB_STYLE@ LATEX_TIMESTAMP = @DOXYGEN_LATEX_TIMESTAMP@ +LATEX_EMOJI_DIRECTORY = @DOXYGEN_LATEX_EMOJI_DIRECTORY@ GENERATE_RTF = @DOXYGEN_GENERATE_RTF@ RTF_OUTPUT = @DOXYGEN_RTF_OUTPUT@ COMPACT_RTF = @DOXYGEN_COMPACT_RTF@ @@ -210,6 +214,7 @@ MAN_LINKS = @DOXYGEN_MAN_LINKS@ GENERATE_XML = @DOXYGEN_GENERATE_XML@ XML_OUTPUT = @DOXYGEN_XML_OUTPUT@ XML_PROGRAMLISTING = @DOXYGEN_XML_PROGRAMLISTING@ +XML_NS_MEMB_FILE_SCOPE = @DOXYGEN_XML_NS_MEMB_FILE_SCOPE@ GENERATE_DOCBOOK = @DOXYGEN_GENERATE_DOCBOOK@ DOCBOOK_OUTPUT = @DOXYGEN_DOCBOOK_OUTPUT@ DOCBOOK_PROGRAMLISTING = @DOXYGEN_DOCBOOK_PROGRAMLISTING@ diff --git a/CMakeDoxygenDefaults.cmake b/CMakeDoxygenDefaults.cmake index bbe01762..5bebcce5 100644 --- a/CMakeDoxygenDefaults.cmake +++ b/CMakeDoxygenDefaults.cmake @@ -17,6 +17,9 @@ endif() if(NOT DEFINED DOXYGEN_OUTPUT_LANGUAGE) set(DOXYGEN_OUTPUT_LANGUAGE English) endif() +if(NOT DEFINED DOXYGEN_OUTPUT_TEXT_DIRECTION) + set(DOXYGEN_OUTPUT_TEXT_DIRECTION None) +endif() if(NOT DEFINED DOXYGEN_BRIEF_MEMBER_DESC) set(DOXYGEN_BRIEF_MEMBER_DESC YES) endif() @@ -78,6 +81,9 @@ endif() if(NOT DEFINED DOXYGEN_OPTIMIZE_OUTPUT_VHDL) set(DOXYGEN_OPTIMIZE_OUTPUT_VHDL NO) endif() +if(NOT DEFINED DOXYGEN_OPTIMIZE_OUTPUT_SLICE) + set(DOXYGEN_OPTIMIZE_OUTPUT_SLICE NO) +endif() if(NOT DEFINED DOXYGEN_MARKDOWN_SUPPORT) set(DOXYGEN_MARKDOWN_SUPPORT YES) endif() @@ -287,7 +293,8 @@ if(NOT DEFINED DOXYGEN_FILE_PATTERNS) *.vhd *.vhdl *.ucf - *.qsf) + *.qsf + *.ice) endif() if(NOT DEFINED DOXYGEN_RECURSIVE) set(DOXYGEN_RECURSIVE NO) @@ -437,7 +444,7 @@ if(NOT DEFINED DOXYGEN_MATHJAX_FORMAT) set(DOXYGEN_MATHJAX_FORMAT HTML-CSS) endif() if(NOT DEFINED DOXYGEN_MATHJAX_RELPATH) - set(DOXYGEN_MATHJAX_RELPATH https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/) + set(DOXYGEN_MATHJAX_RELPATH https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/) endif() if(NOT DEFINED DOXYGEN_SEARCHENGINE) set(DOXYGEN_SEARCHENGINE YES) @@ -457,12 +464,12 @@ endif() if(NOT DEFINED DOXYGEN_LATEX_OUTPUT) set(DOXYGEN_LATEX_OUTPUT latex) endif() -if(NOT DEFINED DOXYGEN_LATEX_CMD_NAME) - set(DOXYGEN_LATEX_CMD_NAME latex) -endif() if(NOT DEFINED DOXYGEN_MAKEINDEX_CMD_NAME) set(DOXYGEN_MAKEINDEX_CMD_NAME makeindex) endif() +if(NOT DEFINED DOXYGEN_LATEX_MAKEINDEX_CMD) + set(DOXYGEN_LATEX_MAKEINDEX_CMD makeindex) +endif() if(NOT DEFINED DOXYGEN_COMPACT_LATEX) set(DOXYGEN_COMPACT_LATEX NO) endif() @@ -526,6 +533,9 @@ endif() if(NOT DEFINED DOXYGEN_XML_PROGRAMLISTING) set(DOXYGEN_XML_PROGRAMLISTING YES) endif() +if(NOT DEFINED DOXYGEN_XML_NS_MEMB_FILE_SCOPE) + set(DOXYGEN_XML_NS_MEMB_FILE_SCOPE NO) +endif() if(NOT DEFINED DOXYGEN_GENERATE_DOCBOOK) set(DOXYGEN_GENERATE_DOCBOOK NO) endif() diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index aaf47183..4675f966 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -1,4 +1,5 @@ add_subdirectory( fc ) +add_subdirectory( config ) add_subdirectory( schema ) add_subdirectory( appbase ) add_subdirectory( chainbase ) diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index 5344c4e6..a1a2d0a6 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -18,6 +18,55 @@ using bpo::options_description; using bpo::variables_map; using std::cout; +namespace{ +// TODO: delete after HF2 +/** + * @brief Fix which renames default data directory and also moves config into subdirectory configs, so users do not need to do it themselves + * Applies fixes only when users did not specify some custom paths to data-dir and config file + * + * @param actual_data_dir + * @param cfg_data_dir + * @param cfg_config + */ +void fix_deprecated_data_folder_structure(const bfs::path& actual_data_dir, + const boost::program_options::variable_value& cfg_data_dir, + const boost::program_options::variable_value& cfg_config) +{ + // If data_dir has default(new) name and there is existing directory with old name -> rename it + if (cfg_data_dir.defaulted() == true) { + bfs::path deprecated_default_data_dir = bfs::current_path() / "witness_node_data_dir"; + if (bfs::exists(deprecated_default_data_dir) == true) { + bfs::rename(deprecated_default_data_dir, actual_data_dir); + } + } + + // If config with default name exists and is not in subdirectory configs -> move it there + if (cfg_config.defaulted() == true) { + bfs::path deprecated_default_config_path = actual_data_dir / "config.ini"; + if (bfs::exists(deprecated_default_config_path) == true) { + if (bfs::exists(actual_data_dir) == false) { + bfs::create_directory(actual_data_dir); + } + + bfs::path configs_dir = actual_data_dir / "configs/"; + if (bfs::exists(configs_dir) == false) { + bfs::create_directory(configs_dir); + } + + bfs::rename(deprecated_default_config_path, configs_dir / cfg_config.as()); + } + } +} + +void migrate_config_to_json(const bfs::path& actual_data_dir, + const boost::program_options::variable_value& cfg_data_dir, + const boost::program_options::variable_value& cfg_config) +{ + +} + +} + class application_impl { public: @@ -72,7 +121,7 @@ void application::set_program_options() ("help,h", "Print this help message and exit.") ("version,v", "Print version information.") ("data-dir,d", bpo::value()->default_value( "sophia_app_data" ), "Directory containing configuration files, blockchain data and external plugins") - ("config,c", bpo::value()->default_value( "config.ini" ), "Main configuration file path (absolute path or relative to the data-dir/configs/)"); + ("config,c", bpo::value()->default_value( "config.ini" ), "Obsolete. Main configuration file path (absolute path or relative to the data-dir/configs/)"); my->_cfg_options.add(app_cfg_opts); my->_app_options.add(app_cfg_opts); @@ -174,43 +223,6 @@ void application::load_external_plugin_config(const std::shared_ptr_args ); } -// TODO: delete after HF2 -/** - * @brief Fix which renames default data directory and also moves config into subdirectory configs, so users do not need to do it themselves - * Applies fixes only when users did not specify some custom paths to data-dir and config file - * - * @param actual_data_dir - * @param cfg_data_dir - * @param cfg_config - */ -void fix_deprecated_data_folder_structure(const bfs::path& actual_data_dir, - const boost::program_options::variable_value& cfg_data_dir, - const boost::program_options::variable_value& cfg_config) { - // If data_dir has default(new) name and there is existing directory with old name -> rename it - if (cfg_data_dir.defaulted() == true) { - bfs::path deprecated_default_data_dir = bfs::current_path() / "witness_node_data_dir"; - if (bfs::exists(deprecated_default_data_dir) == true) { - bfs::rename(deprecated_default_data_dir, actual_data_dir); - } - } - - // If config with default name exists and is not in subdirectory configs -> move it there - if (cfg_config.defaulted() == true) { - bfs::path deprecated_default_config_path = actual_data_dir / "config.ini"; - if (bfs::exists(deprecated_default_config_path) == true) { - if (bfs::exists(actual_data_dir) == false) { - bfs::create_directory(actual_data_dir); - } - - bfs::path configs_dir = actual_data_dir / "configs/"; - if (bfs::exists(configs_dir) == false) { - bfs::create_directory(configs_dir); - } - - bfs::rename(deprecated_default_config_path, configs_dir / cfg_config.as()); - } - } -} bool application::initialize_impl(int argc, char** argv, vector autostart_plugins) { @@ -246,6 +258,7 @@ bool application::initialize_impl(int argc, char** argv, vector_data_dir, my->_args["data-dir"], my->_args["config"]); + migrate_config_to_json(my->_data_dir, my->_args["data-dir"], my->_args["config"] ); // Writes config if it does not already exists @@ -401,4 +414,9 @@ const variables_map& application::get_args() const return my->_args; } +const options_description& application::get_options() const +{ + return my->_cfg_options; +} + } /// namespace appbase diff --git a/libraries/appbase/include/appbase/application.hpp b/libraries/appbase/include/appbase/application.hpp index 60cc8941..2a6c17ce 100644 --- a/libraries/appbase/include/appbase/application.hpp +++ b/libraries/appbase/include/appbase/application.hpp @@ -126,6 +126,7 @@ namespace appbase { void add_program_options( const bpo::options_description& cli, const bpo::options_description& cfg ); const bpo::variables_map& get_args() const; + const options_description& get_options() const; void set_version_string( const string& version ) { version_info = version; } diff --git a/libraries/config/CMakeLists.txt b/libraries/config/CMakeLists.txt new file mode 100644 index 00000000..eacaad6e --- /dev/null +++ b/libraries/config/CMakeLists.txt @@ -0,0 +1,38 @@ +file(GLOB HEADERS "include/sophiatx/config/*.hpp") + + +add_library( sophiatx_config + config.cpp + include/sophiatx/config/config.hpp + ) +target_link_libraries( sophiatx_config fc ) + + +target_include_directories( sophiatx_config + PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) + +if (USE_PCH) + cotire(sophiatx_config) +endif(USE_PCH) + +if( CLANG_TIDY_EXE ) + set_target_properties( + sophiatx_config PROPERTIES + CXX_CLANG_TIDY "${DO_CLANG_TIDY}" + ) +endif( CLANG_TIDY_EXE ) + +if(MSVC) + set_source_files_properties( config.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) +endif(MSVC) + + + +INSTALL( TARGETS + sophiatx_config + + RUNTIME DESTINATION bin + LIBRARY DESTINATION lib + ARCHIVE DESTINATION lib + ) +INSTALL( FILES ${HEADERS} DESTINATION "include/sophiatx/config" ) diff --git a/libraries/plugins/apis/condenser_api/condenser_api_plugin.cpp b/libraries/plugins/apis/condenser_api/condenser_api_plugin.cpp index 58110ca7..51131795 100644 --- a/libraries/plugins/apis/condenser_api/condenser_api_plugin.cpp +++ b/libraries/plugins/apis/condenser_api/condenser_api_plugin.cpp @@ -9,7 +9,7 @@ condenser_api_plugin::~condenser_api_plugin() {} void condenser_api_plugin::set_program_options( options_description& cli, options_description& cfg ) { - cli.add_options() + cfg.add_options() ("disable-get-block", "Disable get_block API call" ) ; } diff --git a/libraries/plugins/chain/chain_plugin.cpp b/libraries/plugins/chain/chain_plugin.cpp index 978978d6..ad74fe7e 100644 --- a/libraries/plugins/chain/chain_plugin.cpp +++ b/libraries/plugins/chain/chain_plugin.cpp @@ -296,6 +296,8 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip ("checkpoint,c", bpo::value>()->composing(), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.") ("flush-state-interval", bpo::value(), "flush shared memory changes to disk every N blocks") + ("initminer-mining-pubkey", bpo::value(), "initminer public key for mining. Used only for private nets.") + ("initminer-account-pubkey", bpo::value(), "initminer public key for account operations. Used only for private nets.") ; cli.add_options() ("replay-blockchain", bpo::bool_switch()->default_value(false), "clear chain database and replay all blocks" ) @@ -305,8 +307,7 @@ void chain_plugin::set_program_options(options_description& cli, options_descrip ("dump-memory-details", bpo::bool_switch()->default_value(false), "Dump database objects memory usage info. Use set-benchmark-interval to set dump interval.") ("check-locks", bpo::bool_switch()->default_value(false), "Check correctness of chainbase locking" ) ("validate-database-invariants", bpo::bool_switch()->default_value(false), "Validate all supply invariants check out" ) - ("initminer-mining-pubkey", bpo::value(), "initminer public key for mining. Used only for private nets.") - ("initminer-account-pubkey", bpo::value(), "initminer public key for account operations. Used only for private nets.") + ; } diff --git a/libraries/plugins/p2p/p2p_plugin.cpp b/libraries/plugins/p2p/p2p_plugin.cpp index 1f2501ab..4ce5917a 100644 --- a/libraries/plugins/p2p/p2p_plugin.cpp +++ b/libraries/plugins/p2p/p2p_plugin.cpp @@ -487,11 +487,9 @@ void p2p_plugin::set_program_options( bpo::options_description& cli, bpo::option ("p2p-max-connections", bpo::value(), "Maxmimum number of incoming connections on P2P endpoint.") ("p2p-seed-node", bpo::value>()->composing(), "The IP address and port of a remote peer to sync with.") ("p2p-parameters", bpo::value(), ("P2P network parameters. (Default: " + fc::json::to_string(graphene::net::node_configuration()) + " )").c_str() ) - ; - cli.add_options() ("force-validate", bpo::bool_switch()->default_value(false), "Force validation of all transactions. Deprecated in favor of p2p-force-validate" ) ("p2p-force-validate", bpo::bool_switch()->default_value(false), "Force validation of all transactions." ) - ; + ; } void p2p_plugin::plugin_initialize(const boost::program_options::variables_map& options) diff --git a/programs/sophiatxd/CMakeLists.txt b/programs/sophiatxd/CMakeLists.txt index a9327217..1fc51cff 100644 --- a/programs/sophiatxd/CMakeLists.txt +++ b/programs/sophiatxd/CMakeLists.txt @@ -15,6 +15,7 @@ if( SOPHIATX_STATIC_BUILD ) appbase sophiatx_utilities sophiatx_plugins + sophiatx_config ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) @@ -23,6 +24,7 @@ else( SOPHIATX_STATIC_BUILD ) appbase sophiatx_utilities sophiatx_plugins + sophiatx_config ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) diff --git a/programs/sophiatxd/main.cpp b/programs/sophiatxd/main.cpp index 548c6092..48d2ff58 100644 --- a/programs/sophiatxd/main.cpp +++ b/programs/sophiatxd/main.cpp @@ -26,6 +26,8 @@ #include #include +#include +#include "../../libraries/config/include/sophiatx/config/config.hpp" namespace bpo = boost::program_options; using sophiatx::protocol::version; @@ -91,6 +93,9 @@ int main( int argc, char** argv ) auto& args = appbase::app().get_args(); + debug_config(appbase::app().get_options(), args); + + try { fc::optional< fc::logging_config > logging_config = sophiatx::utilities::load_logging_config( args, appbase::app().data_dir() ); From 5304e6d917e4990b50a311e2767739aa9d680c31 Mon Sep 17 00:00:00 2001 From: ejossev Date: Mon, 21 Jan 2019 14:16:23 +0100 Subject: [PATCH 02/17] initial version of the configuration manager --- libraries/config/config.cpp | 132 ++++++++++++++++++ .../config/include/sophiatx/config/config.hpp | 122 ++++++++++++++++ 2 files changed, 254 insertions(+) create mode 100644 libraries/config/config.cpp create mode 100644 libraries/config/include/sophiatx/config/config.hpp diff --git a/libraries/config/config.cpp b/libraries/config/config.cpp new file mode 100644 index 00000000..6632df94 --- /dev/null +++ b/libraries/config/config.cpp @@ -0,0 +1,132 @@ + +#include +#include +#include +#include +#include +#include + +using boost::any_cast; + +namespace sophiatx { namespace config { + +namespace{ + +fc::variant get_from_any(const boost::any& a) +{ + fc::variant ret; + if( ! a.empty()) { + //first, try int + if( a.type() == typeid(uint16_t)) + ret = any_cast(a); + else + if( a.type() == typeid(int16_t)) + ret = any_cast(a); + else + if( a.type() == typeid(uint32_t)) + ret = any_cast(a); + else + if( a.type() == typeid(int32_t)) + ret = any_cast(a); + else + if( a.type() == typeid(uint64_t)) + ret = any_cast(a); + else + if( a.type() == typeid(int64_t)) + ret = any_cast(a); + else + if( a.type() == typeid(bool)) + ret = any_cast(a); + else //string? + if( a.type() == typeid(std::string)) + ret = any_cast(a); + else + if( a.type() == typeid(boost::filesystem::path)) { + boost::filesystem::path tmp_ret = any_cast(a); + ret = tmp_ret.generic_string(); + } + else //vector? + if( a.type() == typeid(std::vector)){ + std::vector res; + res = any_cast>(a); + ret = res; + } + } + return ret; +} + + +} + +void configuration_manager::set_defaults_for_chain(const fc::sha256 &chain_id) +{ + for(const auto& i : _descriptions.values) + _variables.values[chain_id][i.first].value = i.second.default_value; +} + + +void configuration_manager::merge_descriptions_with_bpo(const bpo::options_description &descs) +{ + for( const auto& i : descs.options() ){ + boost::any def_val; + fc::variant vdef_val; + if(i->semantic()->apply_default(def_val)) { + vdef_val = get_from_any( def_val); + } + config_entry_description d(i->long_name(), i->description(), vdef_val ); + _descriptions.values[i->long_name()] = d; + } +} + +void configuration_manager::merge_chain_config_with_bpo(const bpo::variables_map &bpo_map, + const fc::sha256 &chain_id) +{ + for(const auto& i : bpo_map){ + const std::string& name = i.first; + const boost::any& value = i.second.value(); + fc::variant vvalue = get_from_any(value); + + _variables.values[chain_id][name].value = vvalue; + } +} + +void configuration_manager::store_to_file(std::string filename) +{ + std::map> extended_values; + for( const auto& chid : _variables.values ){ + for( const auto & desc : _descriptions.values ){ + extended_values[chid.first][desc.first].name = desc.second.name; + extended_values[chid.first][desc.first].description = desc.second.description; + extended_values[chid.first][desc.first].default_value = desc.second.default_value; + if(chid.second.count(desc.first)) + extended_values[ chid.first ][ desc.first ].value = chid.second.at(desc.first).value; + } + + } + + fc::variant file_config; + fc::to_variant(extended_values, file_config); + fc::json::save_to_file(file_config, filename, true); +} + +void configuration_manager::load_from_file(std::string filename) +{ + fc::variant file_config = fc::json::from_file(filename); + fc::from_variant(file_config, _variables.values); +} + +std::string configuration_manager::print_descriptions() +{ + fc::variant vdescriptions; + fc::to_variant( _descriptions.values, vdescriptions); + return fc::json::to_pretty_string(vdescriptions); +} + +std::string configuration_manager::print_configs() +{ + fc::variant voptions; + fc::to_variant( _variables.values, voptions); + return fc::json::to_pretty_string(voptions); +} + +}} //namespace sophiatx::config diff --git a/libraries/config/include/sophiatx/config/config.hpp b/libraries/config/include/sophiatx/config/config.hpp new file mode 100644 index 00000000..e7aab7cb --- /dev/null +++ b/libraries/config/include/sophiatx/config/config.hpp @@ -0,0 +1,122 @@ +// +// Created by Josef Sevcik on 2019-01-18. +// + +#pragma once +#include +#include +#include +#include +#include +#include +#include + +namespace bpo = boost::program_options; + +namespace sophiatx { namespace config { + +namespace{ +const static fc::sha256 _public_net_chain_id = fc::sha256("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); +} + +class config_entry_description{ +public: + std::string name; + std::string description; + fc::optional default_value; + config_entry_description(){} + config_entry_description(const std::string _name, std::string _description, fc::variant _default_value): name(_name), description(_description){ + if(!_default_value.is_null()) + default_value = _default_value; + } + config_entry_description(const config_entry_description& ced):name(ced.name),description(ced.description),default_value(ced.default_value){} + config_entry_description& operator=(const config_entry_description&ced){ + name = ced.name; + description = ced.description; + default_value = ced.default_value; + return *this; + } +}; + +class config_entry{ +public: + fc::variant value; +}; + +class extended_config_entry : public config_entry_description { +public: + fc::optional value; +}; + +struct variables{ + std::map> values; +}; + +struct descriptions{ + std::map values; +}; + +class configuration_manager { +public: + static configuration_manager &get_configuration_manager() { + static configuration_manager instance; + return instance; + } + + configuration_manager(configuration_manager const &) = delete; + + void operator=(configuration_manager const &) = delete; + + fc::variant get_variable(const std::string& name, const fc::sha256& chain_id = _public_net_chain_id){ + try { + return _variables.values.at(chain_id).at(name).value; + }catch(std::out_of_range){ + return fc::variant(); + } + }; + + void set_variable(const std::string& name, const fc::variant& value, const fc::sha256& chain_id = _public_net_chain_id ){ + _variables.values[chain_id][name].value = value; + }; + + void set_description(const std::string& name, const fc::variant& default_value, const std::string description ){ + FC_ASSERT( _descriptions.values.find(name) == _descriptions.values.end(), "description already exists" ); + _descriptions.values[name] = config_entry_description(name, description, default_value); + }; + + std::vector get_descriptions(){ + std::vector ret; + for(const auto& i: _descriptions.values ){ + ret.push_back(i.second); + } + return ret; + } + + void load_from_file(std::string filename); + void store_to_file(std::string filename); + std::string print_descriptions(); + std::string print_configs(); + void merge_chain_config_with_bpo( const bpo::variables_map& bpo_map, const fc::sha256& chain_id = _public_net_chain_id ); + void merge_descriptions_with_bpo( const bpo::options_description& descs); + void set_defaults_for_chain(const fc::sha256& chain_id); + + variables _variables; + descriptions _descriptions; + +private: + configuration_manager() { + }; + + +}; + +}} //namespace sophiatx::config + +FC_REFLECT(sophiatx::config::config_entry_description, (name)(description)(default_value)) +FC_REFLECT(sophiatx::config::variables, (values)) +FC_REFLECT(sophiatx::config::descriptions, (values)) +FC_REFLECT(sophiatx::config::config_entry, (value)) +FC_REFLECT_DERIVED(sophiatx::config::extended_config_entry, (sophiatx::config::config_entry_description), (value) ) + +FC_REFLECT(sophiatx::config::configuration_manager, (_variables)) + From b9dbaaf4cb152923a117601cd62bcd786f057788 Mon Sep 17 00:00:00 2001 From: ejossev Date: Fri, 25 Jan 2019 17:06:34 +0100 Subject: [PATCH 03/17] WIP --- libraries/CMakeLists.txt | 1 - libraries/appbase/CMakeLists.txt | 2 +- libraries/appbase/application.cpp | 354 ++++++++++-------- libraries/appbase/examples/main.cpp | 13 +- .../appbase/include/appbase/application.hpp | 169 ++++----- libraries/appbase/include/appbase/plugin.hpp | 199 +++++++--- libraries/config/CMakeLists.txt | 38 -- libraries/config/config.cpp | 132 ------- .../config/include/sophiatx/config/config.hpp | 122 ------ .../manifest/gensrc/plugins/mf_plugins.cpp | 44 +-- .../templates/plugins/mf_plugins.cpp.j2 | 2 +- .../account_by_key/account_by_key_plugin.cpp | 4 +- .../account_by_key/account_by_key_plugin.hpp | 2 +- .../account_history_plugin.cpp | 6 +- .../account_history_plugin.hpp | 4 +- .../account_by_key_api/account_by_key_api.cpp | 6 +- .../account_by_key_api_plugin.cpp | 2 +- .../account_by_key_api/account_by_key_api.hpp | 2 +- .../account_by_key_api_plugin.hpp | 2 +- .../account_history_api.cpp | 6 +- .../account_history_api_plugin.cpp | 2 +- .../account_history_api.hpp | 2 +- .../account_history_api_plugin.hpp | 2 +- .../alexandria_api/alexandria_api_impl.cpp | 4 +- .../alexandria_api/alexandria_api_plugin.cpp | 2 +- .../block_log_info/block_log_info_plugin.cpp | 4 +- libraries/plugins/chain/chain_plugin.cpp | 54 +-- .../sophiatx/plugins/chain/chain_plugin.hpp | 2 +- .../plugins/debug_node/debug_node_plugin.cpp | 8 +- .../plugins/json_rpc/json_rpc_plugin.hpp | 18 +- .../plugins/json_rpc/json_rpc_plugin.cpp | 9 +- .../multiparty_messaging_plugin.cpp | 2 +- libraries/plugins/p2p/p2p_plugin.cpp | 2 +- .../template_plugin/template_plugin.cpp | 2 +- .../plugins/webserver/webserver_plugin.cpp | 4 +- libraries/plugins/witness/witness_plugin.cpp | 20 +- programs/sophiatxd/CMakeLists.txt | 2 - programs/sophiatxd/main.cpp | 11 +- 38 files changed, 529 insertions(+), 731 deletions(-) delete mode 100644 libraries/config/CMakeLists.txt delete mode 100644 libraries/config/config.cpp delete mode 100644 libraries/config/include/sophiatx/config/config.hpp diff --git a/libraries/CMakeLists.txt b/libraries/CMakeLists.txt index 4675f966..aaf47183 100644 --- a/libraries/CMakeLists.txt +++ b/libraries/CMakeLists.txt @@ -1,5 +1,4 @@ add_subdirectory( fc ) -add_subdirectory( config ) add_subdirectory( schema ) add_subdirectory( appbase ) add_subdirectory( chainbase ) diff --git a/libraries/appbase/CMakeLists.txt b/libraries/appbase/CMakeLists.txt index 56d2ddb7..fddd3baa 100644 --- a/libraries/appbase/CMakeLists.txt +++ b/libraries/appbase/CMakeLists.txt @@ -42,7 +42,7 @@ add_library( appbase application.cpp ) -target_link_libraries( appbase ${Boost_LIBRARIES}) +target_link_libraries( appbase fc ${Boost_LIBRARIES}) target_include_directories( appbase PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ${Boost_INCLUDE_DIR}) diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index a1a2d0a6..e4354805 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -28,7 +28,7 @@ namespace{ * @param cfg_data_dir * @param cfg_config */ -void fix_deprecated_data_folder_structure(const bfs::path& actual_data_dir, +/*void fix_deprecated_data_folder_structure(const bfs::path& actual_data_dir, const boost::program_options::variable_value& cfg_data_dir, const boost::program_options::variable_value& cfg_config) { @@ -56,32 +56,80 @@ void fix_deprecated_data_folder_structure(const bfs::path& actual_data_dir, bfs::rename(deprecated_default_config_path, configs_dir / cfg_config.as()); } } -} +}*/ -void migrate_config_to_json(const bfs::path& actual_data_dir, - const boost::program_options::variable_value& cfg_data_dir, - const boost::program_options::variable_value& cfg_config) -{ +/** + * @brief Writes options_desc data into cfg_file file + * + * @param options_desc + * @param cfg_file + * @return created config file absolute path + */ +bfs::path write_default_config( const options_description& options_desc, const bfs::path& cfg_file, std::string suffix = "" ) { + bfs::path _cfg_file = cfg_file; + if( suffix != "" ){ + _cfg_file += suffix; + } + + bfs::path config_file_name = app_factory().data_dir / "configs" / _cfg_file ; + + if( _cfg_file.is_absolute() == true ) { + config_file_name = _cfg_file; + } + + if(bfs::exists(config_file_name) == true) { + return config_file_name; + } + + if(bfs::exists(config_file_name.parent_path()) == false) { + bfs::create_directories(config_file_name.parent_path()); + } + + std::ofstream out_cfg( bfs::path(config_file_name).make_preferred().string()); + for(const boost::shared_ptr od : options_desc.options()) + { + if(!od->description().empty()) + out_cfg << "# " << od->description() << "\n"; + boost::any store; + if(!od->semantic()->apply_default(store)) + out_cfg << "# " << od->long_name() << " = \n"; + else { + auto example = od->format_parameter(); + if(example.empty()) + // This is a boolean switch + out_cfg << od->long_name() << " = " << "false\n"; + else { + // The string is formatted "arg (=)" + example.erase(0, 6); + example.erase(example.length()-1); + out_cfg << od->long_name() << " = " << example << "\n"; + } + } + out_cfg << "\n"; + } + out_cfg.close(); + return config_file_name; } +const static string _public_net_chain_id = "1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"; + } class application_impl { public: - application_impl():_app_options("Application Options"){ + application_impl(){ } const variables_map* _options = nullptr; - options_description _app_options; - options_description _cfg_options; + options_description& _cfg_options = app_factory().app_options; variables_map _args; bfs::path _data_dir; }; -application::application() -:my(new application_impl()){ +application::application(const string& _id) +:id(_id), my(new application_impl()) { io_serv = std::make_shared(); } @@ -92,61 +140,10 @@ void application::startup() { plugin->startup(); } -application& application::instance( bool reset ) { - static application* _app = new application(); - if( reset ) - { - delete _app; - _app = new application(); - } - return *_app; -} -application& app() { return application::instance(); } -application& reset() { return application::instance( true ); } - - -void application::set_program_options() -{ - options_description app_cfg_opts( "Application Config Options" ); - options_description app_cli_opts( "Application Command Line Options" ); - app_cfg_opts.add_options() - ("plugin", bpo::value< vector >()->composing(), "Plugin(s) to enable, may be specified multiple times"); - - app_cfg_opts.add_options() - ("external-plugins-dir", bpo::value()->default_value( "external-plugins" ), "Directory containing external/runtime-loadable plugins binaries (absolute path or relative to the program option data-dir/)"); - app_cfg_opts.add_options() - ("external-plugin", bpo::value< vector >()->composing(), "External plugin(s) to enable, may be specified multiple times"); - - app_cli_opts.add_options() - ("help,h", "Print this help message and exit.") - ("version,v", "Print version information.") - ("data-dir,d", bpo::value()->default_value( "sophia_app_data" ), "Directory containing configuration files, blockchain data and external plugins") - ("config,c", bpo::value()->default_value( "config.ini" ), "Obsolete. Main configuration file path (absolute path or relative to the data-dir/configs/)"); - - my->_cfg_options.add(app_cfg_opts); - my->_app_options.add(app_cfg_opts); - my->_app_options.add(app_cli_opts); - - for(auto& plug : plugins) { - const plugin_program_options& plugin_options = get_plugin_program_options(plug.second); - - const options_description& plugin_cfg_options = plugin_options.get_cfg_options(); - if (plugin_cfg_options.options().size()) { - my->_app_options.add(plugin_cfg_options); - my->_cfg_options.add(plugin_cfg_options); - } - - const options_description& plugin_cli_options = plugin_options.get_cli_options(); - if (plugin_cli_options.options().size()) { - my->_app_options.add(plugin_cli_options); - } - } -} - -plugin_program_options application::get_plugin_program_options(const std::shared_ptr< abstract_plugin >& plugin) { - options_description plugin_cli_opts("Command Line Options for " + plugin->get_name()); - options_description plugin_cfg_opts("Config Options for " + plugin->get_name()); - plugin->set_program_options(plugin_cli_opts, plugin_cfg_opts); +plugin_program_options application_factory::get_plugin_program_options(std::shared_ptr & plugin_factory) { + options_description plugin_cli_opts("Command Line Options for " + plugin_factory->get_name()); + options_description plugin_cfg_opts("Config Options for " + plugin_factory->get_name()); + plugin_factory->set_program_options(plugin_cli_opts, plugin_cfg_opts); return plugin_program_options(plugin_cli_opts, plugin_cfg_opts); } @@ -192,6 +189,7 @@ bool application::load_external_plugins() { return false; } + loaded_plugin->set_app(shared_from_this()); // Registers loaded plugin for application register_external_plugin(loaded_plugin); @@ -213,61 +211,24 @@ void application::register_external_plugin(const std::shared_ptr& plugin, const std::string& cfg_plugin_name) { - const plugin_program_options& plugin_options = get_plugin_program_options(plugin); + options_description plugin_cli_opts("Command Line Options for " + plugin->get_name()); + options_description plugin_cfg_opts("Config Options for " + plugin->get_name()); + plugin->set_program_options(plugin_cli_opts, plugin_cfg_opts); // Writes config if it does not already exists - bfs::path config_file_path = write_default_config(plugin_options.get_cfg_options(), bfs::path(cfg_plugin_name + "_plugin_config.ini")); + bfs::path config_file_path = write_default_config(plugin_cfg_opts, bfs::path(cfg_plugin_name + "_plugin_config.ini"), id); // Copies parameters from config_file into my->_args bpo::store(bpo::parse_config_file< char >( config_file_path.make_preferred().string().c_str(), - plugin_options.get_cfg_options(), true ), my->_args ); + plugin_cfg_opts, true ), my->_args ); } -bool application::initialize_impl(int argc, char** argv, vector autostart_plugins) +bool application::initialize( const variables_map& app_settings, const vector& autostart_plugins ) { try { - set_program_options(); - bpo::store( bpo::parse_command_line( argc, argv, my->_app_options ), my->_args ); - - if( my->_args.count( "help" ) ) { - cout << my->_app_options << "\n"; - return false; - } - - if( my->_args.count( "version" ) ) - { - cout << version_info << "\n"; - return false; - } - - - // data-dir par (even if it is default) must be always present - assert(my->_args.count( "data-dir" )); - - my->_data_dir = my->_args["data-dir"].as(); - if( my->_data_dir.is_relative() ) - my->_data_dir = bfs::current_path() / my->_data_dir; - - - // config par (even if it is default) must be always present - assert(my->_args.count( "config" )); - - - // TODO: delete after HF2 - // Fix which renames default data directory and also moves config into subdirectory configs, so users do not need to do it themselves - fix_deprecated_data_folder_structure(my->_data_dir, my->_args["data-dir"], my->_args["config"]); - migrate_config_to_json(my->_data_dir, my->_args["data-dir"], my->_args["config"] ); - - - // Writes config if it does not already exists - bfs::path config_file_path = write_default_config(my->_cfg_options, my->_args["config"].as()); - - // Copies parameters from config_file into my->_args - bpo::store(bpo::parse_config_file< char >( config_file_path.make_preferred().string().c_str(), - my->_cfg_options, true ), my->_args ); - + my->_args = app_settings; if(my->_args.count("plugin") > 0) { @@ -286,11 +247,11 @@ bool application::initialize_impl(int argc, char** argv, vectorget_state() == abstract_plugin::registered) plugin->initialize(my->_args); - - bpo::notify(my->_args); + } return true; } @@ -337,46 +298,6 @@ void application::exec() { shutdown(); /// perform synchronous shutdown } -bfs::path application::write_default_config( const options_description& options_desc, const bfs::path& cfg_file ) { - bfs::path config_file_name = my->_data_dir / "configs" / cfg_file; - if( cfg_file.is_absolute() == true ) { - config_file_name = cfg_file; - } - - if(bfs::exists(config_file_name) == true) { - return config_file_name; - } - - if(bfs::exists(config_file_name.parent_path()) == false) { - bfs::create_directories(config_file_name.parent_path()); - } - - std::ofstream out_cfg( bfs::path(config_file_name).make_preferred().string()); - for(const boost::shared_ptr od : options_desc.options()) - { - if(!od->description().empty()) - out_cfg << "# " << od->description() << "\n"; - boost::any store; - if(!od->semantic()->apply_default(store)) - out_cfg << "# " << od->long_name() << " = \n"; - else { - auto example = od->format_parameter(); - if(example.empty()) - // This is a boolean switch - out_cfg << od->long_name() << " = " << "false\n"; - else { - // The string is formatted "arg (=)" - example.erase(0, 6); - example.erase(example.length()-1); - out_cfg << od->long_name() << " = " << example << "\n"; - } - } - out_cfg << "\n"; - } - out_cfg.close(); - - return config_file_name; -} abstract_plugin* application::find_plugin( const string& name )const { @@ -402,21 +323,132 @@ bfs::path application::data_dir()const return my->_data_dir; } -void application::add_program_options( const options_description& cli, const options_description& cfg ) -{ - my->_app_options.add( cli ); - my->_app_options.add( cfg ); - my->_cfg_options.add( cfg ); -} const variables_map& application::get_args() const { return my->_args; } -const options_description& application::get_options() const +void application_factory::add_program_options( const options_description& cli ) +{ + app_options.add( cli ); +} + +application_factory& app_factory() { return application_factory::get_app_factory(); } + + +void application_factory::set_program_options() { - return my->_cfg_options; + + options_description app_cfg_opts( "Application Config Options" ); + options_description app_cli_opts( "Application Command Line Options" ); + app_cfg_opts.add_options() + ("plugin", bpo::value< vector >()->composing(), "Plugin(s) to enable, may be specified multiple times"); + + app_cfg_opts.add_options() + ("external-plugin", bpo::value< vector >()->composing(), "External plugin(s) to enable, may be specified multiple times"); + + app_cli_opts.add_options() + ("startup-apps", bpo::value>()->composing(), "Applications to load at startup"); + + app_cli_opts.add_options() + ("external-plugins-dir", bpo::value()->default_value( "external-plugins" ), "Directory containing external/runtime-loadable plugins binaries (absolute path or relative to the program option data-dir/)"); + + app_cli_opts.add_options() + ("help,h", "Print this help message and exit.") + ("version,v", "Print version information.") + ("data-dir,d", bpo::value()->default_value( "sophia_app_data" ), "Directory containing configuration files, blockchain data and external plugins") + ("config,c", bpo::value()->default_value( "config.ini" ), "Main configuration file path (absolute path or relative to the data-dir/configs/)"); + + app_options.add(app_cfg_opts); + global_options.add(app_cli_opts); + + for(auto& plug : plugin_factories ) { + const plugin_program_options& plugin_options = get_plugin_program_options(plug); + + const options_description& plugin_cfg_options = plugin_options.get_cfg_options(); + if (plugin_cfg_options.options().size()) { + app_options.add(plugin_cfg_options); + } + + const options_description& plugin_cli_options = plugin_options.get_cli_options(); + if (plugin_cli_options.options().size()) { + global_options.add(plugin_cli_options); + } + } +} + +bool application_factory::initialize( int argc, char** argv, vector< string > _autostart_plugins ) +{ + try + { + bpo::store( bpo::parse_command_line( argc, argv, global_options ), global_args ); + std::copy(_autostart_plugins.begin(), _autostart_plugins.end(), std::back_inserter(autostart_plugins)); + + if( global_args.count( "help" ) ) { + cout << global_options << "\n"; + return false; + } + + if( global_args.count( "version" ) ) + { + cout << version_info << "\n"; + return false; + } + + // data-dir par (even if it is default) must be always present + assert(global_args.count( "data-dir" )); + + data_dir = global_args["data-dir"].as(); + if( data_dir.is_relative() ) + data_dir = bfs::current_path() / data_dir; + + // config par (even if it is default) must be always present + assert(global_args.count( "config" )); + + // Writes config if it does not already exists + bfs::path config_file_path = write_default_config(global_options, global_args["config"].as()); + + // Copies parameters from config_file into my->_args + bpo::store(bpo::parse_config_file< char >( config_file_path.make_preferred().string().c_str(), + global_options, true ), global_args ); + + //TODO: migrate the config here + + if(global_args.count("startup-apps") > 0) + { + auto chains = global_args.at("startup-apps").as>(); + for(auto& arg : chains ) + { + vector names; + boost::split(names, arg, boost::is_any_of(" \t,")); + for(const std::string& name : names) + { + bfs::path config_file_path = write_default_config(app_options, global_args["config"].as(), name ); + variables_map app_args; + bpo::store(bpo::parse_config_file< char >( config_file_path.make_preferred().string().c_str(), + app_options, true ), app_args ); + auto new_app = new_application(app_args, name); + + } + } + }else{ + //load default (public) one. + bfs::path config_file_path = write_default_config(app_options, global_args["config"].as(), _public_net_chain_id ); + variables_map app_args; + bpo::store(bpo::parse_config_file< char >( config_file_path.make_preferred().string().c_str(), + app_options, true ), app_args ); + auto new_app = new_application(app_args, _public_net_chain_id); + } + + return true; + } + catch (const boost::program_options::error& e) + { + std::cerr << "Error parsing command line: " << e.what() << "\n"; + return false; + } + } } /// namespace appbase diff --git a/libraries/appbase/examples/main.cpp b/libraries/appbase/examples/main.cpp index adaaa4e0..3ecde61c 100755 --- a/libraries/appbase/examples/main.cpp +++ b/libraries/appbase/examples/main.cpp @@ -18,7 +18,7 @@ class plugin_a : public appbase::plugin static const std::string& name() { static std::string name = "plugin_a"; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override + static void set_program_options( options_description& cli, options_description& cfg ) { cfg.add_options() ("dbsize", bpo::value()->default_value( 8*1024 ), "Minimum size MB of database shared memory file") @@ -59,7 +59,7 @@ class plugin_b : public appbase::plugin static const std::string& name() { static std::string name = "plugin_b"; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override + static void set_program_options( options_description& cli, options_description& cfg ) { cfg.add_options() ("listen-endpoint", bpo::value()->default_value( "127.0.0.1:9876" ), "The local IP address and port to listen for incoming connections.") @@ -90,11 +90,12 @@ class plugin_b : public appbase::plugin int main( int argc, char** argv ) { try { - appbase::app().register_plugin(); - if( !appbase::app().initialize( argc, argv ) ) + appbase::app_factory().register_plugin_factory(); + + if( !appbase::app_factory().initialize( argc, argv, {} ) ) return -1; - appbase::app().startup(); - appbase::app().exec(); + appbase::app_factory().startup(); + appbase::app_factory().exec(); } catch ( const boost::exception& e ) { std::cerr << boost::diagnostic_information(e) << "\n"; } catch ( const std::exception& e ) { diff --git a/libraries/appbase/include/appbase/application.hpp b/libraries/appbase/include/appbase/application.hpp index 2a6c17ce..5bd923b8 100644 --- a/libraries/appbase/include/appbase/application.hpp +++ b/libraries/appbase/include/appbase/application.hpp @@ -7,13 +7,14 @@ #include -#define APPBASE_VERSION_STRING ("appbase 1.0") +#define APPBASE_VERSION_STRING ("appbase 1.1") namespace appbase { namespace bpo = boost::program_options; namespace bfs = boost::filesystem; + class application; /** * @brief Simple data holder for plugin program options @@ -36,10 +37,11 @@ namespace appbase { }; - class application + class application : std::enable_shared_from_this { public: ~application(); + application(const string& _id); /** * @brief Looks for the --plugin commandline / config option and calls initialize on those plugins @@ -48,11 +50,7 @@ namespace appbase { * configuration settings or dependency resolution, this template has no effect. * @return true if the application and plugins were initialized, false or exception on error */ - template< typename... Plugin > - bool initialize( int argc, char** argv ) - { - return initialize_impl( argc, argv, { find_plugin( Plugin::name() )... } ); - } + bool initialize( const variables_map& app_settings, const vector& autostart_plugins ); void startup(); void shutdown(); @@ -63,19 +61,13 @@ namespace appbase { void exec(); void quit(); - static application& instance( bool reset = false ); + void register_plugin( const std::shared_ptr& plugin ){ + auto existing = find_plugin( plugin->get_name() ); + if(existing) + return; - template< typename Plugin > - auto& register_plugin() - { - auto existing = find_plugin( Plugin::name() ); - if( existing ) - return *dynamic_cast< Plugin* >( existing ); - - auto plug = std::make_shared< Plugin >(); - plugins[Plugin::name()] = plug; - plug->register_dependencies(); - return *plug; + plugins[plugin->get_name()] = plugin; + plugin->register_dependencies(); } /** @@ -124,11 +116,8 @@ namespace appbase { bfs::path data_dir()const; - void add_program_options( const bpo::options_description& cli, const bpo::options_description& cfg ); const bpo::variables_map& get_args() const; - const options_description& get_options() const; - - void set_version_string( const string& version ) { version_info = version; } + string id; boost::asio::io_service& get_io_service() { return *io_serv; } @@ -136,8 +125,6 @@ namespace appbase { template< typename Impl > friend class plugin; - bool initialize_impl( int argc, char** argv, vector< abstract_plugin* > autostart_plugins ); - abstract_plugin* find_plugin( const string& name )const; abstract_plugin& get_plugin( const string& name )const; @@ -150,89 +137,85 @@ namespace appbase { ///@} private: - application(); ///< private because application is a singlton that should be accessed via instance() + map< string, std::shared_ptr< abstract_plugin > > plugins; ///< all registered plugins vector< abstract_plugin* > initialized_plugins; ///< stored in the order they were started running vector< abstract_plugin* > running_plugins; ///< stored in the order they were started running std::shared_ptr< boost::asio::io_service > io_serv; - std::string version_info; - - void set_program_options(); - - plugin_program_options get_plugin_program_options(const std::shared_ptr< abstract_plugin >& plugin); - - /** - * @brief Writes options_desc data into cfg_file file - * - * @param options_desc - * @param cfg_file - * @return created config file absolute path - */ - bfs::path write_default_config( const options_description& options_desc, const bfs::path& cfg_file ); std::unique_ptr< class application_impl > my; }; - application& app(); - application& reset(); - - template< typename Impl > - class plugin : public abstract_plugin + class application_factory { - public: - virtual ~plugin() {} - - virtual state get_state() const override { return _state; } - virtual const std::string& get_name()const override final { return Impl::name(); } - - virtual void register_dependencies() override - { - this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){} ); - } - - virtual void initialize(const variables_map& options) override final - { - if( _state == registered ) - { - _state = initialized; - this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.initialize( options ); } ); - this->plugin_initialize( options ); - // std::cout << "Initializing plugin " << Impl::name() << std::endl; - app().plugin_initialized( *this ); - } - if (_state != initialized) - BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not registered, so final state cannot be initialized.") ); + public: + static application_factory &get_app_factory() { + static application_factory instance; + return instance; + } + + application_factory(application_factory const &) = delete; + void operator=(application_factory const &) = delete; + + template void register_plugin_factory(){ + std::shared_ptr> new_plugin_factory = std::make_shared>(); + plugin_factories.push_back(new_plugin_factory); + } + + std::shared_ptr new_application(const variables_map& app_args, const string& id){ + std::shared_ptr new_app = std::make_shared(id ); + for( const auto& pf : plugin_factories){ + auto new_plugin = pf->new_plugin(new_app); + new_app->register_plugin(new_plugin); } + apps.push_back(new_app); + new_app->initialize(app_args, autostart_plugins); + return new_app; + } + + void add_program_options( const bpo::options_description& cli ); + + bool initialize( int argc, char** argv, vector< string > autostart_plugins ); + void set_version_string( const string& version ) { version_info = version; } + + options_description app_options; + options_description global_options; + bfs::path data_dir; + variables_map global_args; + + void startup(){ + for(auto& app : apps) + app->startup(); + }; + + void exec(){ + for(auto& app : apps) + app->exec(); + }; + void shutdown(){ + for(auto& app : apps) + app->shutdown(); + } + void quit(){ + for(auto& app : apps) + app->quit(); + } - virtual void startup() override final - { - if( _state == initialized ) - { - _state = started; - this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.startup(); } ); - this->plugin_startup(); - app().plugin_started( *this ); - } - if (_state != started ) - BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not initialized, so final state cannot be started.") ); - } + private: + void set_program_options(); + vector> plugin_factories; + vector autostart_plugins; + vector> apps; + string version_info; - virtual void shutdown() override final - { - if( _state == started ) - { - _state = stopped; - //ilog( "shutting down plugin ${name}", ("name",name()) ); - this->plugin_shutdown(); - } - } + application_factory():global_options("Application Options") { + set_program_options(); + }; - protected: - plugin() = default; - private: - state _state = abstract_plugin::registered; + plugin_program_options get_plugin_program_options(std::shared_ptr & plugin_factory); }; + application_factory& app_factory(); } diff --git a/libraries/appbase/include/appbase/plugin.hpp b/libraries/appbase/include/appbase/plugin.hpp index f8b62016..48e01b12 100644 --- a/libraries/appbase/include/appbase/plugin.hpp +++ b/libraries/appbase/include/appbase/plugin.hpp @@ -8,7 +8,7 @@ #include #define APPBASE_PLUGIN_REQUIRES_VISIT( r, visitor, elem ) \ - visitor( appbase::app().register_plugin() ); + visitor( ( app()->get_plugin() ) ); #define APPBASE_PLUGIN_REQUIRES( PLUGINS ) \ virtual void plugin_for_each_dependency( plugin_processor&& l ) override { \ @@ -17,58 +17,151 @@ namespace appbase { - using boost::program_options::options_description; - using boost::program_options::variables_map; - using std::string; - using std::vector; - using std::map; - - class application; - application& app(); - - class abstract_plugin { - public: - enum state { - registered, ///< the plugin is constructed but doesn't do anything - initialized, ///< the plugin has initlaized any state required but is idle - started, ///< the plugin is actively running - stopped ///< the plugin is no longer running - }; - - virtual ~abstract_plugin(){} - - virtual state get_state()const = 0; - virtual const std::string& get_name()const = 0; - virtual void set_program_options( options_description& cli, options_description& cfg ) = 0; - virtual void register_dependencies() = 0; - virtual void initialize(const variables_map& options) = 0; - virtual void startup() = 0; - virtual void shutdown() = 0; - - protected: - typedef std::function plugin_processor; - - /** Abstract method to be reimplemented in final plugin implementation. - It is a part of initialization/startup process triggerred by main application. - Allows to process all plugins, this one depends on. - */ - virtual void plugin_for_each_dependency(plugin_processor&& processor) = 0; - - /** Abstract method to be reimplemented in final plugin implementation. - It is a part of initialization process triggerred by main application. - */ - virtual void plugin_initialize( const variables_map& options ) = 0; - /** Abstract method to be reimplemented in final plugin implementation. - It is a part of startup process triggerred by main application. - */ - virtual void plugin_startup() = 0; - /** Abstract method to be reimplemented in final plugin implementation. - It is a part of shutdown process triggerred by main application. - */ - virtual void plugin_shutdown() = 0; +using boost::program_options::options_description; +using boost::program_options::variables_map; +using std::string; +using std::vector; +using std::map; +class application; + +class abstract_plugin : std::enable_shared_from_this +{ +public: + enum state { + registered, ///< the plugin is constructed but doesn't do anything + initialized, ///< the plugin has initlaized any state required but is idle + started, ///< the plugin is actively running + stopped ///< the plugin is no longer running }; - template - class plugin; -} + virtual ~abstract_plugin(){} + + virtual state get_state()const = 0; + virtual const std::string& get_name()const = 0; + static void set_program_options( options_description& cli, options_description& cfg ){}; + virtual void register_dependencies() = 0; + virtual void initialize(const variables_map& options) = 0; + virtual void startup() = 0; + virtual void shutdown() = 0; + void set_app(const std::shared_ptr& my_app) { _app = my_app; } + const std::shared_ptr app() { return _app; } + +protected: + typedef std::function plugin_processor; + + /** Abstract method to be reimplemented in final plugin implementation. + It is a part of initialization/startup process triggerred by main application. + Allows to process all plugins, this one depends on. + */ + virtual void plugin_for_each_dependency(plugin_processor&& processor) = 0; + + /** Abstract method to be reimplemented in final plugin implementation. + It is a part of initialization process triggerred by main application. + */ + virtual void plugin_initialize( const variables_map& options ) = 0; + /** Abstract method to be reimplemented in final plugin implementation. + It is a part of startup process triggerred by main application. + */ + virtual void plugin_startup() = 0; + /** Abstract method to be reimplemented in final plugin implementation. + It is a part of shutdown process triggerred by main application. + */ + virtual void plugin_shutdown() = 0; + +private: + std::shared_ptr _app; +}; + +template< typename Impl > +class plugin : public abstract_plugin +{ +public: + virtual ~plugin() {} + + virtual state get_state() const override { return _state; } + virtual const std::string& get_name()const override final { return Impl::name(); } + + virtual void register_dependencies() override + { + this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){} ); + } + + virtual void initialize(const variables_map& options) override final + { + if( _state == registered ) + { + _state = initialized; + this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.initialize( options ); } ); + this->plugin_initialize( options ); + // std::cout << "Initializing plugin " << Impl::name() << std::endl; + app()->plugin_initialized( *this ); + } + if (_state != initialized) + BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not registered, so final state cannot be initialized.") ); + } + + virtual void startup() override final + { + if( _state == initialized ) + { + _state = started; + this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.startup(); } ); + this->plugin_startup(); + app()->plugin_started( *this ); + } + if (_state != started ) + BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not initialized, so final state cannot be started.") ); + } + + virtual void shutdown() override final + { + if( _state == started ) + { + _state = stopped; + //ilog( "shutting down plugin ${name}", ("name",name()) ); + this->plugin_shutdown(); + } + } + +protected: + plugin() = default; + +private: + state _state = abstract_plugin::registered; +}; + +class abstract_plugin_factory +{ +public: + virtual ~abstract_plugin_factory(){} + virtual std::shared_ptr new_plugin( std::shared_ptr new_app ) const = 0; + virtual void set_program_options( options_description& cli, options_description& cfg ) = 0; + virtual std::string get_name() = 0; +}; + + +template +class plugin_factory : public abstract_plugin_factory +{ +public: + virtual ~plugin_factory(){} + virtual std::shared_ptr new_plugin( std::shared_ptr new_app ) const final { + std::shared_ptr new_plugin = std::make_shared(); + new_plugin->set_app( new_app ); + return new_plugin; + } + + virtual void set_program_options( options_description& cli, options_description& cfg ) { + Plugin::set_program_options(cli, cfg); + }; + + virtual std::string get_name(){ + return Plugin::name(); + } + +}; + +template class plugin; +}; + diff --git a/libraries/config/CMakeLists.txt b/libraries/config/CMakeLists.txt deleted file mode 100644 index eacaad6e..00000000 --- a/libraries/config/CMakeLists.txt +++ /dev/null @@ -1,38 +0,0 @@ -file(GLOB HEADERS "include/sophiatx/config/*.hpp") - - -add_library( sophiatx_config - config.cpp - include/sophiatx/config/config.hpp - ) -target_link_libraries( sophiatx_config fc ) - - -target_include_directories( sophiatx_config - PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ) - -if (USE_PCH) - cotire(sophiatx_config) -endif(USE_PCH) - -if( CLANG_TIDY_EXE ) - set_target_properties( - sophiatx_config PROPERTIES - CXX_CLANG_TIDY "${DO_CLANG_TIDY}" - ) -endif( CLANG_TIDY_EXE ) - -if(MSVC) - set_source_files_properties( config.cpp PROPERTIES COMPILE_FLAGS "/bigobj" ) -endif(MSVC) - - - -INSTALL( TARGETS - sophiatx_config - - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - ) -INSTALL( FILES ${HEADERS} DESTINATION "include/sophiatx/config" ) diff --git a/libraries/config/config.cpp b/libraries/config/config.cpp deleted file mode 100644 index 6632df94..00000000 --- a/libraries/config/config.cpp +++ /dev/null @@ -1,132 +0,0 @@ - -#include -#include -#include -#include -#include -#include - -using boost::any_cast; - -namespace sophiatx { namespace config { - -namespace{ - -fc::variant get_from_any(const boost::any& a) -{ - fc::variant ret; - if( ! a.empty()) { - //first, try int - if( a.type() == typeid(uint16_t)) - ret = any_cast(a); - else - if( a.type() == typeid(int16_t)) - ret = any_cast(a); - else - if( a.type() == typeid(uint32_t)) - ret = any_cast(a); - else - if( a.type() == typeid(int32_t)) - ret = any_cast(a); - else - if( a.type() == typeid(uint64_t)) - ret = any_cast(a); - else - if( a.type() == typeid(int64_t)) - ret = any_cast(a); - else - if( a.type() == typeid(bool)) - ret = any_cast(a); - else //string? - if( a.type() == typeid(std::string)) - ret = any_cast(a); - else - if( a.type() == typeid(boost::filesystem::path)) { - boost::filesystem::path tmp_ret = any_cast(a); - ret = tmp_ret.generic_string(); - } - else //vector? - if( a.type() == typeid(std::vector)){ - std::vector res; - res = any_cast>(a); - ret = res; - } - } - return ret; -} - - -} - -void configuration_manager::set_defaults_for_chain(const fc::sha256 &chain_id) -{ - for(const auto& i : _descriptions.values) - _variables.values[chain_id][i.first].value = i.second.default_value; -} - - -void configuration_manager::merge_descriptions_with_bpo(const bpo::options_description &descs) -{ - for( const auto& i : descs.options() ){ - boost::any def_val; - fc::variant vdef_val; - if(i->semantic()->apply_default(def_val)) { - vdef_val = get_from_any( def_val); - } - config_entry_description d(i->long_name(), i->description(), vdef_val ); - _descriptions.values[i->long_name()] = d; - } -} - -void configuration_manager::merge_chain_config_with_bpo(const bpo::variables_map &bpo_map, - const fc::sha256 &chain_id) -{ - for(const auto& i : bpo_map){ - const std::string& name = i.first; - const boost::any& value = i.second.value(); - fc::variant vvalue = get_from_any(value); - - _variables.values[chain_id][name].value = vvalue; - } -} - -void configuration_manager::store_to_file(std::string filename) -{ - std::map> extended_values; - for( const auto& chid : _variables.values ){ - for( const auto & desc : _descriptions.values ){ - extended_values[chid.first][desc.first].name = desc.second.name; - extended_values[chid.first][desc.first].description = desc.second.description; - extended_values[chid.first][desc.first].default_value = desc.second.default_value; - if(chid.second.count(desc.first)) - extended_values[ chid.first ][ desc.first ].value = chid.second.at(desc.first).value; - } - - } - - fc::variant file_config; - fc::to_variant(extended_values, file_config); - fc::json::save_to_file(file_config, filename, true); -} - -void configuration_manager::load_from_file(std::string filename) -{ - fc::variant file_config = fc::json::from_file(filename); - fc::from_variant(file_config, _variables.values); -} - -std::string configuration_manager::print_descriptions() -{ - fc::variant vdescriptions; - fc::to_variant( _descriptions.values, vdescriptions); - return fc::json::to_pretty_string(vdescriptions); -} - -std::string configuration_manager::print_configs() -{ - fc::variant voptions; - fc::to_variant( _variables.values, voptions); - return fc::json::to_pretty_string(voptions); -} - -}} //namespace sophiatx::config diff --git a/libraries/config/include/sophiatx/config/config.hpp b/libraries/config/include/sophiatx/config/config.hpp deleted file mode 100644 index e7aab7cb..00000000 --- a/libraries/config/include/sophiatx/config/config.hpp +++ /dev/null @@ -1,122 +0,0 @@ -// -// Created by Josef Sevcik on 2019-01-18. -// - -#pragma once -#include -#include -#include -#include -#include -#include -#include - -namespace bpo = boost::program_options; - -namespace sophiatx { namespace config { - -namespace{ -const static fc::sha256 _public_net_chain_id = fc::sha256("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); -} - -class config_entry_description{ -public: - std::string name; - std::string description; - fc::optional default_value; - config_entry_description(){} - config_entry_description(const std::string _name, std::string _description, fc::variant _default_value): name(_name), description(_description){ - if(!_default_value.is_null()) - default_value = _default_value; - } - config_entry_description(const config_entry_description& ced):name(ced.name),description(ced.description),default_value(ced.default_value){} - config_entry_description& operator=(const config_entry_description&ced){ - name = ced.name; - description = ced.description; - default_value = ced.default_value; - return *this; - } -}; - -class config_entry{ -public: - fc::variant value; -}; - -class extended_config_entry : public config_entry_description { -public: - fc::optional value; -}; - -struct variables{ - std::map> values; -}; - -struct descriptions{ - std::map values; -}; - -class configuration_manager { -public: - static configuration_manager &get_configuration_manager() { - static configuration_manager instance; - return instance; - } - - configuration_manager(configuration_manager const &) = delete; - - void operator=(configuration_manager const &) = delete; - - fc::variant get_variable(const std::string& name, const fc::sha256& chain_id = _public_net_chain_id){ - try { - return _variables.values.at(chain_id).at(name).value; - }catch(std::out_of_range){ - return fc::variant(); - } - }; - - void set_variable(const std::string& name, const fc::variant& value, const fc::sha256& chain_id = _public_net_chain_id ){ - _variables.values[chain_id][name].value = value; - }; - - void set_description(const std::string& name, const fc::variant& default_value, const std::string description ){ - FC_ASSERT( _descriptions.values.find(name) == _descriptions.values.end(), "description already exists" ); - _descriptions.values[name] = config_entry_description(name, description, default_value); - }; - - std::vector get_descriptions(){ - std::vector ret; - for(const auto& i: _descriptions.values ){ - ret.push_back(i.second); - } - return ret; - } - - void load_from_file(std::string filename); - void store_to_file(std::string filename); - std::string print_descriptions(); - std::string print_configs(); - void merge_chain_config_with_bpo( const bpo::variables_map& bpo_map, const fc::sha256& chain_id = _public_net_chain_id ); - void merge_descriptions_with_bpo( const bpo::options_description& descs); - void set_defaults_for_chain(const fc::sha256& chain_id); - - variables _variables; - descriptions _descriptions; - -private: - configuration_manager() { - }; - - -}; - -}} //namespace sophiatx::config - -FC_REFLECT(sophiatx::config::config_entry_description, (name)(description)(default_value)) -FC_REFLECT(sophiatx::config::variables, (values)) -FC_REFLECT(sophiatx::config::descriptions, (values)) -FC_REFLECT(sophiatx::config::config_entry, (value)) -FC_REFLECT_DERIVED(sophiatx::config::extended_config_entry, (sophiatx::config::config_entry_description), (value) ) - -FC_REFLECT(sophiatx::config::configuration_manager, (_variables)) - diff --git a/libraries/manifest/gensrc/plugins/mf_plugins.cpp b/libraries/manifest/gensrc/plugins/mf_plugins.cpp index 58508d06..22884a14 100644 --- a/libraries/manifest/gensrc/plugins/mf_plugins.cpp +++ b/libraries/manifest/gensrc/plugins/mf_plugins.cpp @@ -54,49 +54,49 @@ namespace sophiatx { namespace plugins { void register_plugins() { - appbase::app().register_plugin< sophiatx::plugins::witness::witness_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::witness::witness_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::account_history::account_history_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::account_history::account_history_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::subscribe::subscribe_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::subscribe::subscribe_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::custom::custom_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::custom::custom_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::witness::witness_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::witness::witness_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::network_broadcast_api::network_broadcast_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::network_broadcast_api::network_broadcast_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::database_api::database_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::database_api::database_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::alexandria_api::alexandria_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::alexandria_api::alexandria_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::chain::chain_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::chain::chain_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::account_by_key::account_by_key_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::account_by_key::account_by_key_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::block_api::block_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::block_api::block_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::debug_node::debug_node_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::debug_node::debug_node_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::condenser_api::condenser_api_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::condenser_api::condenser_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::multiparty_messaging::multiparty_messaging_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::multiparty_messaging::multiparty_messaging_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::account_history::account_history_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::account_history::account_history_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::chain::chain_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::chain::chain_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::debug_node::debug_node_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::debug_node::debug_node_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::webserver::webserver_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::webserver::webserver_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::template_plugin::template_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::template_plugin::template_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::p2p::p2p_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::p2p::p2p_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::block_log_info::block_log_info_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::block_log_info::block_log_info_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::account_by_key::account_by_key_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::account_by_key::account_by_key_plugin >(); } diff --git a/libraries/manifest/templates/plugins/mf_plugins.cpp.j2 b/libraries/manifest/templates/plugins/mf_plugins.cpp.j2 index 8251ae51..103f3901 100644 --- a/libraries/manifest/templates/plugins/mf_plugins.cpp.j2 +++ b/libraries/manifest/templates/plugins/mf_plugins.cpp.j2 @@ -12,7 +12,7 @@ namespace sophiatx { namespace plugins { void register_plugins() { {% for plugin in plugins %} - appbase::app().register_plugin< sophiatx::plugins::{{ plugin["plugin_namespace"] }}::{{ plugin["plugin_name" ] }}_plugin >(); + appbase::app_factory().register_plugin_factory< sophiatx::plugins::{{ plugin["plugin_namespace"] }}::{{ plugin["plugin_name" ] }}_plugin >(); {% endfor %} } diff --git a/libraries/plugins/account_by_key/account_by_key_plugin.cpp b/libraries/plugins/account_by_key/account_by_key_plugin.cpp index 2370c780..d45909ab 100644 --- a/libraries/plugins/account_by_key/account_by_key_plugin.cpp +++ b/libraries/plugins/account_by_key/account_by_key_plugin.cpp @@ -14,7 +14,7 @@ class account_by_key_plugin_impl { public: account_by_key_plugin_impl( account_by_key_plugin& _plugin ) : - _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), + _db( _plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), _self( _plugin ) {} void pre_operation( const operation_notification& op_obj ); @@ -209,7 +209,7 @@ void account_by_key_plugin::plugin_initialize( const boost::program_options::var try { ilog( "Initializing account_by_key plugin" ); - chain::database& db = appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); + chain::database& db = app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); my->pre_apply_connection = db.pre_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->pre_operation( o ); } ); my->post_apply_connection = db.post_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->post_operation( o ); } ); diff --git a/libraries/plugins/account_by_key/include/sophiatx/plugins/account_by_key/account_by_key_plugin.hpp b/libraries/plugins/account_by_key/include/sophiatx/plugins/account_by_key/account_by_key_plugin.hpp index 898df461..ed56124f 100644 --- a/libraries/plugins/account_by_key/include/sophiatx/plugins/account_by_key/account_by_key_plugin.hpp +++ b/libraries/plugins/account_by_key/include/sophiatx/plugins/account_by_key/account_by_key_plugin.hpp @@ -21,7 +21,7 @@ class account_by_key_plugin : public appbase::plugin< account_by_key_plugin > static const std::string& name() { static std::string name = SOPHIATX_ACCOUNT_BY_KEY_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/libraries/plugins/account_history/account_history_plugin.cpp b/libraries/plugins/account_history/account_history_plugin.cpp index efb0c662..f3439816 100644 --- a/libraries/plugins/account_history/account_history_plugin.cpp +++ b/libraries/plugins/account_history/account_history_plugin.cpp @@ -30,8 +30,8 @@ namespace detail { class account_history_plugin_impl { public: - account_history_plugin_impl() : - _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} + account_history_plugin_impl( account_history_plugin& plugin ) : + _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} virtual ~account_history_plugin_impl() {} @@ -218,7 +218,7 @@ void account_history_plugin::set_program_options( void account_history_plugin::plugin_initialize( const boost::program_options::variables_map& options ) { - my = std::make_unique< detail::account_history_plugin_impl >(); + my = std::make_unique< detail::account_history_plugin_impl >(*this); my->pre_apply_connection = my->_db.pre_apply_operation.connect( 0, [&]( const operation_notification& note ){ my->on_operation(note); } ); diff --git a/libraries/plugins/account_history/include/sophiatx/plugins/account_history/account_history_plugin.hpp b/libraries/plugins/account_history/include/sophiatx/plugins/account_history/account_history_plugin.hpp index 0dc6ce82..9a4ce95e 100644 --- a/libraries/plugins/account_history/include/sophiatx/plugins/account_history/account_history_plugin.hpp +++ b/libraries/plugins/account_history/include/sophiatx/plugins/account_history/account_history_plugin.hpp @@ -38,9 +38,9 @@ class account_history_plugin : public plugin< account_history_plugin > static const std::string& name() { static std::string name = SOPHIATX_ACCOUNT_HISTORY_PLUGIN_NAME; return name; } - virtual void set_program_options( + static void set_program_options( options_description& cli, - options_description& cfg ) override; + options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/libraries/plugins/apis/account_by_key_api/account_by_key_api.cpp b/libraries/plugins/apis/account_by_key_api/account_by_key_api.cpp index a5cce128..4ef44feb 100644 --- a/libraries/plugins/apis/account_by_key_api/account_by_key_api.cpp +++ b/libraries/plugins/apis/account_by_key_api/account_by_key_api.cpp @@ -10,7 +10,7 @@ namespace detail { class account_by_key_api_impl { public: - account_by_key_api_impl() : _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} + account_by_key_api_impl( account_by_key_api_plugin& plugin ) : _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} get_key_references_return get_key_references( const get_key_references_args& args )const; @@ -43,9 +43,9 @@ get_key_references_return account_by_key_api_impl::get_key_references( const get } // detail -account_by_key_api::account_by_key_api(): my( new detail::account_by_key_api_impl() ) +account_by_key_api::account_by_key_api(account_by_key_api_plugin& plugin): my( new detail::account_by_key_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_ACCOUNT_BY_KEY_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_ACCOUNT_BY_KEY_API_PLUGIN_NAME, plugin.app() ); } account_by_key_api::~account_by_key_api() {} diff --git a/libraries/plugins/apis/account_by_key_api/account_by_key_api_plugin.cpp b/libraries/plugins/apis/account_by_key_api/account_by_key_api_plugin.cpp index 6f1ce7ca..3bb4b1c6 100644 --- a/libraries/plugins/apis/account_by_key_api/account_by_key_api_plugin.cpp +++ b/libraries/plugins/apis/account_by_key_api/account_by_key_api_plugin.cpp @@ -10,7 +10,7 @@ account_by_key_api_plugin::~account_by_key_api_plugin() {} void account_by_key_api_plugin::set_program_options( options_description& cli, options_description& cfg ) {} void account_by_key_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< account_by_key_api >(); + api = std::make_shared< account_by_key_api >(*this); } void account_by_key_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api.hpp b/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api.hpp index 2234096c..2549cce4 100644 --- a/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api.hpp +++ b/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api.hpp @@ -27,7 +27,7 @@ struct get_key_references_return class account_by_key_api { public: - account_by_key_api(); + account_by_key_api(account_by_key_api_plugin& plugin ); ~account_by_key_api(); DECLARE_API( (get_key_references) ) diff --git a/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api_plugin.hpp b/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api_plugin.hpp index a8bc82dd..6669ff93 100644 --- a/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api_plugin.hpp +++ b/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api_plugin.hpp @@ -24,7 +24,7 @@ class account_by_key_api_plugin : public appbase::plugin< account_by_key_api_plu static const std::string& name() { static std::string name = SOPHIATX_ACCOUNT_BY_KEY_API_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; diff --git a/libraries/plugins/apis/account_history_api/account_history_api.cpp b/libraries/plugins/apis/account_history_api/account_history_api.cpp index afc3a347..ccb7ae5e 100644 --- a/libraries/plugins/apis/account_history_api/account_history_api.cpp +++ b/libraries/plugins/apis/account_history_api/account_history_api.cpp @@ -12,7 +12,7 @@ namespace detail { class account_history_api_impl { public: - account_history_api_impl() : _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} + account_history_api_impl(account_history_api_plugin& plugin) : _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} DECLARE_API_IMPL( (get_ops_in_block) @@ -108,9 +108,9 @@ DEFINE_API_IMPL( account_history_api_impl, get_account_history ) } // detail -account_history_api::account_history_api(): my( new detail::account_history_api_impl() ) +account_history_api::account_history_api(account_history_api_plugin& plugin): my( new detail::account_history_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_ACCOUNT_HISTORY_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_ACCOUNT_HISTORY_API_PLUGIN_NAME, plugin.app() ); } account_history_api::~account_history_api() {} diff --git a/libraries/plugins/apis/account_history_api/account_history_api_plugin.cpp b/libraries/plugins/apis/account_history_api/account_history_api_plugin.cpp index dcdd81a8..72b04a1b 100644 --- a/libraries/plugins/apis/account_history_api/account_history_api_plugin.cpp +++ b/libraries/plugins/apis/account_history_api/account_history_api_plugin.cpp @@ -11,7 +11,7 @@ void account_history_api_plugin::set_program_options( options_description& cli, void account_history_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< account_history_api >(); + api = std::make_shared< account_history_api >(*this); } void account_history_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api.hpp b/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api.hpp index e03deac5..c884710e 100644 --- a/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api.hpp +++ b/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api.hpp @@ -10,7 +10,7 @@ namespace detail { class account_history_api_impl; } class account_history_api { public: - account_history_api(); + account_history_api(account_history_api_plugin& plugin); ~account_history_api(); DECLARE_API( diff --git a/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api_plugin.hpp b/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api_plugin.hpp index c5918c19..a66e4bcf 100644 --- a/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api_plugin.hpp +++ b/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api_plugin.hpp @@ -23,7 +23,7 @@ class account_history_api_plugin : public plugin< account_history_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_ACCOUNT_HISTORY_API_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; diff --git a/libraries/plugins/apis/alexandria_api/alexandria_api_impl.cpp b/libraries/plugins/apis/alexandria_api/alexandria_api_impl.cpp index 44a2f259..474dc772 100644 --- a/libraries/plugins/apis/alexandria_api/alexandria_api_impl.cpp +++ b/libraries/plugins/apis/alexandria_api/alexandria_api_impl.cpp @@ -9,8 +9,8 @@ namespace sophiatx { namespace plugins { namespace alexandria_api { -alexandria_api_impl::alexandria_api_impl() - : _db(appbase::app().get_plugin().db()) {} +alexandria_api_impl::alexandria_api_impl(alexandria_api_plugin& plugin) + : _db(plugin.app()->get_plugin().db()) {} alexandria_api_impl::~alexandria_api_impl() {} diff --git a/libraries/plugins/apis/alexandria_api/alexandria_api_plugin.cpp b/libraries/plugins/apis/alexandria_api/alexandria_api_plugin.cpp index 9955c095..ea510524 100644 --- a/libraries/plugins/apis/alexandria_api/alexandria_api_plugin.cpp +++ b/libraries/plugins/apis/alexandria_api/alexandria_api_plugin.cpp @@ -12,7 +12,7 @@ void alexandria_api_plugin::set_program_options( void alexandria_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< alexandria_api >(); + api = std::make_shared< alexandria_api >( ); } void alexandria_api_plugin::plugin_startup() { diff --git a/libraries/plugins/block_log_info/block_log_info_plugin.cpp b/libraries/plugins/block_log_info/block_log_info_plugin.cpp index 20d0f325..18678f5b 100644 --- a/libraries/plugins/block_log_info/block_log_info_plugin.cpp +++ b/libraries/plugins/block_log_info/block_log_info_plugin.cpp @@ -19,7 +19,7 @@ class block_log_info_plugin_impl { public: block_log_info_plugin_impl( block_log_info_plugin& _plugin ) : - _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), + _db( _plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), _self( _plugin ) {} void on_applied_block( const signed_block& b ); @@ -147,7 +147,7 @@ void block_log_info_plugin::plugin_initialize( const boost::program_options::var try { ilog( "Initializing block_log_info plugin" ); - chain::database& db = appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); + chain::database& db = app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); my->on_applied_block_connection = db.applied_block.connect( [&]( const signed_block& b ){ my->on_applied_block( b ); } ); diff --git a/libraries/plugins/chain/chain_plugin.cpp b/libraries/plugins/chain/chain_plugin.cpp index ad74fe7e..717aa1a6 100644 --- a/libraries/plugins/chain/chain_plugin.cpp +++ b/libraries/plugins/chain/chain_plugin.cpp @@ -333,37 +333,21 @@ void chain_plugin::plugin_initialize(const variables_map& options) { auto initial_state = [&] { - if( private_net){ - if ( options.count("initminer-account-pubkey")) { - // Creates genesis based on provided initminer account public key - genesis_state_type genesis; - genesis.genesis_time = time_point_sec::from_iso_string("2018-01-01T08:00:00"); - genesis.initial_balace = 0; - genesis.initial_public_key = public_key_type(options.at( "initminer-account-pubkey" ).as< std::string >()); - genesis.is_private_net = true; - - fc::sha256::encoder enc; - fc::raw::pack( enc, genesis ); - genesis.initial_chain_id = enc.result(); - - return genesis; - } - // private net might be also started with custom genesis file - else { - if (options.count("genesis-json") == 0) { - genesis_state_type genesis; - genesis.genesis_time = time_point_sec::from_iso_string("2018-01-01T08:00:00"); - genesis.initial_balace = 0; - genesis.initial_public_key = public_key_type(options.at( "initminer-mining-pubkey" ).as< std::string >()); - genesis.is_private_net = true; - - fc::sha256::encoder enc; - fc::raw::pack( enc, genesis ); - genesis.initial_chain_id = enc.result(); - - return genesis; - } - } + if( (private_net && options.count("initminer-account-pubkey")) || + (private_net && options.count("genesis-json") == 0 ) ){ + genesis_state_type genesis; + genesis.genesis_time = time_point_sec::from_iso_string("2018-01-01T08:00:00"); + genesis.initial_balace = 0; + genesis.initial_public_key = options.count("initminer-account-pubkey") ? + public_key_type(options.at( "initminer-account-pubkey" ).as< std::string >()) : + public_key_type(options.at( "initminer-mining-pubkey" ).as< std::string >()); + genesis.is_private_net = true; + + fc::sha256::encoder enc; + fc::raw::pack( enc, genesis ); + genesis.initial_chain_id = enc.result(); + + return genesis; } if( options.count("genesis-json") ) @@ -424,12 +408,12 @@ void chain_plugin::plugin_startup() chain_id_type chain_id = my->genesis.compute_chain_id(); - my->shared_memory_dir = app().data_dir() / chain_id.str() / "blockchain"; + my->shared_memory_dir = app_factory().data_dir / chain_id.str() / "blockchain"; // correct directories, TODO can be removed after next HF2 - if( ! my->genesis.is_private_net && bfs::exists( app().data_dir() / "blockchain" ) ){ + if( ! my->genesis.is_private_net && bfs::exists( app_factory().data_dir / "blockchain" ) ){ bfs::create_directories ( my->shared_memory_dir ); - bfs::rename( app().data_dir() / "blockchain", my->shared_memory_dir ); + bfs::rename( app_factory().data_dir / "blockchain", my->shared_memory_dir ); } elog("Starting node with chain id ${i}", ("i", chain_id)); @@ -528,7 +512,7 @@ void chain_plugin::plugin_startup() if( my->stop_replay_at > 0 && my->stop_replay_at == last_block_number ) { ilog("Stopped blockchain replaying on user request. Last applied block number: ${n}.", ("n", last_block_number)); - appbase::app().quit(); + app()->quit(); return; } } diff --git a/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin.hpp b/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin.hpp index 64ca50cc..a0889a02 100644 --- a/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin.hpp +++ b/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin.hpp @@ -29,7 +29,7 @@ class chain_plugin : public plugin< chain_plugin > static const std::string& name() { static std::string name = SOPHIATX_CHAIN_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/libraries/plugins/debug_node/debug_node_plugin.cpp b/libraries/plugins/debug_node/debug_node_plugin.cpp index dba3bb94..50fc2f57 100644 --- a/libraries/plugins/debug_node/debug_node_plugin.cpp +++ b/libraries/plugins/debug_node/debug_node_plugin.cpp @@ -21,15 +21,15 @@ namespace detail { class debug_node_plugin_impl { public: - debug_node_plugin_impl(); - virtual ~debug_node_plugin_impl(); + debug_node_plugin_impl( debug_node_plugin& _plugin); + virtual ~debug_node_plugin_impl( ); chain::database& _db; boost::signals2::connection applied_block_connection; }; -debug_node_plugin_impl::debug_node_plugin_impl() : - _db( appbase::app().get_plugin< chain::chain_plugin >().db() ) {} +debug_node_plugin_impl::debug_node_plugin_impl(debug_node_plugin& _plugin) : + _db( _plugin.app()->get_plugin< chain::chain_plugin >().db() ) {} debug_node_plugin_impl::~debug_node_plugin_impl() {} } diff --git a/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp b/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp index 71db64cb..6d864710 100644 --- a/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp +++ b/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp @@ -37,15 +37,15 @@ #define SOPHIATX_JSON_RPC_PLUGIN_NAME "json_rpc" -#define JSON_RPC_REGISTER_API( API_NAME ) \ +#define JSON_RPC_REGISTER_API( API_NAME, APP ) \ { \ - sophiatx::plugins::json_rpc::detail::register_api_method_visitor vtor( API_NAME ); \ + sophiatx::plugins::json_rpc::detail::register_api_method_visitor vtor( API_NAME, APP ); \ for_each_api( vtor ); \ } -#define JSON_RPC_REGISTER_SUBSCRIBE_API( API_NAME ) \ +#define JSON_RPC_REGISTER_SUBSCRIBE_API( API_NAME, APP ) \ { \ - sophiatx::plugins::json_rpc::detail::register_api_subscribe_method_visitor vtor( API_NAME ); \ + sophiatx::plugins::json_rpc::detail::register_api_subscribe_method_visitor vtor( API_NAME, APP ); \ for_each_api( vtor ); \ } @@ -98,7 +98,7 @@ class json_rpc_plugin : public appbase::plugin< json_rpc_plugin > virtual ~json_rpc_plugin(); APPBASE_PLUGIN_REQUIRES(); - virtual void set_program_options( options_description&, options_description& ) override; + static void set_program_options( options_description&, options_description& ); static const std::string& name() { static std::string name = SOPHIATX_JSON_RPC_PLUGIN_NAME; return name; } @@ -122,9 +122,9 @@ namespace detail { class register_api_method_visitor { public: - register_api_method_visitor( const std::string& api_name ) + register_api_method_visitor( const std::string& api_name, const std::shared_ptr& app ) : _api_name( api_name ), - _json_rpc_plugin( appbase::app().get_plugin< sophiatx::plugins::json_rpc::json_rpc_plugin >() ) + _json_rpc_plugin( app->get_plugin< sophiatx::plugins::json_rpc::json_rpc_plugin >() ) {} template< typename Plugin, typename Method, typename Args, typename Ret > @@ -151,9 +151,9 @@ namespace detail { class register_api_subscribe_method_visitor { public: - register_api_subscribe_method_visitor( const std::string& api_name ) + register_api_subscribe_method_visitor( const std::string& api_name, const std::shared_ptr& app ) : _api_name( api_name ), - _json_rpc_plugin( appbase::app().get_plugin< sophiatx::plugins::json_rpc::json_rpc_plugin >() ) + _json_rpc_plugin( app->get_plugin< sophiatx::plugins::json_rpc::json_rpc_plugin >() ) {} template< typename Plugin, typename Method, typename Args, typename Ret > diff --git a/libraries/plugins/json_rpc/json_rpc_plugin.cpp b/libraries/plugins/json_rpc/json_rpc_plugin.cpp index 965ba854..30d9ab2b 100644 --- a/libraries/plugins/json_rpc/json_rpc_plugin.cpp +++ b/libraries/plugins/json_rpc/json_rpc_plugin.cpp @@ -128,7 +128,7 @@ namespace detail class json_rpc_plugin_impl { public: - json_rpc_plugin_impl(); + json_rpc_plugin_impl(json_rpc_plugin& plugin); ~json_rpc_plugin_impl(); void add_api_method( const string& api_name, const string& method_name, const api_method& api, const api_method_signature& sig ); @@ -159,9 +159,10 @@ namespace detail std::unique_ptr< json_rpc_logger > _logger; vector _subscribe_methods; map > _subscribe_callbacks; + json_rpc_plugin& _plugin; }; - json_rpc_plugin_impl::json_rpc_plugin_impl() {} + json_rpc_plugin_impl::json_rpc_plugin_impl(json_rpc_plugin& plugin):_plugin(plugin) {} json_rpc_plugin_impl::~json_rpc_plugin_impl() {} void json_rpc_plugin_impl::add_api_method( const string& api_name, const string& method_name, const api_method& api, const api_method_signature& sig ) @@ -183,7 +184,7 @@ namespace detail void json_rpc_plugin_impl::initialize() { - JSON_RPC_REGISTER_API( "jsonrpc" ); + JSON_RPC_REGISTER_API( "jsonrpc", _plugin.app() ); } get_methods_return json_rpc_plugin_impl::get_methods( const get_methods_args& args, bool lock ) @@ -421,7 +422,7 @@ using detail::json_rpc_error; using detail::json_rpc_response; using detail::json_rpc_logger; -json_rpc_plugin::json_rpc_plugin() : my( new detail::json_rpc_plugin_impl() ) {} +json_rpc_plugin::json_rpc_plugin() : my( new detail::json_rpc_plugin_impl( *this ) ) {} json_rpc_plugin::~json_rpc_plugin() {} void json_rpc_plugin::set_program_options( options_description& , options_description& cfg) diff --git a/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp b/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp index 2b38f5b9..1ba7be44 100644 --- a/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp +++ b/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp @@ -18,7 +18,7 @@ class multiparty_messaging_plugin_impl : public custom_operation_interpreter { public: multiparty_messaging_plugin_impl( multiparty_messaging_plugin& _plugin ) : - _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), + _db( _plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), _self( _plugin ), app_id(_plugin.app_id) { } diff --git a/libraries/plugins/p2p/p2p_plugin.cpp b/libraries/plugins/p2p/p2p_plugin.cpp index 4ce5917a..fa0f2edd 100644 --- a/libraries/plugins/p2p/p2p_plugin.cpp +++ b/libraries/plugins/p2p/p2p_plugin.cpp @@ -494,7 +494,7 @@ void p2p_plugin::set_program_options( bpo::options_description& cli, bpo::option void p2p_plugin::plugin_initialize(const boost::program_options::variables_map& options) { - my = std::make_unique< detail::p2p_plugin_impl >( appbase::app().get_plugin< plugins::chain::chain_plugin >() ); + my = std::make_unique< detail::p2p_plugin_impl >( app() -> get_plugin< plugins::chain::chain_plugin >() ); if( options.count( "p2p-endpoint" ) ) my->endpoint = fc::ip::endpoint::from_string( options.at( "p2p-endpoint" ).as< string >() ); diff --git a/libraries/plugins/template_plugin/template_plugin.cpp b/libraries/plugins/template_plugin/template_plugin.cpp index 24173e9e..56617098 100644 --- a/libraries/plugins/template_plugin/template_plugin.cpp +++ b/libraries/plugins/template_plugin/template_plugin.cpp @@ -14,7 +14,7 @@ class template_plugin_impl { public: template_plugin_impl( template_plugin& _plugin ) : - _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), + _db( _plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), _self( _plugin ) {} void pre_operation( const operation_notification& op_obj ); diff --git a/libraries/plugins/webserver/webserver_plugin.cpp b/libraries/plugins/webserver/webserver_plugin.cpp index 0c7ccca8..1eb8652e 100644 --- a/libraries/plugins/webserver/webserver_plugin.cpp +++ b/libraries/plugins/webserver/webserver_plugin.cpp @@ -516,10 +516,10 @@ void webserver_plugin::plugin_initialize( const variables_map& options ) void webserver_plugin::plugin_startup() { - my->api = appbase::app().find_plugin< plugins::json_rpc::json_rpc_plugin >(); + my->api = app() -> find_plugin< plugins::json_rpc::json_rpc_plugin >(); FC_ASSERT( my->api != nullptr, "Could not find API Register Plugin" ); - plugins::chain::chain_plugin* chain = appbase::app().find_plugin< plugins::chain::chain_plugin >(); + plugins::chain::chain_plugin* chain = app() -> find_plugin< plugins::chain::chain_plugin >(); if( chain != nullptr && chain->get_state() != appbase::abstract_plugin::started ) { ilog( "Waiting for chain plugin to start" ); diff --git a/libraries/plugins/witness/witness_plugin.cpp b/libraries/plugins/witness/witness_plugin.cpp index 6cdf50f4..fe5cb162 100644 --- a/libraries/plugins/witness/witness_plugin.cpp +++ b/libraries/plugins/witness/witness_plugin.cpp @@ -49,10 +49,11 @@ namespace detail { class witness_plugin_impl { public: - witness_plugin_impl( boost::asio::io_service& io ) : + witness_plugin_impl( witness_plugin& plugin, boost::asio::io_service& io ) : _timer(io), - _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), - _chain_plugin( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >()) {} + _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), + _chain_plugin( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >()), + _p2p_plugin( plugin.app()->get_plugin()){} void pre_transaction( const sophiatx::protocol::signed_transaction& trx ); void pre_operation( const chain::operation_notification& note ); @@ -72,6 +73,7 @@ namespace detail { chain::database& _db; plugins::chain::chain_plugin& _chain_plugin; + plugins::p2p::p2p_plugin& _p2p_plugin; boost::signals2::connection pre_apply_connection; boost::signals2::connection applied_block_connection; boost::signals2::connection on_pre_apply_transaction_connection; @@ -254,7 +256,7 @@ namespace detail { block_production_condition::block_production_condition_enum witness_plugin_impl::block_production_loop() { - chain::database& db = appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); + chain::database& db = _db; if( fc::time_point::now() < fc::time_point(db.get_genesis_time()) ) { wlog( "waiting until genesis time to produce block: ${t}, now is: ${n}", ("t", db.get_genesis_time())("n", fc::time_point::now()) ); @@ -324,7 +326,7 @@ namespace detail { block_production_condition::block_production_condition_enum witness_plugin_impl::maybe_produce_block(fc::mutable_variant_object& capture) { - chain::database& db = appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); + chain::database& db = _db; fc::time_point now_fine = fc::time_point::now(); fc::time_point_sec now = now_fine + fc::microseconds( 500000 ); @@ -395,7 +397,7 @@ namespace detail { ); capture("n", block.block_num())("t", block.timestamp)("c", now); - appbase::app().get_plugin< sophiatx::plugins::p2p::p2p_plugin >().broadcast_block( block ); + _p2p_plugin.broadcast_block( block ); return block_production_condition::produced; } @@ -421,7 +423,7 @@ void witness_plugin::set_program_options( void witness_plugin::plugin_initialize(const boost::program_options::variables_map& options) { try { - my = std::make_unique< detail::witness_plugin_impl >( appbase::app().get_io_service() ); + my = std::make_unique< detail::witness_plugin_impl >( *this, app()->get_io_service() ); SOPHIATX_LOAD_VALUE_SET( options, "witness", my->_witnesses, sophiatx::protocol::account_name_type ) @@ -457,12 +459,12 @@ void witness_plugin::plugin_initialize(const boost::program_options::variables_m void witness_plugin::plugin_startup() { try { ilog("witness plugin: plugin_startup() begin"); - chain::database& d = appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); + chain::database& d = app()->template get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); if( !my->_witnesses.empty() ) { ilog( "Launching block production for ${n} witnesses.", ("n", my->_witnesses.size()) ); - appbase::app().get_plugin< sophiatx::plugins::p2p::p2p_plugin >().set_block_production( true ); + app()->template get_plugin< sophiatx::plugins::p2p::p2p_plugin >().set_block_production( true ); if( my->_production_enabled ) { if( d.head_block_num() == 0 ) diff --git a/programs/sophiatxd/CMakeLists.txt b/programs/sophiatxd/CMakeLists.txt index 1fc51cff..a9327217 100644 --- a/programs/sophiatxd/CMakeLists.txt +++ b/programs/sophiatxd/CMakeLists.txt @@ -15,7 +15,6 @@ if( SOPHIATX_STATIC_BUILD ) appbase sophiatx_utilities sophiatx_plugins - sophiatx_config ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) @@ -24,7 +23,6 @@ else( SOPHIATX_STATIC_BUILD ) appbase sophiatx_utilities sophiatx_plugins - sophiatx_config ${CMAKE_DL_LIBS} ${PLATFORM_SPECIFIC_LIBS} ) diff --git a/programs/sophiatxd/main.cpp b/programs/sophiatxd/main.cpp index 48d2ff58..e013c595 100644 --- a/programs/sophiatxd/main.cpp +++ b/programs/sophiatxd/main.cpp @@ -75,10 +75,10 @@ int main( int argc, char** argv ) options.add_options() ("backtrace", bpo::value< string >()->default_value( "yes" ), "Whether to print backtrace on SIGSEGV" ); - appbase::app().add_program_options( bpo::options_description(), options ); + appbase::app_factory().add_program_options( options ); sophiatx::plugins::register_plugins(); - appbase::app().set_version_string( version_string() ); + appbase::app_factory().set_version_string( version_string() ); bool initialized = appbase::app().initialize< sophiatx::plugins::chain::chain_plugin, @@ -91,14 +91,11 @@ int main( int argc, char** argv ) if( !initialized ) return 0; - auto& args = appbase::app().get_args(); - - debug_config(appbase::app().get_options(), args); - + auto& args = appbase::app_factory().global_args; try { - fc::optional< fc::logging_config > logging_config = sophiatx::utilities::load_logging_config( args, appbase::app().data_dir() ); + fc::optional< fc::logging_config > logging_config = sophiatx::utilities::load_logging_config( args, appbase::app_factory().data_dir ); if( logging_config ) fc::configure_logging( *logging_config ); } From d21c82eb403fbe24d7d4c9517bca702ceafccd46 Mon Sep 17 00:00:00 2001 From: ejossev Date: Wed, 30 Jan 2019 18:14:29 +0100 Subject: [PATCH 04/17] stable version --- CMakeLists.txt | 1 + .../track_and_trace/track_and_trace_api.hpp | 4 +- .../track_and_trace_plugin.hpp | 4 +- .../track_and_trace/track_and_trace_api.cpp | 6 +- .../track_and_trace_plugin.cpp | 6 +- .../track_and_trace_plugin_export.cpp | 6 +- libraries/appbase/application.cpp | 125 +++++++++--------- libraries/appbase/examples/main.cpp | 2 +- .../appbase/include/appbase/application.hpp | 63 ++++++--- libraries/appbase/include/appbase/plugin.hpp | 14 +- libraries/chain/database.cpp | 1 + .../account_by_key_api/account_by_key_api.hpp | 2 + .../account_history_api.hpp | 1 + .../apis/alexandria_api/alexandria_api.cpp | 24 ++-- .../alexandria_api/alexandria_api_impl.cpp | 12 +- .../alexandria_api/alexandria_api_plugin.cpp | 2 +- .../plugins/alexandria_api/alexandria_api.hpp | 4 +- .../alexandria_api/alexandria_api_impl.hpp | 4 +- .../alexandria_api/alexandria_api_plugin.hpp | 4 +- .../plugins/apis/block_api/block_api.cpp | 12 +- .../apis/block_api/block_api_plugin.cpp | 2 +- .../sophiatx/plugins/block_api/block_api.hpp | 3 +- .../plugins/block_api/block_api_plugin.hpp | 4 +- .../plugins/apis/chain_api/chain_api.cpp | 6 +- .../apis/chain_api/chain_api_plugin.cpp | 2 +- .../sophiatx/plugins/chain_api/chain_api.hpp | 3 +- .../plugins/chain_api/chain_api_plugin.hpp | 2 +- .../plugins/apis/custom_api/custom_api.cpp | 6 +- .../apis/custom_api/custom_api_plugin.cpp | 2 +- .../plugins/custom_api/custom_api.hpp | 3 +- .../plugins/custom_api/custom_api_plugin.hpp | 2 +- .../apis/database_api/database_api.cpp | 12 +- .../apis/database_api/database_api_plugin.cpp | 2 +- .../plugins/database_api/database_api.hpp | 3 +- .../database_api/database_api_plugin.hpp | 4 +- .../apis/debug_node_api/debug_node_api.cpp | 10 +- .../debug_node_api/debug_node_api_plugin.cpp | 2 +- .../plugins/debug_node_api/debug_node_api.hpp | 4 +- .../debug_node_api/debug_node_api_plugin.hpp | 2 +- .../network_broadcast_api.hpp | 4 +- .../network_broadcast_api_plugin.hpp | 2 +- .../network_broadcast_api.cpp | 10 +- .../network_broadcast_api_plugin.cpp | 2 +- .../plugins/subscribe_api/subscribe_api.hpp | 3 +- .../subscribe_api/subscribe_api_plugin.hpp | 2 +- .../apis/subscribe_api/subscribe_api.cpp | 17 +-- .../subscribe_api/subscribe_api_plugin.cpp | 2 +- .../plugins/test_api/test_api_plugin.hpp | 2 +- .../plugins/apis/test_api/test_api_plugin.cpp | 2 +- .../plugins/witness_api/witness_api.hpp | 3 +- .../witness_api/witness_api_plugin.hpp | 2 +- .../plugins/apis/witness_api/witness_api.cpp | 6 +- .../apis/witness_api/witness_api_plugin.cpp | 2 +- .../block_log_info/block_log_info_plugin.hpp | 2 +- libraries/plugins/chain/chain_plugin_full.cpp | 2 +- libraries/plugins/chain/chain_plugin_lite.cpp | 4 +- .../sophiatx/plugins/chain/chain_plugin.hpp | 2 +- .../plugins/chain/chain_plugin_full.hpp | 2 +- .../plugins/chain/chain_plugin_lite.hpp | 2 +- .../plugins/debug_node/debug_node_plugin.cpp | 3 +- .../plugins/debug_node/debug_node_plugin.hpp | 4 +- .../plugins/json_rpc/json_rpc_plugin.hpp | 2 +- .../multiparty_messaging_plugin.hpp | 4 +- .../multiparty_messaging_api.cpp | 13 +- .../multiparty_messaging_plugin.cpp | 2 +- .../sophiatx/plugins/p2p/p2p_plugin.hpp | 4 +- libraries/plugins/p2p/p2p_plugin.cpp | 4 +- .../plugins/template/template_api.hpp | 4 +- .../plugins/template/template_plugin.hpp | 4 +- .../plugins/template_plugin/template_api.cpp | 6 +- .../template_plugin/template_plugin.cpp | 4 +- .../plugins/webserver/webserver_plugin.hpp | 2 +- .../plugins/witness/witness_plugin.hpp | 4 +- libraries/plugins/witness/witness_plugin.cpp | 22 ++- programs/sophiatx_light/main.cpp | 21 ++- programs/sophiatxd/main.cpp | 16 +-- tests/db_fixture/database_fixture.cpp | 115 ++++++++-------- tests/db_fixture/database_fixture.hpp | 5 +- tests/tests/block_tests.cpp | 25 ++-- 79 files changed, 374 insertions(+), 334 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3354d065..a17bc8bb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,6 @@ # Defines SophiaTX library target. + find_program(CCACHE_PROGRAM ccache) if(CCACHE_PROGRAM) MESSAGE(STATUS "Building with ccache") diff --git a/external_plugins/track_and_trace/include/sophiatx/plugins/track_and_trace/track_and_trace_api.hpp b/external_plugins/track_and_trace/include/sophiatx/plugins/track_and_trace/track_and_trace_api.hpp index eb1c0e85..65bc7e5b 100644 --- a/external_plugins/track_and_trace/include/sophiatx/plugins/track_and_trace/track_and_trace_api.hpp +++ b/external_plugins/track_and_trace/include/sophiatx/plugins/track_and_trace/track_and_trace_api.hpp @@ -80,10 +80,12 @@ struct get_tracked_object_history_return vector history_items; }; +class track_and_trace_plugin; + class track_and_trace_api { public: - track_and_trace_api(); + track_and_trace_api(track_and_trace_plugin& plugin); ~track_and_trace_api(); DECLARE_API( (get_current_holder) (get_holdings) (get_tracked_object_history) (get_transfer_requests) (get_item_details)) diff --git a/external_plugins/track_and_trace/include/sophiatx/plugins/track_and_trace/track_and_trace_plugin.hpp b/external_plugins/track_and_trace/include/sophiatx/plugins/track_and_trace/track_and_trace_plugin.hpp index 197a5925..8db380c7 100644 --- a/external_plugins/track_and_trace/include/sophiatx/plugins/track_and_trace/track_and_trace_plugin.hpp +++ b/external_plugins/track_and_trace/include/sophiatx/plugins/track_and_trace/track_and_trace_plugin.hpp @@ -31,9 +31,9 @@ class track_and_trace_plugin : public plugin< track_and_trace_plugin > static const std::string& name() { static std::string name = SOPHIATX_TAT_PLUGIN_NAME; return name; } - virtual void set_program_options( + static void set_program_options( options_description& cli, - options_description& cfg ) override; + options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/external_plugins/track_and_trace/track_and_trace_api.cpp b/external_plugins/track_and_trace/track_and_trace_api.cpp index f902652b..6d208f19 100644 --- a/external_plugins/track_and_trace/track_and_trace_api.cpp +++ b/external_plugins/track_and_trace/track_and_trace_api.cpp @@ -9,7 +9,7 @@ namespace detail { class track_and_trace_api_impl { public: - track_and_trace_api_impl() : _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} + track_and_trace_api_impl(track_and_trace_plugin& plugin) : _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} get_current_holder_return get_current_holder( const get_current_holder_args& args )const; get_holdings_return get_holdings( const get_holdings_args& args )const; @@ -79,9 +79,9 @@ get_item_details_return track_and_trace_api_impl::get_item_details(const get_ite } // detail -track_and_trace_api::track_and_trace_api(): my( new detail::track_and_trace_api_impl() ) +track_and_trace_api::track_and_trace_api(track_and_trace_plugin& plugin): my( new detail::track_and_trace_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_TAT_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_TAT_PLUGIN_NAME, plugin.app() ); } track_and_trace_api::~track_and_trace_api() {} diff --git a/external_plugins/track_and_trace/track_and_trace_plugin.cpp b/external_plugins/track_and_trace/track_and_trace_plugin.cpp index 7a3d41ee..8a4168f9 100644 --- a/external_plugins/track_and_trace/track_and_trace_plugin.cpp +++ b/external_plugins/track_and_trace/track_and_trace_plugin.cpp @@ -25,7 +25,7 @@ class track_and_trace_plugin_impl { public: track_and_trace_plugin_impl( track_and_trace_plugin& _plugin ) : - _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), + _db( _plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), _self( _plugin ), app_id(_plugin.app_id) { interpreter = std::make_shared(_db); @@ -117,12 +117,12 @@ void track_and_trace_plugin::plugin_initialize( const boost::program_options::va return; } my = std::make_unique< detail::track_and_trace_plugin_impl >( *this ); - api = std::make_shared< track_and_trace_api >(); + api = std::make_shared< track_and_trace_api >( *this ); try { ilog( "Initializing track_and_trace_plugin_impl plugin" ); - auto& db = appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); + auto& db = app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); db->set_custom_operation_interpreter(app_id, dynamic_pointer_cast(my->interpreter)); add_plugin_index< posession_index >(db); diff --git a/external_plugins/track_and_trace/track_and_trace_plugin_export.cpp b/external_plugins/track_and_trace/track_and_trace_plugin_export.cpp index b2041881..f3d2fd5b 100644 --- a/external_plugins/track_and_trace/track_and_trace_plugin_export.cpp +++ b/external_plugins/track_and_trace/track_and_trace_plugin_export.cpp @@ -7,10 +7,14 @@ namespace sophiatx { namespace plugins { namespace track_and_trace_plugin { #pragma clang diagnostic ignored "-Wreturn-type-c-linkage" #endif -extern "C" BOOST_SYMBOL_EXPORT std::shared_ptr get_plugin() { +extern "C" BOOST_SYMBOL_EXPORT std::shared_ptr plugin_factory() { return std::make_shared(); } +extern "C" BOOST_SYMBOL_EXPORT void options_setter(options_description& cli, options_description& cfg) { + track_and_trace_plugin::set_program_options(cli, cfg); +} + #ifdef __clang__ #pragma clang diagnostic pop #endif diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index e4354805..4edf42cb 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -68,7 +68,7 @@ namespace{ bfs::path write_default_config( const options_description& options_desc, const bfs::path& cfg_file, std::string suffix = "" ) { bfs::path _cfg_file = cfg_file; if( suffix != "" ){ - _cfg_file += suffix; + _cfg_file += std::string(".") + suffix; } bfs::path config_file_name = app_factory().data_dir / "configs" / _cfg_file ; @@ -140,7 +140,7 @@ void application::startup() { plugin->startup(); } -plugin_program_options application_factory::get_plugin_program_options(std::shared_ptr & plugin_factory) { +plugin_program_options application_factory::get_plugin_program_options(std::shared_ptr plugin_factory) { options_description plugin_cli_opts("Command Line Options for " + plugin_factory->get_name()); options_description plugin_cfg_opts("Config Options for " + plugin_factory->get_name()); plugin_factory->set_program_options(plugin_cli_opts, plugin_cfg_opts); @@ -151,17 +151,7 @@ plugin_program_options application_factory::get_plugin_program_options(std::shar bool application::load_external_plugins() { // plugins-dir par (even if it is default) must be always present - assert(my->_args.count( "external-plugins-dir" )); - boost::program_options::variable_value cfg_plugins_dir = my->_args["external-plugins-dir"]; - bfs::path plugins_dir = cfg_plugins_dir.as(); - if (plugins_dir.is_relative() == true) { - plugins_dir = my->_data_dir / plugins_dir; - - if (bfs::exists(plugins_dir) == false) { - bfs::create_directory(plugins_dir); - } - } if(my->_args.count("external-plugin") > 0) { @@ -172,16 +162,18 @@ bool application::load_external_plugins() { boost::split(plugins_names, arg, boost::is_any_of(" \t,")); for(const std::string& plugin_name : plugins_names) { - bfs::path plugin_binary_path = plugins_dir / std::string("lib" + plugin_name + "_plugin.so"); + bfs::path plugin_binary_path = app_factory().plugins_dir / std::string("lib" + plugin_name + "_plugin.so"); if (bfs::exists(plugin_binary_path) == false) { std::cerr << "Missing binary: " << plugin_binary_path << " for plugin: \"" << plugin_name << "\"" << std::endl; return false; } std::shared_ptr loaded_plugin; + std::function options_setter; try { - auto plugin_creator = boost::dll::import()>(plugin_binary_path, "get_plugin", boost::dll::load_mode::append_decorations); - loaded_plugin = plugin_creator(); + auto plugin_factory = boost::dll::import()>(plugin_binary_path, "plugin_factory", boost::dll::load_mode::append_decorations); + options_setter = boost::dll::import(plugin_binary_path, "options_setter", boost::dll::load_mode::append_decorations); + loaded_plugin = plugin_factory(); } catch ( const boost::exception& e ) { @@ -189,12 +181,12 @@ bool application::load_external_plugins() { return false; } - loaded_plugin->set_app(shared_from_this()); + loaded_plugin->set_app( shared_from_this() ); // Registers loaded plugin for application register_external_plugin(loaded_plugin); // Loads plugins config parameters - load_external_plugin_config(loaded_plugin, plugin_name); + load_external_plugin_config(options_setter, plugin_name); // Initializes plugin loaded_plugin->initialize(my->_args); @@ -210,10 +202,10 @@ void application::register_external_plugin(const std::shared_ptrregister_dependencies(); } -void application::load_external_plugin_config(const std::shared_ptr& plugin, const std::string& cfg_plugin_name) { - options_description plugin_cli_opts("Command Line Options for " + plugin->get_name()); - options_description plugin_cfg_opts("Config Options for " + plugin->get_name()); - plugin->set_program_options(plugin_cli_opts, plugin_cfg_opts); +void application::load_external_plugin_config(const std::function options_setter, const std::string& cfg_plugin_name) { + options_description plugin_cli_opts("Command Line Options for " + cfg_plugin_name); + options_description plugin_cfg_opts("Config Options for " + cfg_plugin_name); + options_setter(plugin_cli_opts, plugin_cfg_opts); // Writes config if it does not already exists bfs::path config_file_path = write_default_config(plugin_cfg_opts, bfs::path(cfg_plugin_name + "_plugin_config.ini"), id); @@ -362,38 +354,25 @@ void application_factory::set_program_options() app_options.add(app_cfg_opts); global_options.add(app_cli_opts); - - for(auto& plug : plugin_factories ) { - const plugin_program_options& plugin_options = get_plugin_program_options(plug); - - const options_description& plugin_cfg_options = plugin_options.get_cfg_options(); - if (plugin_cfg_options.options().size()) { - app_options.add(plugin_cfg_options); - } - - const options_description& plugin_cli_options = plugin_options.get_cli_options(); - if (plugin_cli_options.options().size()) { - global_options.add(plugin_cli_options); - } - } } -bool application_factory::initialize( int argc, char** argv, vector< string > _autostart_plugins ) +map> application_factory::initialize( int argc, char** argv, vector< string > _autostart_plugins, bool start_apps ) { try { + map> ret; bpo::store( bpo::parse_command_line( argc, argv, global_options ), global_args ); std::copy(_autostart_plugins.begin(), _autostart_plugins.end(), std::back_inserter(autostart_plugins)); if( global_args.count( "help" ) ) { cout << global_options << "\n"; - return false; + return ret; } if( global_args.count( "version" ) ) { cout << version_info << "\n"; - return false; + return ret; } // data-dir par (even if it is default) must be always present @@ -403,6 +382,20 @@ bool application_factory::initialize( int argc, char** argv, vector< string > _a if( data_dir.is_relative() ) data_dir = bfs::current_path() / data_dir; + assert(global_args.count( "external-plugins-dir" )); + + boost::program_options::variable_value cfg_plugins_dir = global_args["external-plugins-dir"]; + plugins_dir = cfg_plugins_dir.as(); + if (plugins_dir.is_relative() == true) { + plugins_dir = data_dir / plugins_dir; + + if (bfs::exists(plugins_dir) == false) { + bfs::create_directory(plugins_dir); + } + } + + + // config par (even if it is default) must be always present assert(global_args.count( "config" )); @@ -415,40 +408,46 @@ bool application_factory::initialize( int argc, char** argv, vector< string > _a //TODO: migrate the config here - if(global_args.count("startup-apps") > 0) - { - auto chains = global_args.at("startup-apps").as>(); - for(auto& arg : chains ) - { - vector names; - boost::split(names, arg, boost::is_any_of(" \t,")); - for(const std::string& name : names) - { - bfs::path config_file_path = write_default_config(app_options, global_args["config"].as(), name ); - variables_map app_args; - bpo::store(bpo::parse_config_file< char >( config_file_path.make_preferred().string().c_str(), - app_options, true ), app_args ); - auto new_app = new_application(app_args, name); - + if(start_apps) { + if( global_args.count("startup-apps") > 0 ) { + auto chains = global_args.at("startup-apps").as>(); + for( auto &arg : chains ) { + vector names; + boost::split(names, arg, boost::is_any_of(" \t,")); + for( const std::string &name : names ) { + variables_map app_args = read_app_config(name); + auto new_app = new_application(name); + new_app->initialize(app_args, autostart_plugins); + ret[ name ] = new_app; + } } + } else { + //load default (public) one. + variables_map app_args = read_app_config(_public_net_chain_id); + auto new_app = new_application(_public_net_chain_id); + new_app->initialize(app_args, autostart_plugins); + ret[ _public_net_chain_id ] = new_app; } - }else{ - //load default (public) one. - bfs::path config_file_path = write_default_config(app_options, global_args["config"].as(), _public_net_chain_id ); - variables_map app_args; - bpo::store(bpo::parse_config_file< char >( config_file_path.make_preferred().string().c_str(), - app_options, true ), app_args ); - auto new_app = new_application(app_args, _public_net_chain_id); } - - return true; + return ret; } catch (const boost::program_options::error& e) { + map> ret; std::cerr << "Error parsing command line: " << e.what() << "\n"; - return false; + return ret; } +} +variables_map application_factory::read_app_config(std::string name) +{ + bfs::path config_file_path = write_default_config(app_options, global_args[ "config" ].as(), + name); + variables_map app_args; + bpo::store(bpo::parse_config_file(config_file_path.make_preferred().string().c_str(), + app_options, true), app_args); + return app_args; } + } /// namespace appbase diff --git a/libraries/appbase/examples/main.cpp b/libraries/appbase/examples/main.cpp index 3020528c..09e4625b 100755 --- a/libraries/appbase/examples/main.cpp +++ b/libraries/appbase/examples/main.cpp @@ -92,7 +92,7 @@ int main( int argc, char** argv ) { try { appbase::app_factory().register_plugin_factory(); - if( !appbase::app_factory().initialize( argc, argv, {} ) ) + if( appbase::app_factory().initialize( argc, argv, {} ).size() == 0 ) return -1; appbase::app_factory().startup(); appbase::app_factory().exec(); diff --git a/libraries/appbase/include/appbase/application.hpp b/libraries/appbase/include/appbase/application.hpp index 5bd923b8..8acbad6a 100644 --- a/libraries/appbase/include/appbase/application.hpp +++ b/libraries/appbase/include/appbase/application.hpp @@ -89,19 +89,13 @@ namespace appbase { * * @param plugin */ - void load_external_plugin_config(const std::shared_ptr& plugin, const std::string& cfg_plugin_name); + void load_external_plugin_config(const std::function options_setter, const std::string& cfg_plugin_name); template< typename Plugin > Plugin* find_plugin()const { Plugin* plugin = dynamic_cast< Plugin* >( find_plugin( Plugin::name() ) ); - // Do not return plugins that are registered but not at least initialized. - if( plugin != nullptr && plugin->get_state() == abstract_plugin::registered ) - { - return nullptr; - } - return plugin; } @@ -114,6 +108,22 @@ namespace appbase { return *ptr; } + template< typename Plugin > + Plugin& get_or_create_plugin() + { + Plugin* plugin = dynamic_cast< Plugin* >( find_plugin( Plugin::name() ) ); + if( plugin != nullptr ) + return *plugin; + auto new_plg = std::make_shared(); + new_plg->set_app( shared_from_this() ); + plugins[ Plugin::name() ] = new_plg; + return *new_plg; + } + + void reset(){ + plugins.clear(); + } + bfs::path data_dir()const; const bpo::variables_map& get_args() const; @@ -159,54 +169,67 @@ namespace appbase { void operator=(application_factory const &) = delete; template void register_plugin_factory(){ + if( plugin_factories.find(P::name()) != plugin_factories.end() ) + return; std::shared_ptr> new_plugin_factory = std::make_shared>(); - plugin_factories.push_back(new_plugin_factory); + plugin_factories[P::name()] = new_plugin_factory; + const plugin_program_options& plugin_options = get_plugin_program_options(new_plugin_factory); + const options_description& plugin_cfg_options = plugin_options.get_cfg_options(); + if (plugin_cfg_options.options().size()) { + app_options.add(plugin_cfg_options); + } + + const options_description& plugin_cli_options = plugin_options.get_cli_options(); + if (plugin_cli_options.options().size()) { + app_options.add(plugin_cli_options); + } } - std::shared_ptr new_application(const variables_map& app_args, const string& id){ + std::shared_ptr new_application( const string& id){ std::shared_ptr new_app = std::make_shared(id ); + apps[id] = new_app; for( const auto& pf : plugin_factories){ - auto new_plugin = pf->new_plugin(new_app); + auto new_plugin = pf.second->new_plugin(new_app); new_app->register_plugin(new_plugin); } - apps.push_back(new_app); - new_app->initialize(app_args, autostart_plugins); return new_app; } void add_program_options( const bpo::options_description& cli ); + variables_map read_app_config(string name); - bool initialize( int argc, char** argv, vector< string > autostart_plugins ); + map> initialize( int argc, char** argv, vector< string > autostart_plugins, bool start_apps = true ); void set_version_string( const string& version ) { version_info = version; } options_description app_options; options_description global_options; bfs::path data_dir; + bfs::path plugins_dir; variables_map global_args; void startup(){ for(auto& app : apps) - app->startup(); + app.second->startup(); }; void exec(){ for(auto& app : apps) - app->exec(); + app.second->exec(); }; void shutdown(){ for(auto& app : apps) - app->shutdown(); + app.second->shutdown(); } void quit(){ for(auto& app : apps) - app->quit(); + app.second->quit(); } private: void set_program_options(); - vector> plugin_factories; + std::map> plugin_factories; vector autostart_plugins; - vector> apps; + std::map> apps; string version_info; application_factory():global_options("Application Options") { @@ -214,7 +237,7 @@ namespace appbase { }; - plugin_program_options get_plugin_program_options(std::shared_ptr & plugin_factory); + plugin_program_options get_plugin_program_options(std::shared_ptr plugin_factory); }; application_factory& app_factory(); diff --git a/libraries/appbase/include/appbase/plugin.hpp b/libraries/appbase/include/appbase/plugin.hpp index 48e01b12..590316d9 100644 --- a/libraries/appbase/include/appbase/plugin.hpp +++ b/libraries/appbase/include/appbase/plugin.hpp @@ -8,7 +8,7 @@ #include #define APPBASE_PLUGIN_REQUIRES_VISIT( r, visitor, elem ) \ - visitor( ( app()->get_plugin() ) ); + visitor( ( app()->get_or_create_plugin() ) ); #define APPBASE_PLUGIN_REQUIRES( PLUGINS ) \ virtual void plugin_for_each_dependency( plugin_processor&& l ) override { \ @@ -44,8 +44,8 @@ class abstract_plugin : std::enable_shared_from_this virtual void initialize(const variables_map& options) = 0; virtual void startup() = 0; virtual void shutdown() = 0; - void set_app(const std::shared_ptr& my_app) { _app = my_app; } - const std::shared_ptr app() { return _app; } + void set_app(std::shared_ptr my_app) { _app = my_app; } + std::shared_ptr app() { return _app; } protected: typedef std::function plugin_processor; @@ -84,7 +84,7 @@ class plugin : public abstract_plugin virtual void register_dependencies() override { - this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){} ); + //this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){} ); } virtual void initialize(const variables_map& options) override final @@ -147,9 +147,9 @@ class plugin_factory : public abstract_plugin_factory public: virtual ~plugin_factory(){} virtual std::shared_ptr new_plugin( std::shared_ptr new_app ) const final { - std::shared_ptr new_plugin = std::make_shared(); - new_plugin->set_app( new_app ); - return new_plugin; + std::shared_ptr new_plg = std::make_shared(); + new_plg->set_app( new_app ); + return new_plg; } virtual void set_program_options( options_description& cli, options_description& cfg ) { diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index 2e765ec0..b6540f58 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1,4 +1,5 @@ #include +#include #include #include diff --git a/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api.hpp b/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api.hpp index 2549cce4..2b24f15f 100644 --- a/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api.hpp +++ b/libraries/plugins/apis/account_by_key_api/include/sophiatx/plugins/account_by_key_api/account_by_key_api.hpp @@ -24,6 +24,8 @@ struct get_key_references_return std::vector< std::vector< sophiatx::protocol::account_name_type > > accounts; }; +class account_by_key_api_plugin; + class account_by_key_api { public: diff --git a/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api.hpp b/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api.hpp index c884710e..25664f4e 100644 --- a/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api.hpp +++ b/libraries/plugins/apis/account_history_api/include/sophiatx/plugins/account_history_api/account_history_api.hpp @@ -6,6 +6,7 @@ namespace sophiatx { namespace plugins { namespace account_history { namespace detail { class account_history_api_impl; } +class account_history_api_plugin; class account_history_api { diff --git a/libraries/plugins/apis/alexandria_api/alexandria_api.cpp b/libraries/plugins/apis/alexandria_api/alexandria_api.cpp index 69dc8741..a249e033 100644 --- a/libraries/plugins/apis/alexandria_api/alexandria_api.cpp +++ b/libraries/plugins/apis/alexandria_api/alexandria_api.cpp @@ -19,57 +19,57 @@ namespace sophiatx { namespace plugins { namespace alexandria_api { -alexandria_api::alexandria_api() - : my( new alexandria_api_impl() ) +alexandria_api::alexandria_api(alexandria_api_plugin& plugin) + : my( new alexandria_api_impl(plugin) ), _plugin(plugin) { - JSON_RPC_REGISTER_API( SOPHIATX_ALEXANDRIA_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_ALEXANDRIA_API_PLUGIN_NAME, _plugin.app() ); } alexandria_api::~alexandria_api() {} void alexandria_api::init() { - auto database = appbase::app().find_plugin< database_api::database_api_plugin >(); + auto database = _plugin.app()->find_plugin< database_api::database_api_plugin >(); if( database != nullptr ) { my->set_database_api(database->api); } - auto block = appbase::app().find_plugin< block_api::block_api_plugin >(); + auto block = _plugin.app()->find_plugin< block_api::block_api_plugin >(); if( block != nullptr ) { my->set_block_api(block->api); } - auto account_by_key = appbase::app().find_plugin< account_by_key::account_by_key_api_plugin >(); + auto account_by_key = _plugin.app()->find_plugin< account_by_key::account_by_key_api_plugin >(); if( account_by_key != nullptr ) { my->set_account_by_key_api(account_by_key->api); } - auto account_history = appbase::app().find_plugin< account_history::account_history_api_plugin >(); + auto account_history = _plugin.app()->find_plugin< account_history::account_history_api_plugin >(); if( account_history != nullptr ) { my->set_account_history_api(account_history->api); } - auto network_broadcast = appbase::app().find_plugin< network_broadcast_api::network_broadcast_api_plugin >(); + auto network_broadcast = _plugin.app()->find_plugin< network_broadcast_api::network_broadcast_api_plugin >(); if( network_broadcast != nullptr ) { my->set_network_broadcast_api(network_broadcast->api); } - auto witness = appbase::app().find_plugin< witness::witness_api_plugin >(); + auto witness = _plugin.app()->find_plugin< witness::witness_api_plugin >(); if( witness != nullptr ) { my->set_witness_api(witness->api); } - auto custom = appbase::app().find_plugin< custom::custom_api_plugin>(); + auto custom = _plugin.app()->find_plugin< custom::custom_api_plugin>(); if( custom != nullptr ) { my->set_custom_api(custom->api); } - auto subscribe = appbase::app().find_plugin< subscribe::subscribe_api_plugin>(); + auto subscribe = _plugin.app()->find_plugin< subscribe::subscribe_api_plugin>(); if ( subscribe != nullptr) { my->set_subscribe_api(subscribe->api); } - auto multiparty_messaging = appbase::app().find_plugin< multiparty_messaging::multiparty_messaging_plugin>(); + auto multiparty_messaging = _plugin.app()->find_plugin< multiparty_messaging::multiparty_messaging_plugin>(); if ( multiparty_messaging != nullptr) { my->set_mpm_api(multiparty_messaging->api); } diff --git a/libraries/plugins/apis/alexandria_api/alexandria_api_impl.cpp b/libraries/plugins/apis/alexandria_api/alexandria_api_impl.cpp index a75cbc12..4c77d61f 100644 --- a/libraries/plugins/apis/alexandria_api/alexandria_api_impl.cpp +++ b/libraries/plugins/apis/alexandria_api/alexandria_api_impl.cpp @@ -1,5 +1,7 @@ #include +#include +#include #include #include #include @@ -1317,9 +1319,9 @@ DEFINE_API_IMPL(alexandria_api_impl, get_required_signatures) FC_ASSERT( approving_account_objects.size() == v_approving_account_names.size(), "", ("aco.size:", approving_account_objects.size())("acn",v_approving_account_names.size()) ); - flat_map approving_account_lut; + flat_map approving_account_lut; size_t i = 0; - for( const optional& approving_acct : approving_account_objects ) + for( const optional& approving_acct : approving_account_objects ) { if( !approving_acct.valid() ) { @@ -1338,7 +1340,7 @@ DEFINE_API_IMPL(alexandria_api_impl, get_required_signatures) const auto it = approving_account_lut.find( acct_name ); if( it == approving_account_lut.end() ) continue; - const alexandria_api::api_account_object& acct = it->second; + const api_account_object& acct = it->second; vector v_approving_keys = acct.active.get_keys(); for( const public_key_type& approving_key : v_approving_keys ) { @@ -1351,7 +1353,7 @@ DEFINE_API_IMPL(alexandria_api_impl, get_required_signatures) const auto it = approving_account_lut.find( acct_name ); if( it == approving_account_lut.end() ) continue; - const alexandria_api::api_account_object& acct = it->second; + const api_account_object& acct = it->second; vector v_approving_keys = acct.owner.get_keys(); for( const public_key_type& approving_key : v_approving_keys ) { @@ -1449,7 +1451,7 @@ DEFINE_API_IMPL(alexandria_api_impl, get_hardfork_property_object) { checkApiEnabled(_database_api); - alexandria_api::api_hardfork_property_object props = _database_api->get_hardfork_properties( {} ); + api_hardfork_property_object props = _database_api->get_hardfork_properties( {} ); get_hardfork_property_object_return result; result.hf_obj = std::move(props); diff --git a/libraries/plugins/apis/alexandria_api/alexandria_api_plugin.cpp b/libraries/plugins/apis/alexandria_api/alexandria_api_plugin.cpp index ea510524..569dcf46 100644 --- a/libraries/plugins/apis/alexandria_api/alexandria_api_plugin.cpp +++ b/libraries/plugins/apis/alexandria_api/alexandria_api_plugin.cpp @@ -12,7 +12,7 @@ void alexandria_api_plugin::set_program_options( void alexandria_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< alexandria_api >( ); + api = std::make_shared< alexandria_api >( *this ); } void alexandria_api_plugin::plugin_startup() { diff --git a/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api.hpp b/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api.hpp index b26984fb..8b553816 100644 --- a/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api.hpp +++ b/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api.hpp @@ -8,11 +8,12 @@ namespace sophiatx { namespace plugins { namespace alexandria_api { class alexandria_api_impl; +class alexandria_api_plugin; class alexandria_api { public: - alexandria_api(); + alexandria_api(alexandria_api_plugin& plugin); ~alexandria_api(); void init(); @@ -568,6 +569,7 @@ class alexandria_api private: std::unique_ptr< alexandria_api_impl > my; + alexandria_api_plugin& _plugin; }; } } } //sophiatx::plugins::alexandria_api \ No newline at end of file diff --git a/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api_impl.hpp b/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api_impl.hpp index 1f5b8ac4..75bc68f9 100644 --- a/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api_impl.hpp +++ b/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api_impl.hpp @@ -14,10 +14,12 @@ #include namespace sophiatx { namespace plugins { namespace alexandria_api { +class alexandria_api_plugin; + class alexandria_api_impl { public: - alexandria_api_impl(); + alexandria_api_impl(alexandria_api_plugin& plugin); ~alexandria_api_impl(); /** diff --git a/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api_plugin.hpp b/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api_plugin.hpp index 0d9ef3fb..d5d964bc 100644 --- a/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api_plugin.hpp +++ b/libraries/plugins/apis/alexandria_api/include/sophiatx/plugins/alexandria_api/alexandria_api_plugin.hpp @@ -23,9 +23,9 @@ class alexandria_api_plugin : public plugin< alexandria_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_ALEXANDRIA_API_PLUGIN_NAME; return name; } - virtual void set_program_options( + static void set_program_options( options_description& cli, - options_description& cfg ) override; + options_description& cfg ) ; void plugin_initialize( const variables_map& options ) override; void plugin_startup() override; void plugin_shutdown() override; diff --git a/libraries/plugins/apis/block_api/block_api.cpp b/libraries/plugins/apis/block_api/block_api.cpp index 662e16f7..e76b65c5 100644 --- a/libraries/plugins/apis/block_api/block_api.cpp +++ b/libraries/plugins/apis/block_api/block_api.cpp @@ -10,7 +10,7 @@ namespace sophiatx { namespace plugins { namespace block_api { class block_api_impl { public: - block_api_impl(); + block_api_impl(block_api_plugin& plugin); ~block_api_impl(); DECLARE_API_IMPL( @@ -27,16 +27,16 @@ class block_api_impl // // ////////////////////////////////////////////////////////////////////// -block_api::block_api() - : my( new block_api_impl() ) +block_api::block_api(block_api_plugin& plugin) + : my( new block_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_BLOCK_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_BLOCK_API_PLUGIN_NAME, plugin.app() ); } block_api::~block_api() {} -block_api_impl::block_api_impl() - : _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} +block_api_impl::block_api_impl(block_api_plugin& plugin) + : _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} block_api_impl::~block_api_impl() {} diff --git a/libraries/plugins/apis/block_api/block_api_plugin.cpp b/libraries/plugins/apis/block_api/block_api_plugin.cpp index 47552231..9abce2ab 100644 --- a/libraries/plugins/apis/block_api/block_api_plugin.cpp +++ b/libraries/plugins/apis/block_api/block_api_plugin.cpp @@ -12,7 +12,7 @@ void block_api_plugin::set_program_options( void block_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< block_api >(); + api = std::make_shared< block_api >(*this); } void block_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/apis/block_api/include/sophiatx/plugins/block_api/block_api.hpp b/libraries/plugins/apis/block_api/include/sophiatx/plugins/block_api/block_api.hpp index 9a45fa03..c05f34a6 100644 --- a/libraries/plugins/apis/block_api/include/sophiatx/plugins/block_api/block_api.hpp +++ b/libraries/plugins/apis/block_api/include/sophiatx/plugins/block_api/block_api.hpp @@ -9,11 +9,12 @@ namespace sophiatx { namespace plugins { namespace block_api { class block_api_impl; +class block_api_plugin; class block_api { public: - block_api(); + block_api(block_api_plugin& plugin); ~block_api(); DECLARE_API( diff --git a/libraries/plugins/apis/block_api/include/sophiatx/plugins/block_api/block_api_plugin.hpp b/libraries/plugins/apis/block_api/include/sophiatx/plugins/block_api/block_api_plugin.hpp index ecb815b0..8f488012 100644 --- a/libraries/plugins/apis/block_api/include/sophiatx/plugins/block_api/block_api_plugin.hpp +++ b/libraries/plugins/apis/block_api/include/sophiatx/plugins/block_api/block_api_plugin.hpp @@ -23,9 +23,9 @@ class block_api_plugin : public plugin< block_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_BLOCK_API_PLUGIN_NAME; return name; } - virtual void set_program_options( + static void set_program_options( options_description& cli, - options_description& cfg ) override; + options_description& cfg ); void plugin_initialize( const variables_map& options ) override; void plugin_startup() override; void plugin_shutdown() override; diff --git a/libraries/plugins/apis/chain_api/chain_api.cpp b/libraries/plugins/apis/chain_api/chain_api.cpp index 30f951a8..8821da2a 100644 --- a/libraries/plugins/apis/chain_api/chain_api.cpp +++ b/libraries/plugins/apis/chain_api/chain_api.cpp @@ -8,7 +8,7 @@ namespace detail { class chain_api_impl { public: - chain_api_impl() : _chain( appbase::app().get_plugin() ) {} + chain_api_impl(chain_api_plugin& plugin) : _chain( plugin.app()->get_plugin() ) {} DECLARE_API_IMPL( (push_block) @@ -74,9 +74,9 @@ DEFINE_API_IMPL( chain_api_impl, push_transaction ) } // detail -chain_api::chain_api(): my( new detail::chain_api_impl() ) +chain_api::chain_api(chain_api_plugin& plugin): my( new detail::chain_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_CHAIN_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_CHAIN_API_PLUGIN_NAME, plugin.app() ); } chain_api::~chain_api() {} diff --git a/libraries/plugins/apis/chain_api/chain_api_plugin.cpp b/libraries/plugins/apis/chain_api/chain_api_plugin.cpp index bf881f53..aac1b4ab 100644 --- a/libraries/plugins/apis/chain_api/chain_api_plugin.cpp +++ b/libraries/plugins/apis/chain_api/chain_api_plugin.cpp @@ -11,7 +11,7 @@ void chain_api_plugin::set_program_options( options_description& cli, options_de void chain_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< chain_api >(); + api = std::make_shared< chain_api >(*this); } void chain_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/apis/chain_api/include/sophiatx/plugins/chain_api/chain_api.hpp b/libraries/plugins/apis/chain_api/include/sophiatx/plugins/chain_api/chain_api.hpp index 2a4c5021..53e6c160 100644 --- a/libraries/plugins/apis/chain_api/include/sophiatx/plugins/chain_api/chain_api.hpp +++ b/libraries/plugins/apis/chain_api/include/sophiatx/plugins/chain_api/chain_api.hpp @@ -30,11 +30,12 @@ struct push_transaction_return optional error; }; +class chain_api_plugin; class chain_api { public: - chain_api(); + chain_api(chain_api_plugin& plugin); ~chain_api(); DECLARE_API( diff --git a/libraries/plugins/apis/chain_api/include/sophiatx/plugins/chain_api/chain_api_plugin.hpp b/libraries/plugins/apis/chain_api/include/sophiatx/plugins/chain_api/chain_api_plugin.hpp index f194926f..9500833c 100644 --- a/libraries/plugins/apis/chain_api/include/sophiatx/plugins/chain_api/chain_api_plugin.hpp +++ b/libraries/plugins/apis/chain_api/include/sophiatx/plugins/chain_api/chain_api_plugin.hpp @@ -25,7 +25,7 @@ class chain_api_plugin : public plugin< chain_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_CHAIN_API_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); void plugin_initialize( const variables_map& options ) override; void plugin_startup() override; diff --git a/libraries/plugins/apis/custom_api/custom_api.cpp b/libraries/plugins/apis/custom_api/custom_api.cpp index ee80dca8..13bc1680 100644 --- a/libraries/plugins/apis/custom_api/custom_api.cpp +++ b/libraries/plugins/apis/custom_api/custom_api.cpp @@ -9,7 +9,7 @@ namespace detail { class custom_api_impl { public: - custom_api_impl() : _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) { + custom_api_impl(custom_api_plugin& plugin) : _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) { } DECLARE_API_IMPL( @@ -177,9 +177,9 @@ DEFINE_API_IMPL( custom_api_impl, list_received_documents ) } // detail -custom_api::custom_api(): my( new detail::custom_api_impl() ) +custom_api::custom_api(custom_api_plugin& plugin): my( new detail::custom_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_CUSTOM_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_CUSTOM_API_PLUGIN_NAME, plugin.app() ); } custom_api::~custom_api() {} diff --git a/libraries/plugins/apis/custom_api/custom_api_plugin.cpp b/libraries/plugins/apis/custom_api/custom_api_plugin.cpp index d0919b13..a3a54757 100644 --- a/libraries/plugins/apis/custom_api/custom_api_plugin.cpp +++ b/libraries/plugins/apis/custom_api/custom_api_plugin.cpp @@ -11,7 +11,7 @@ void custom_api_plugin::set_program_options( options_description& cli, options_d void custom_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< custom_api >(); + api = std::make_shared< custom_api >(*this); } void custom_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/apis/custom_api/include/sophiatx/plugins/custom_api/custom_api.hpp b/libraries/plugins/apis/custom_api/include/sophiatx/plugins/custom_api/custom_api.hpp index 996d76b4..f38068c1 100644 --- a/libraries/plugins/apis/custom_api/include/sophiatx/plugins/custom_api/custom_api.hpp +++ b/libraries/plugins/apis/custom_api/include/sophiatx/plugins/custom_api/custom_api.hpp @@ -71,11 +71,12 @@ typedef std::map< uint64_t, received_object > list_received_documents_return; typedef received_object get_received_document_return; typedef map get_app_custom_messages_return; +class custom_api_plugin; class custom_api { public: - custom_api(); + custom_api(custom_api_plugin& plugin); ~custom_api(); DECLARE_API( diff --git a/libraries/plugins/apis/custom_api/include/sophiatx/plugins/custom_api/custom_api_plugin.hpp b/libraries/plugins/apis/custom_api/include/sophiatx/plugins/custom_api/custom_api_plugin.hpp index bace097b..40516a4c 100644 --- a/libraries/plugins/apis/custom_api/include/sophiatx/plugins/custom_api/custom_api_plugin.hpp +++ b/libraries/plugins/apis/custom_api/include/sophiatx/plugins/custom_api/custom_api_plugin.hpp @@ -23,7 +23,7 @@ class custom_api_plugin : public plugin< custom_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_CUSTOM_API_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; diff --git a/libraries/plugins/apis/database_api/database_api.cpp b/libraries/plugins/apis/database_api/database_api.cpp index 2423dc65..890cc95b 100644 --- a/libraries/plugins/apis/database_api/database_api.cpp +++ b/libraries/plugins/apis/database_api/database_api.cpp @@ -14,7 +14,7 @@ namespace sophiatx { namespace plugins { namespace database_api { class database_api_impl { public: - database_api_impl(); + database_api_impl(database_api_plugin& plugin); ~database_api_impl(); DECLARE_API_IMPL @@ -80,16 +80,16 @@ class database_api_impl // // ////////////////////////////////////////////////////////////////////// -database_api::database_api() - : my( new database_api_impl() ) +database_api::database_api(database_api_plugin& plugin) + : my( new database_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_DATABASE_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_DATABASE_API_PLUGIN_NAME, plugin.app() ); } database_api::~database_api() {} -database_api_impl::database_api_impl() - : _db( std::static_pointer_cast(appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db()) ) {} +database_api_impl::database_api_impl( database_api_plugin& plugin ) + : _db( std::static_pointer_cast( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db()) ) {} database_api_impl::~database_api_impl() {} diff --git a/libraries/plugins/apis/database_api/database_api_plugin.cpp b/libraries/plugins/apis/database_api/database_api_plugin.cpp index fe27f9dd..c3135eed 100644 --- a/libraries/plugins/apis/database_api/database_api_plugin.cpp +++ b/libraries/plugins/apis/database_api/database_api_plugin.cpp @@ -12,7 +12,7 @@ void database_api_plugin::set_program_options( void database_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< database_api >(); + api = std::make_shared< database_api >(*this); } void database_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/apis/database_api/include/sophiatx/plugins/database_api/database_api.hpp b/libraries/plugins/apis/database_api/include/sophiatx/plugins/database_api/database_api.hpp index 04043fee..c52fbdee 100644 --- a/libraries/plugins/apis/database_api/include/sophiatx/plugins/database_api/database_api.hpp +++ b/libraries/plugins/apis/database_api/include/sophiatx/plugins/database_api/database_api.hpp @@ -8,11 +8,12 @@ namespace sophiatx { namespace plugins { namespace database_api { class database_api_impl; +class database_api_plugin; class database_api { public: - database_api(); + database_api(database_api_plugin& plugin); ~database_api(); DECLARE_API( diff --git a/libraries/plugins/apis/database_api/include/sophiatx/plugins/database_api/database_api_plugin.hpp b/libraries/plugins/apis/database_api/include/sophiatx/plugins/database_api/database_api_plugin.hpp index 3b1e730f..16848dc7 100644 --- a/libraries/plugins/apis/database_api/include/sophiatx/plugins/database_api/database_api_plugin.hpp +++ b/libraries/plugins/apis/database_api/include/sophiatx/plugins/database_api/database_api_plugin.hpp @@ -23,9 +23,9 @@ class database_api_plugin : public plugin< database_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_DATABASE_API_PLUGIN_NAME; return name; } - virtual void set_program_options( + static void set_program_options( options_description& cli, - options_description& cfg ) override; + options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/libraries/plugins/apis/debug_node_api/debug_node_api.cpp b/libraries/plugins/apis/debug_node_api/debug_node_api.cpp index 9b3feda5..10b92a31 100644 --- a/libraries/plugins/apis/debug_node_api/debug_node_api.cpp +++ b/libraries/plugins/apis/debug_node_api/debug_node_api.cpp @@ -19,9 +19,9 @@ namespace detail { class debug_node_api_impl { public: - debug_node_api_impl() : - _db( std::static_pointer_cast(appbase::app().get_plugin< chain::chain_plugin >().db()) ), - _debug_node( appbase::app().get_plugin< debug_node_plugin >() ) {} + debug_node_api_impl(debug_node_api_plugin& plugin) : + _db( std::static_pointer_cast(plugin.app()->get_plugin< chain::chain_plugin >().db()) ), + _debug_node( plugin.app()->get_plugin< debug_node_plugin >() ) {} DECLARE_API_IMPL( (debug_push_blocks) @@ -152,9 +152,9 @@ DEFINE_API_IMPL( debug_node_api_impl, debug_get_json_schema ) } // detail -debug_node_api::debug_node_api(): my( new detail::debug_node_api_impl() ) +debug_node_api::debug_node_api(debug_node_api_plugin& plugin): my( new detail::debug_node_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_DEBUG_NODE_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_DEBUG_NODE_API_PLUGIN_NAME, plugin.app() ); } debug_node_api::~debug_node_api() {} diff --git a/libraries/plugins/apis/debug_node_api/debug_node_api_plugin.cpp b/libraries/plugins/apis/debug_node_api/debug_node_api_plugin.cpp index 53ddbf8b..4a737fcd 100644 --- a/libraries/plugins/apis/debug_node_api/debug_node_api_plugin.cpp +++ b/libraries/plugins/apis/debug_node_api/debug_node_api_plugin.cpp @@ -11,7 +11,7 @@ void debug_node_api_plugin::set_program_options( options_description& cli, optio void debug_node_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< debug_node_api >(); + api = std::make_shared< debug_node_api >(*this); } void debug_node_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/apis/debug_node_api/include/sophiatx/plugins/debug_node_api/debug_node_api.hpp b/libraries/plugins/apis/debug_node_api/include/sophiatx/plugins/debug_node_api/debug_node_api.hpp index b4306895..83314cf7 100644 --- a/libraries/plugins/apis/debug_node_api/include/sophiatx/plugins/debug_node_api/debug_node_api.hpp +++ b/libraries/plugins/apis/debug_node_api/include/sophiatx/plugins/debug_node_api/debug_node_api.hpp @@ -70,11 +70,11 @@ struct debug_get_json_schema_return std::string schema; }; - +class debug_node_api_plugin; class debug_node_api { public: - debug_node_api(); + debug_node_api( debug_node_api_plugin& plugin); ~debug_node_api(); DECLARE_API( diff --git a/libraries/plugins/apis/debug_node_api/include/sophiatx/plugins/debug_node_api/debug_node_api_plugin.hpp b/libraries/plugins/apis/debug_node_api/include/sophiatx/plugins/debug_node_api/debug_node_api_plugin.hpp index 8188825d..298acd0d 100644 --- a/libraries/plugins/apis/debug_node_api/include/sophiatx/plugins/debug_node_api/debug_node_api_plugin.hpp +++ b/libraries/plugins/apis/debug_node_api/include/sophiatx/plugins/debug_node_api/debug_node_api_plugin.hpp @@ -24,7 +24,7 @@ class debug_node_api_plugin : public appbase::plugin< debug_node_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_DEBUG_NODE_API_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; diff --git a/libraries/plugins/apis/network_broadcast_api/include/sophiatx/plugins/network_broadcast_api/network_broadcast_api.hpp b/libraries/plugins/apis/network_broadcast_api/include/sophiatx/plugins/network_broadcast_api/network_broadcast_api.hpp index 74c387dd..07769cde 100644 --- a/libraries/plugins/apis/network_broadcast_api/include/sophiatx/plugins/network_broadcast_api/network_broadcast_api.hpp +++ b/libraries/plugins/apis/network_broadcast_api/include/sophiatx/plugins/network_broadcast_api/network_broadcast_api.hpp @@ -54,11 +54,13 @@ typedef void_type broadcast_block_return; typedef std::function< void( const broadcast_transaction_synchronous_return& ) > confirmation_callback; namespace detail{ class network_broadcast_api_impl; } +class network_broadcast_api_plugin; + class network_broadcast_api { public: - network_broadcast_api(); + network_broadcast_api(network_broadcast_api_plugin& plugin); ~network_broadcast_api(); DECLARE_API( diff --git a/libraries/plugins/apis/network_broadcast_api/include/sophiatx/plugins/network_broadcast_api/network_broadcast_api_plugin.hpp b/libraries/plugins/apis/network_broadcast_api/include/sophiatx/plugins/network_broadcast_api/network_broadcast_api_plugin.hpp index 00f5830e..5bf822ac 100644 --- a/libraries/plugins/apis/network_broadcast_api/include/sophiatx/plugins/network_broadcast_api/network_broadcast_api_plugin.hpp +++ b/libraries/plugins/apis/network_broadcast_api/include/sophiatx/plugins/network_broadcast_api/network_broadcast_api_plugin.hpp @@ -25,7 +25,7 @@ class network_broadcast_api_plugin : public appbase::plugin< network_broadcast_a static const std::string& name() { static std::string name = SOPHIATX_NETWORK_BROADCAST_API_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/libraries/plugins/apis/network_broadcast_api/network_broadcast_api.cpp b/libraries/plugins/apis/network_broadcast_api/network_broadcast_api.cpp index 8dcca6cb..ce0dd2f7 100644 --- a/libraries/plugins/apis/network_broadcast_api/network_broadcast_api.cpp +++ b/libraries/plugins/apis/network_broadcast_api/network_broadcast_api.cpp @@ -13,9 +13,9 @@ namespace detail class network_broadcast_api_impl { public: - network_broadcast_api_impl() : - _p2p( appbase::app().get_plugin< sophiatx::plugins::p2p::p2p_plugin >() ), - _chain( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >() ) + network_broadcast_api_impl(network_broadcast_api_plugin& plugin) : + _p2p( plugin.app()->get_plugin< sophiatx::plugins::p2p::p2p_plugin >() ), + _chain( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >() ) { _on_applied_block_connection = _chain.db()->applied_block.connect( 0, [&]( const signed_block& b ){ on_applied_block( b ); } ); @@ -175,9 +175,9 @@ namespace detail } // detail -network_broadcast_api::network_broadcast_api() : my( new detail::network_broadcast_api_impl() ) +network_broadcast_api::network_broadcast_api(network_broadcast_api_plugin& plugin) : my( new detail::network_broadcast_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_NETWORK_BROADCAST_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_NETWORK_BROADCAST_API_PLUGIN_NAME, plugin.app() ); } network_broadcast_api::~network_broadcast_api() {} diff --git a/libraries/plugins/apis/network_broadcast_api/network_broadcast_api_plugin.cpp b/libraries/plugins/apis/network_broadcast_api/network_broadcast_api_plugin.cpp index 79cf916e..e56b2381 100644 --- a/libraries/plugins/apis/network_broadcast_api/network_broadcast_api_plugin.cpp +++ b/libraries/plugins/apis/network_broadcast_api/network_broadcast_api_plugin.cpp @@ -10,7 +10,7 @@ void network_broadcast_api_plugin::set_program_options( options_description& cli void network_broadcast_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< network_broadcast_api >(); + api = std::make_shared< network_broadcast_api >(*this); } void network_broadcast_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/apis/subscribe_api/include/sophiatx/plugins/subscribe_api/subscribe_api.hpp b/libraries/plugins/apis/subscribe_api/include/sophiatx/plugins/subscribe_api/subscribe_api.hpp index f9b9fd97..21edb452 100644 --- a/libraries/plugins/apis/subscribe_api/include/sophiatx/plugins/subscribe_api/subscribe_api.hpp +++ b/libraries/plugins/apis/subscribe_api/include/sophiatx/plugins/subscribe_api/subscribe_api.hpp @@ -26,11 +26,12 @@ struct custom_object_subscription_args{ typedef uint64_t custom_object_subscription_return; +class subscribe_api_plugin; class subscribe_api { public: - subscribe_api(); + subscribe_api(subscribe_api_plugin& plugin); ~subscribe_api(); void api_startup(); diff --git a/libraries/plugins/apis/subscribe_api/include/sophiatx/plugins/subscribe_api/subscribe_api_plugin.hpp b/libraries/plugins/apis/subscribe_api/include/sophiatx/plugins/subscribe_api/subscribe_api_plugin.hpp index 8dc938b2..151e2ee5 100644 --- a/libraries/plugins/apis/subscribe_api/include/sophiatx/plugins/subscribe_api/subscribe_api_plugin.hpp +++ b/libraries/plugins/apis/subscribe_api/include/sophiatx/plugins/subscribe_api/subscribe_api_plugin.hpp @@ -22,7 +22,7 @@ class subscribe_api_plugin : public plugin< subscribe_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_SUBSCRIBE_API_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; diff --git a/libraries/plugins/apis/subscribe_api/subscribe_api.cpp b/libraries/plugins/apis/subscribe_api/subscribe_api.cpp index c9550840..fee86ef3 100644 --- a/libraries/plugins/apis/subscribe_api/subscribe_api.cpp +++ b/libraries/plugins/apis/subscribe_api/subscribe_api.cpp @@ -16,8 +16,12 @@ struct custom_content_callback; class subscribe_api_impl { public: - subscribe_api_impl() : _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) { + subscribe_api_impl(subscribe_api_plugin&plugin) : _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) { post_apply_connection = _db->post_apply_operation.connect( 0, [&]( const chain::operation_notification& note ){ on_operation(note); } ); + json_api = plugin.app()->find_plugin< plugins::json_rpc::json_rpc_plugin >(); + auto custom = plugin.app()->find_plugin< custom::custom_api_plugin>(); + if( custom != nullptr ) + custom_api = custom->api; } DECLARE_API_IMPL( @@ -118,17 +122,14 @@ DEFINE_API_IMPL( subscribe_api_impl, custom_object_subscription) } // namespace detail -subscribe_api::subscribe_api(): my( new detail::subscribe_api_impl() ) +subscribe_api::subscribe_api(subscribe_api_plugin& plugin): my( new detail::subscribe_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_SUBSCRIBE_API_PLUGIN_NAME ); - appbase::app().get_plugin< sophiatx::plugins::json_rpc::json_rpc_plugin >().add_api_subscribe_method("subscribe_api", "custom_object_subscription" ); + JSON_RPC_REGISTER_API( SOPHIATX_SUBSCRIBE_API_PLUGIN_NAME, plugin.app() ); + plugin.app()->get_plugin< sophiatx::plugins::json_rpc::json_rpc_plugin >().add_api_subscribe_method("subscribe_api", "custom_object_subscription" ); } void subscribe_api::api_startup(){ - my->json_api = appbase::app().find_plugin< plugins::json_rpc::json_rpc_plugin >(); - auto custom = appbase::app().find_plugin< custom::custom_api_plugin>(); - if( custom != nullptr ) - my->custom_api = custom->api; + } subscribe_api::~subscribe_api() {} diff --git a/libraries/plugins/apis/subscribe_api/subscribe_api_plugin.cpp b/libraries/plugins/apis/subscribe_api/subscribe_api_plugin.cpp index 63ca5e20..7e630908 100644 --- a/libraries/plugins/apis/subscribe_api/subscribe_api_plugin.cpp +++ b/libraries/plugins/apis/subscribe_api/subscribe_api_plugin.cpp @@ -11,7 +11,7 @@ void subscribe_api_plugin::set_program_options( options_description& cli, option void subscribe_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< subscribe_api >(); + api = std::make_shared< subscribe_api >(*this); } void subscribe_api_plugin::plugin_startup() diff --git a/libraries/plugins/apis/test_api/include/sophiatx/plugins/test_api/test_api_plugin.hpp b/libraries/plugins/apis/test_api/include/sophiatx/plugins/test_api/test_api_plugin.hpp index 9315d7c0..5bc447e6 100644 --- a/libraries/plugins/apis/test_api/include/sophiatx/plugins/test_api/test_api_plugin.hpp +++ b/libraries/plugins/apis/test_api/include/sophiatx/plugins/test_api/test_api_plugin.hpp @@ -27,7 +27,7 @@ class test_api_plugin : public appbase::plugin< test_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_TEST_API_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description&, options_description& ) override {} + static void set_program_options( options_description&, options_description& ) {} virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; diff --git a/libraries/plugins/apis/test_api/test_api_plugin.cpp b/libraries/plugins/apis/test_api/test_api_plugin.cpp index 51b66839..561caaf9 100644 --- a/libraries/plugins/apis/test_api/test_api_plugin.cpp +++ b/libraries/plugins/apis/test_api/test_api_plugin.cpp @@ -9,7 +9,7 @@ test_api_plugin::~test_api_plugin() {} void test_api_plugin::plugin_initialize( const variables_map& options ) { - JSON_RPC_REGISTER_API( name() ); + JSON_RPC_REGISTER_API( name(), app() ); } void test_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/apis/witness_api/include/sophiatx/plugins/witness_api/witness_api.hpp b/libraries/plugins/apis/witness_api/include/sophiatx/plugins/witness_api/witness_api.hpp index 0256a47e..05fa9ac7 100644 --- a/libraries/plugins/apis/witness_api/include/sophiatx/plugins/witness_api/witness_api.hpp +++ b/libraries/plugins/apis/witness_api/include/sophiatx/plugins/witness_api/witness_api.hpp @@ -30,11 +30,12 @@ struct get_account_bandwidth_return typedef json_rpc::void_type get_reserve_ratio_args; typedef reserve_ratio_object get_reserve_ratio_return; +class witness_api_plugin; class witness_api { public: - witness_api(); + witness_api(witness_api_plugin& plugin); ~witness_api(); DECLARE_API( diff --git a/libraries/plugins/apis/witness_api/include/sophiatx/plugins/witness_api/witness_api_plugin.hpp b/libraries/plugins/apis/witness_api/include/sophiatx/plugins/witness_api/witness_api_plugin.hpp index 8449bcef..58d66b3c 100644 --- a/libraries/plugins/apis/witness_api/include/sophiatx/plugins/witness_api/witness_api_plugin.hpp +++ b/libraries/plugins/apis/witness_api/include/sophiatx/plugins/witness_api/witness_api_plugin.hpp @@ -24,7 +24,7 @@ class witness_api_plugin : public appbase::plugin< witness_api_plugin > static const std::string& name() { static std::string name = SOPHIATX_WITNESS_API_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; diff --git a/libraries/plugins/apis/witness_api/witness_api.cpp b/libraries/plugins/apis/witness_api/witness_api.cpp index 6dd20c15..d70e8500 100644 --- a/libraries/plugins/apis/witness_api/witness_api.cpp +++ b/libraries/plugins/apis/witness_api/witness_api.cpp @@ -8,7 +8,7 @@ namespace detail { class witness_api_impl { public: - witness_api_impl() : _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} + witness_api_impl(witness_api_plugin & plugin) : _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} DECLARE_API_IMPL( (get_account_bandwidth) @@ -36,9 +36,9 @@ DEFINE_API_IMPL( witness_api_impl, get_reserve_ratio ) } // detail -witness_api::witness_api(): my( new detail::witness_api_impl() ) +witness_api::witness_api(witness_api_plugin & plugin): my( new detail::witness_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_WITNESS_API_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_WITNESS_API_PLUGIN_NAME, plugin.app() ); } witness_api::~witness_api() {} diff --git a/libraries/plugins/apis/witness_api/witness_api_plugin.cpp b/libraries/plugins/apis/witness_api/witness_api_plugin.cpp index e25b69df..9e05576d 100644 --- a/libraries/plugins/apis/witness_api/witness_api_plugin.cpp +++ b/libraries/plugins/apis/witness_api/witness_api_plugin.cpp @@ -11,7 +11,7 @@ void witness_api_plugin::set_program_options( options_description& cli, options_ void witness_api_plugin::plugin_initialize( const variables_map& options ) { - api = std::make_shared< witness_api >(); + api = std::make_shared< witness_api >(*this); } void witness_api_plugin::plugin_startup() {} diff --git a/libraries/plugins/block_log_info/include/sophiatx/plugins/block_log_info/block_log_info_plugin.hpp b/libraries/plugins/block_log_info/include/sophiatx/plugins/block_log_info/block_log_info_plugin.hpp index 08f47945..b8810ae7 100644 --- a/libraries/plugins/block_log_info/include/sophiatx/plugins/block_log_info/block_log_info_plugin.hpp +++ b/libraries/plugins/block_log_info/include/sophiatx/plugins/block_log_info/block_log_info_plugin.hpp @@ -21,7 +21,7 @@ class block_log_info_plugin : public appbase::plugin< block_log_info_plugin > static const std::string& name() { static std::string name = SOPHIATX_BLOCK_LOG_INFO_PLUGIN_NAME; return name; } - virtual void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/libraries/plugins/chain/chain_plugin_full.cpp b/libraries/plugins/chain/chain_plugin_full.cpp index 79a401db..eb38ef28 100644 --- a/libraries/plugins/chain/chain_plugin_full.cpp +++ b/libraries/plugins/chain/chain_plugin_full.cpp @@ -342,7 +342,7 @@ void chain_plugin_full::plugin_startup() // correct directories, TODO can be removed after next HF2 if( ! genesis.is_private_net && bfs::exists( app_factory().data_dir / "blockchain" ) ){ bfs::create_directories ( shared_memory_dir ); - bfs::rename( app_factory().data_dir / "blockchain", my->shared_memory_dir ); + bfs::rename( app_factory().data_dir / "blockchain", shared_memory_dir ); } ilog("Starting node with chain id ${i}", ("i", chain_id)); diff --git a/libraries/plugins/chain/chain_plugin_lite.cpp b/libraries/plugins/chain/chain_plugin_lite.cpp index 03adeebe..d5588428 100644 --- a/libraries/plugins/chain/chain_plugin_lite.cpp +++ b/libraries/plugins/chain/chain_plugin_lite.cpp @@ -43,7 +43,7 @@ void chain_plugin_lite::plugin_initialize(const variables_map &options) { if( options.count("shared-file-dir")) { auto sfd = options.at("shared-file-dir").as(); if( sfd.is_relative()) - shared_memory_dir = app().data_dir() / sfd; + shared_memory_dir = app()->data_dir() / sfd; else shared_memory_dir = sfd; } @@ -66,7 +66,7 @@ void chain_plugin_lite::plugin_startup() { ilog("Starting chain with shared_file_size: ${n} bytes", ("n", shared_memory_size)); if( shared_memory_dir.generic_string().empty()) - shared_memory_dir = app().data_dir() / "blockchain"; + shared_memory_dir = app()->data_dir() / "blockchain"; if( resync ) { wlog("resync requested: deleting block log and shared memory"); diff --git a/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin.hpp b/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin.hpp index 2d6e9af1..2cda2816 100644 --- a/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin.hpp +++ b/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin.hpp @@ -28,7 +28,7 @@ class chain_plugin : public plugin< chain_plugin > static const std::string& name() { static std::string name = SOPHIATX_CHAIN_PLUGIN_NAME; return name; } - void set_program_options(options_description &cli, options_description &cfg) override { + static void set_program_options(options_description &cli, options_description &cfg) { FC_ASSERT(false, "Not implemented for base class of chain_plugin"); } diff --git a/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin_full.hpp b/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin_full.hpp index 8487e200..763d3b21 100644 --- a/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin_full.hpp +++ b/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin_full.hpp @@ -47,7 +47,7 @@ class chain_plugin_full : public chain_plugin chain_plugin_full(); virtual ~chain_plugin_full(); - void set_program_options( options_description& cli, options_description& cfg ) override; + static void set_program_options( options_description& cli, options_description& cfg ); void plugin_initialize( const variables_map& options ) override; void plugin_startup() override; void plugin_shutdown() override; diff --git a/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin_lite.hpp b/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin_lite.hpp index 84953d23..8a32b443 100644 --- a/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin_lite.hpp +++ b/libraries/plugins/chain/include/sophiatx/plugins/chain/chain_plugin_lite.hpp @@ -17,7 +17,7 @@ class chain_plugin_lite : public chain_plugin { virtual ~chain_plugin_lite(); - void set_program_options(options_description &cli, options_description &cfg) override; + static void set_program_options(options_description &cli, options_description &cfg); void plugin_initialize(const variables_map &options) override; diff --git a/libraries/plugins/debug_node/debug_node_plugin.cpp b/libraries/plugins/debug_node/debug_node_plugin.cpp index 5b9f965d..bb0934e6 100644 --- a/libraries/plugins/debug_node/debug_node_plugin.cpp +++ b/libraries/plugins/debug_node/debug_node_plugin.cpp @@ -29,7 +29,6 @@ class debug_node_plugin_impl boost::signals2::connection applied_block_connection; }; -<<<<<<< HEAD debug_node_plugin_impl::debug_node_plugin_impl(debug_node_plugin& _plugin) : _db( std::static_pointer_cast(_plugin.app()->get_plugin< chain::chain_plugin >().db()) ) {} debug_node_plugin_impl::~debug_node_plugin_impl() {} @@ -52,7 +51,7 @@ void debug_node_plugin::set_program_options( void debug_node_plugin::plugin_initialize( const variables_map& options ) { - my = std::make_shared< detail::debug_node_plugin_impl >(); + my = std::make_shared< detail::debug_node_plugin_impl >(*this); if( options.count( "debug-node-edit-script" ) > 0 ) { diff --git a/libraries/plugins/debug_node/include/sophiatx/plugins/debug_node/debug_node_plugin.hpp b/libraries/plugins/debug_node/include/sophiatx/plugins/debug_node/debug_node_plugin.hpp index 02a2c114..a092c0ea 100644 --- a/libraries/plugins/debug_node/include/sophiatx/plugins/debug_node/debug_node_plugin.hpp +++ b/libraries/plugins/debug_node/include/sophiatx/plugins/debug_node/debug_node_plugin.hpp @@ -45,9 +45,9 @@ class debug_node_plugin : public plugin< debug_node_plugin > static const std::string& name() { static std::string name = SOPHIATX_DEBUG_NODE_PLUGIN_NAME; return name; } - virtual void set_program_options( + static void set_program_options( options_description& cli, - options_description& cfg ) override; + options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp b/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp index 5fb31ba8..ad75c28f 100644 --- a/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp +++ b/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp @@ -123,7 +123,7 @@ namespace detail { class register_api_method_visitor { public: - register_api_method_visitor( const std::string& api_name, const std::shared_ptr& app ) + register_api_method_visitor( const std::string& api_name, std::shared_ptr app ) : _api_name( api_name ), _json_rpc_plugin( app->get_plugin< sophiatx::plugins::json_rpc::json_rpc_plugin >() ) {} diff --git a/libraries/plugins/multiparty_messaging/include/sophiatx/plugins/multiparty_messaging/multiparty_messaging_plugin.hpp b/libraries/plugins/multiparty_messaging/include/sophiatx/plugins/multiparty_messaging/multiparty_messaging_plugin.hpp index 0db436e7..eda7def8 100644 --- a/libraries/plugins/multiparty_messaging/include/sophiatx/plugins/multiparty_messaging/multiparty_messaging_plugin.hpp +++ b/libraries/plugins/multiparty_messaging/include/sophiatx/plugins/multiparty_messaging/multiparty_messaging_plugin.hpp @@ -39,9 +39,9 @@ class multiparty_messaging_plugin : public plugin< multiparty_messaging_plugin > static const std::string& name() { static std::string name = SOPHIATX_MPM_PLUGIN_NAME; return name; } - virtual void set_program_options( + static void set_program_options( options_description& cli, - options_description& cfg ) override; + options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/libraries/plugins/multiparty_messaging/multiparty_messaging_api.cpp b/libraries/plugins/multiparty_messaging/multiparty_messaging_api.cpp index 5369627e..ccf042a9 100644 --- a/libraries/plugins/multiparty_messaging/multiparty_messaging_api.cpp +++ b/libraries/plugins/multiparty_messaging/multiparty_messaging_api.cpp @@ -36,7 +36,10 @@ void find_new_members ( shared_vector current_members, vector class multiparty_messaging_api_impl { public: - multiparty_messaging_api_impl(multiparty_messaging_plugin& plugin) : _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), _plugin(plugin) {} + multiparty_messaging_api_impl(multiparty_messaging_plugin& plugin) : + _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ), _plugin(plugin), + _json_api(plugin.app()->find_plugin< plugins::json_rpc::json_rpc_plugin >()) {} + get_group_return get_group(const get_group_args& args) const; get_group_name_return get_group_name(const get_group_name_args& args) const; list_my_groups_return list_my_groups(const list_my_groups_args& args) const; @@ -50,7 +53,7 @@ class multiparty_messaging_api_impl std::shared_ptr _db; multiparty_messaging_plugin& _plugin; - plugins::json_rpc::json_rpc_plugin* json_api; + plugins::json_rpc::json_rpc_plugin* _json_api; private: vector generate_random_key() const; @@ -111,7 +114,7 @@ vector multiparty_messaging_api_impl::generate_random_key() const alexandria_api::api_account_object multiparty_messaging_api_impl::get_account(const account_name_type& account) const { alexandria_api::get_account_args args {account}; - auto result = json_api->call_api_method("alexandria_api", "get_account", fc::variant(args)); + auto result = _json_api->call_api_method("alexandria_api", "get_account", fc::variant(args)); FC_ASSERT(result.valid(), "Account does not exist!"); alexandria_api::get_account_return acc_return; fc::from_variant( *result, acc_return ); @@ -384,13 +387,13 @@ send_group_message_return multiparty_messaging_api_impl::send_group_message(con multiparty_messaging_api::multiparty_messaging_api(multiparty_messaging_plugin& plugin): my( new detail::multiparty_messaging_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_MPM_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_MPM_PLUGIN_NAME, plugin.app() ); + } multiparty_messaging_api::~multiparty_messaging_api() {} void multiparty_messaging_api::api_startup() { - my->json_api = appbase::app().find_plugin< plugins::json_rpc::json_rpc_plugin >(); } DEFINE_READ_APIS( multiparty_messaging_api, (get_group) (get_group_name) (list_my_groups) (list_messages) diff --git a/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp b/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp index e1292edd..47fdc58f 100644 --- a/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp +++ b/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp @@ -248,7 +248,7 @@ void multiparty_messaging_plugin::plugin_initialize( const boost::program_option try { ilog( "Initializing multiparty_messaging_plugin_impl plugin" ); - auto& db = appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); + auto& db = app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); db->set_custom_operation_interpreter(app_id, dynamic_pointer_cast(_my)); add_plugin_index< group_index >(db); diff --git a/libraries/plugins/p2p/include/sophiatx/plugins/p2p/p2p_plugin.hpp b/libraries/plugins/p2p/include/sophiatx/plugins/p2p/p2p_plugin.hpp index a14af04e..36a8a168 100644 --- a/libraries/plugins/p2p/include/sophiatx/plugins/p2p/p2p_plugin.hpp +++ b/libraries/plugins/p2p/include/sophiatx/plugins/p2p/p2p_plugin.hpp @@ -18,8 +18,8 @@ class p2p_plugin : public appbase::plugin { p2p_plugin(); virtual ~p2p_plugin(); - void set_program_options(bpo::options_description &, - bpo::options_description &config_file_options) override; + static void set_program_options(bpo::options_description &, + bpo::options_description &config_file_options); static const std::string& name() { static std::string name = SOPHIATX_P2P_PLUGIN_NAME; return name; } diff --git a/libraries/plugins/p2p/p2p_plugin.cpp b/libraries/plugins/p2p/p2p_plugin.cpp index f4621a40..a6036e5e 100644 --- a/libraries/plugins/p2p/p2p_plugin.cpp +++ b/libraries/plugins/p2p/p2p_plugin.cpp @@ -20,8 +20,6 @@ using std::vector; namespace sophiatx { namespace plugins { namespace p2p { -using appbase::app; - using graphene::net::item_hash_t; using graphene::net::item_id; using graphene::net::message; @@ -558,7 +556,7 @@ void p2p_plugin::plugin_startup() my->p2p_thread.async( [this] { my->node.reset(new graphene::net::node(my->user_agent)); - my->node->load_configuration(app().data_dir() / "p2p"); + my->node->load_configuration(app() -> data_dir() / "p2p"); my->node->set_node_delegate( &(*my) ); if( my->endpoint ) diff --git a/libraries/plugins/template_plugin/include/sophiatx/plugins/template/template_api.hpp b/libraries/plugins/template_plugin/include/sophiatx/plugins/template/template_api.hpp index 9cb52bb5..23e86168 100644 --- a/libraries/plugins/template_plugin/include/sophiatx/plugins/template/template_api.hpp +++ b/libraries/plugins/template_plugin/include/sophiatx/plugins/template/template_api.hpp @@ -26,10 +26,12 @@ struct example_call_return uint64_t mul; }; +class template_plugin; + class template_api { public: - template_api(); + template_api(template_plugin& plugin); ~template_api(); DECLARE_API( (example_call) ) diff --git a/libraries/plugins/template_plugin/include/sophiatx/plugins/template/template_plugin.hpp b/libraries/plugins/template_plugin/include/sophiatx/plugins/template/template_plugin.hpp index 7dd23cb0..c35eecb7 100644 --- a/libraries/plugins/template_plugin/include/sophiatx/plugins/template/template_plugin.hpp +++ b/libraries/plugins/template_plugin/include/sophiatx/plugins/template/template_plugin.hpp @@ -31,9 +31,9 @@ class template_plugin : public plugin< template_plugin > static const std::string& name() { static std::string name = SOPHIATX_TEMPLATE_PLUGIN_NAME; return name; } - virtual void set_program_options( + static void set_program_options( options_description& cli, - options_description& cfg ) override; + options_description& cfg ); virtual void plugin_initialize( const variables_map& options ) override; virtual void plugin_startup() override; virtual void plugin_shutdown() override; diff --git a/libraries/plugins/template_plugin/template_api.cpp b/libraries/plugins/template_plugin/template_api.cpp index ec1d2704..6a9df95c 100644 --- a/libraries/plugins/template_plugin/template_api.cpp +++ b/libraries/plugins/template_plugin/template_api.cpp @@ -9,7 +9,7 @@ namespace detail { class template_api_impl { public: - template_api_impl() : _db( appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} + template_api_impl(template_plugin& plugin) : _db( plugin.app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db() ) {} example_call_return example_call( const example_call_args& args )const; @@ -28,9 +28,9 @@ example_call_return template_api_impl::example_call( const example_call_args& ar } // detail -template_api::template_api(): my( new detail::template_api_impl() ) +template_api::template_api(template_plugin& plugin): my( new detail::template_api_impl(plugin) ) { - JSON_RPC_REGISTER_API( SOPHIATX_TEMPLATE_PLUGIN_NAME ); + JSON_RPC_REGISTER_API( SOPHIATX_TEMPLATE_PLUGIN_NAME, plugin.app() ); } template_api::~template_api() {} diff --git a/libraries/plugins/template_plugin/template_plugin.cpp b/libraries/plugins/template_plugin/template_plugin.cpp index bda12d44..438f2088 100644 --- a/libraries/plugins/template_plugin/template_plugin.cpp +++ b/libraries/plugins/template_plugin/template_plugin.cpp @@ -93,11 +93,11 @@ void template_plugin::set_program_options( options_description& cli, options_des void template_plugin::plugin_initialize( const boost::program_options::variables_map& options ) { my = std::make_unique< detail::template_plugin_impl >( *this ); - api = std::make_shared< template_api >(); + api = std::make_shared< template_api >(*this); try { ilog( "Initializing template_plugin_impl plugin" ); - auto& db = appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); + auto& db = app()->get_plugin< sophiatx::plugins::chain::chain_plugin >().db(); my->pre_apply_connection = db->pre_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->pre_operation( o ); } ); my->post_apply_connection = db->post_apply_operation.connect( 0, [&]( const operation_notification& o ){ my->post_operation( o ); } ); diff --git a/libraries/plugins/webserver/include/sophiatx/plugins/webserver/webserver_plugin.hpp b/libraries/plugins/webserver/include/sophiatx/plugins/webserver/webserver_plugin.hpp index 7230f8ef..9281faec 100644 --- a/libraries/plugins/webserver/include/sophiatx/plugins/webserver/webserver_plugin.hpp +++ b/libraries/plugins/webserver/include/sophiatx/plugins/webserver/webserver_plugin.hpp @@ -37,7 +37,7 @@ class webserver_plugin : public appbase::plugin< webserver_plugin > static const std::string& name() { static std::string name = SOPHIATX_WEBSERVER_PLUGIN_NAME; return name; } - virtual void set_program_options(options_description&, options_description& cfg) override; + static void set_program_options(options_description&, options_description& cfg); protected: virtual void plugin_initialize(const variables_map& options) override; diff --git a/libraries/plugins/witness/include/sophiatx/plugins/witness/witness_plugin.hpp b/libraries/plugins/witness/include/sophiatx/plugins/witness/witness_plugin.hpp index 9c17fb1a..88894948 100644 --- a/libraries/plugins/witness/include/sophiatx/plugins/witness/witness_plugin.hpp +++ b/libraries/plugins/witness/include/sophiatx/plugins/witness/witness_plugin.hpp @@ -41,10 +41,10 @@ class witness_plugin : public appbase::plugin< witness_plugin > static const std::string& name() { static std::string name = SOPHIATX_WITNESS_PLUGIN_NAME; return name; } - virtual void set_program_options( + static void set_program_options( boost::program_options::options_description &command_line_options, boost::program_options::options_description &config_file_options - ) override; + ); virtual void plugin_initialize(const boost::program_options::variables_map& options) override; virtual void plugin_startup() override; diff --git a/libraries/plugins/witness/witness_plugin.cpp b/libraries/plugins/witness/witness_plugin.cpp index dc95d570..2d6157f9 100644 --- a/libraries/plugins/witness/witness_plugin.cpp +++ b/libraries/plugins/witness/witness_plugin.cpp @@ -257,10 +257,9 @@ namespace detail { block_production_condition::block_production_condition_enum witness_plugin_impl::block_production_loop() { - auto db = std::static_pointer_cast(appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); - if( fc::time_point::now() < fc::time_point(db->get_genesis_time()) ) + if( fc::time_point::now() < fc::time_point(_db->get_genesis_time()) ) { - wlog( "waiting until genesis time to produce block: ${t}, now is: ${n}", ("t", db->get_genesis_time())("n", fc::time_point::now()) ); + wlog( "waiting until genesis time to produce block: ${t}, now is: ${n}", ("t", _db->get_genesis_time())("n", fc::time_point::now()) ); schedule_production_loop(); return block_production_condition::wait_for_genesis; } @@ -327,24 +326,23 @@ namespace detail { block_production_condition::block_production_condition_enum witness_plugin_impl::maybe_produce_block(fc::mutable_variant_object& capture) { - auto db = std::static_pointer_cast(appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); fc::time_point now_fine = fc::time_point::now(); fc::time_point_sec now = now_fine + fc::microseconds( 500000 ); // If the next block production opportunity is in the present or future, we're synced. if( !_production_enabled ) { - if( db->get_slot_time(1) >= now ) + if( _db->get_slot_time(1) >= now ) _production_enabled = true; else return block_production_condition::not_synced; } // is anyone scheduled to produce now or one second in the future? - uint32_t slot = db->get_slot_at_time( now ); + uint32_t slot = _db->get_slot_at_time( now ); if( slot == 0 ) { - capture("next_time", db->get_slot_time(1)); + capture("next_time", _db->get_slot_time(1)); return block_production_condition::not_time_yet; } @@ -356,9 +354,9 @@ namespace detail { // which would result in allowing a later block to have a timestamp // less than or equal to the previous block // - assert( now > db->head_block_time() ); + assert( now > _db->head_block_time() ); - chain::account_name_type scheduled_witness = db->get_scheduled_witness( slot ); + chain::account_name_type scheduled_witness = _db->get_scheduled_witness( slot ); // we must control the witness scheduled to produce the next block. if( _witnesses.find( scheduled_witness ) == _witnesses.end() ) { @@ -366,8 +364,8 @@ namespace detail { return block_production_condition::not_my_turn; } - fc::time_point_sec scheduled_time = db->get_slot_time( slot ); - chain::public_key_type scheduled_key = db->get< chain::witness_object, chain::by_name >(scheduled_witness).signing_key; + fc::time_point_sec scheduled_time = _db->get_slot_time( slot ); + chain::public_key_type scheduled_key = _db->get< chain::witness_object, chain::by_name >(scheduled_witness).signing_key; auto private_key_itr = _private_keys.find( scheduled_key ); if( private_key_itr == _private_keys.end() ) @@ -377,7 +375,7 @@ namespace detail { return block_production_condition::no_private_key; } - uint32_t prate = db->witness_participation_rate(); + uint32_t prate = _db->witness_participation_rate(); if( prate < _required_witness_participation ) { capture("pct", uint32_t(100*uint64_t(prate) / SOPHIATX_1_PERCENT)); diff --git a/programs/sophiatx_light/main.cpp b/programs/sophiatx_light/main.cpp index b5838c33..e7e5c626 100644 --- a/programs/sophiatx_light/main.cpp +++ b/programs/sophiatx_light/main.cpp @@ -59,27 +59,24 @@ int main( int argc, char** argv ) options.add_options() ("backtrace", bpo::value< string >()->default_value( "yes" ), "Whether to print backtrace on SIGSEGV" ); - appbase::app().add_program_options( bpo::options_description(), options ); + appbase::app_factory().add_program_options( options ); - appbase::app().register_plugin(); + appbase::app_factory().register_plugin_factory(); sophiatx::plugins::register_plugins(); - appbase::app().set_version_string( version_string() ); + appbase::app_factory().set_version_string( version_string() ); - bool initialized = appbase::app().initialize< - sophiatx::plugins::chain::chain_plugin_lite, - sophiatx::plugins::json_rpc::json_rpc_plugin, - sophiatx::plugins::webserver::webserver_plugin >( argc, argv ); + auto initialized = appbase::app_factory().initialize( argc, argv, {"chain_plugin_lite", "json_rpc_plugin", "webserver_plugin" } ); info(); - if( !initialized ) + if( !initialized.size() ) return 0; - auto& args = appbase::app().get_args(); + auto& args = appbase::app_factory().global_args; try { - fc::optional< fc::logging_config > logging_config = sophiatx::utilities::load_logging_config( args, appbase::app().data_dir() ); + fc::optional< fc::logging_config > logging_config = sophiatx::utilities::load_logging_config( args, appbase::app_factory().data_dir ); if( logging_config ) fc::configure_logging( *logging_config ); } @@ -94,8 +91,8 @@ int main( int argc, char** argv ) ilog( "Backtrace on segfault is enabled." ); } - appbase::app().startup(); - appbase::app().exec(); + appbase::app_factory().startup(); + appbase::app_factory().exec(); std::cout << "exited cleanly\n"; return 0; diff --git a/programs/sophiatxd/main.cpp b/programs/sophiatxd/main.cpp index 51b5815c..ec5ffa99 100644 --- a/programs/sophiatxd/main.cpp +++ b/programs/sophiatxd/main.cpp @@ -26,8 +26,6 @@ #include #include -#include -#include "../../libraries/config/include/sophiatx/config/config.hpp" namespace bpo = boost::program_options; using sophiatx::protocol::version; @@ -77,19 +75,15 @@ int main( int argc, char** argv ) appbase::app_factory().add_program_options( options ); - appbase::app().register_plugin(); + appbase::app_factory().register_plugin_factory(); sophiatx::plugins::register_plugins(); appbase::app_factory().set_version_string( version_string() ); - bool initialized = appbase::app().initialize< - sophiatx::plugins::chain::chain_plugin_full, - sophiatx::plugins::p2p::p2p_plugin, - sophiatx::plugins::webserver::webserver_plugin > - ( argc, argv ); + auto initialized = appbase::app_factory().initialize( argc, argv, {"chain_plugin_full", "p2p_plugin", "webserver_plugin"} ); info(); - if( !initialized ) + if( !initialized.size() ) return 0; auto& args = appbase::app_factory().global_args; @@ -111,8 +105,8 @@ int main( int argc, char** argv ) ilog( "Backtrace on segfault is enabled." ); } - appbase::app().startup(); - appbase::app().exec(); + appbase::app_factory().startup(); + appbase::app_factory().exec(); std::cout << "exited cleanly\n"; return 0; diff --git a/tests/db_fixture/database_fixture.cpp b/tests/db_fixture/database_fixture.cpp index a3bfe87d..9422b6c7 100644 --- a/tests/db_fixture/database_fixture.cpp +++ b/tests/db_fixture/database_fixture.cpp @@ -49,20 +49,22 @@ clean_database_fixture::clean_database_fixture() std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl; } - appbase::app().register_plugin(); - appbase::app().register_plugin< sophiatx::plugins::account_history::account_history_plugin >(); - db_plugin = &appbase::app().register_plugin< sophiatx::plugins::debug_node::debug_node_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::witness::witness_plugin >(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().initialize(argc, argv, {"chain", "account_history", "debug_node", "witness"}, false); + auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + auto app = w_app.lock(); + auto _db_plugin = app->find_plugin() ; + db_plugin = _db_plugin; db_plugin->logging = false; - appbase::app().initialize< - sophiatx::plugins::chain::chain_plugin_full, - sophiatx::plugins::account_history::account_history_plugin, - sophiatx::plugins::debug_node::debug_node_plugin, - sophiatx::plugins::witness::witness_plugin - >( argc, argv ); - - db = std::static_pointer_cast(appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); + app->initialize(appconfig, {"chain", "account_history", "debug_node", "witness"}); + + db = std::static_pointer_cast(app->get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); BOOST_REQUIRE( db ); init_account_pub_key = init_account_priv_key.get_public_key(); @@ -191,20 +193,20 @@ private_database_fixture::private_database_fixture() std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl; } - appbase::app().register_plugin(); - appbase::app().register_plugin< sophiatx::plugins::account_history::account_history_plugin >(); - db_plugin = &appbase::app().register_plugin< sophiatx::plugins::debug_node::debug_node_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::witness::witness_plugin >(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + auto app = w_app.lock(); + db_plugin = app->find_plugin() ; db_plugin->logging = false; - appbase::app().initialize< - sophiatx::plugins::chain::chain_plugin_full, - sophiatx::plugins::account_history::account_history_plugin, - sophiatx::plugins::debug_node::debug_node_plugin, - sophiatx::plugins::witness::witness_plugin - >( argc, argv ); - - db = std::static_pointer_cast(appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); + app->initialize(appconfig, {"chain", "account_history", "debug", "witness"}); + + db = std::static_pointer_cast(app->get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); BOOST_REQUIRE( db ); init_account_pub_key = init_account_priv_key.get_public_key(); @@ -279,16 +281,18 @@ live_database_fixture::live_database_fixture() _chain_dir = fc::current_path() / "test_blockchain"; FC_ASSERT( fc::exists( _chain_dir ), "Requires blockchain to test on in ./test_blockchain" ); - appbase::app().register_plugin(); - appbase::app().register_plugin< sophiatx::plugins::account_history::account_history_plugin >(); - db_plugin = &appbase::app().register_plugin< sophiatx::plugins::debug_node::debug_node_plugin >(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); - appbase::app().initialize< - sophiatx::plugins::chain::chain_plugin_full, - sophiatx::plugins::account_history::account_history_plugin, sophiatx::plugins::debug_node::debug_node_plugin - >( argc, argv ); + auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + auto app = w_app.lock(); + db_plugin = app->find_plugin() ; + db_plugin->logging = false; + app->initialize(appconfig, {"chain", "account_history_", "debug_node"}); - db = std::static_pointer_cast(appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); + db = std::static_pointer_cast(app->get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); BOOST_REQUIRE( db ); { @@ -694,33 +698,28 @@ json_rpc_database_fixture::json_rpc_database_fixture() std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl; } - appbase::app().register_plugin(); - appbase::app().register_plugin< sophiatx::plugins::account_history::account_history_plugin >(); - db_plugin = &appbase::app().register_plugin< sophiatx::plugins::debug_node::debug_node_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::witness::witness_plugin >(); - rpc_plugin = &appbase::app().register_plugin< sophiatx::plugins::json_rpc::json_rpc_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::block_api::block_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::database_api::database_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::witness::witness_api_plugin >(); - appbase::app().register_plugin< sophiatx::plugins::alexandria_api::alexandria_api_plugin >(); - + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + + w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + auto app = w_app.lock(); + + db_plugin = app->find_plugin() ; db_plugin->logging = false; - appbase::app().initialize< - sophiatx::plugins::chain::chain_plugin_full, - sophiatx::plugins::account_history::account_history_plugin, - sophiatx::plugins::debug_node::debug_node_plugin, - sophiatx::plugins::witness::witness_plugin, - sophiatx::plugins::json_rpc::json_rpc_plugin, - sophiatx::plugins::block_api::block_api_plugin, - sophiatx::plugins::database_api::database_api_plugin, - sophiatx::plugins::witness::witness_api_plugin, - sophiatx::plugins::alexandria_api::alexandria_api_plugin - >( argc, argv ); - - - appbase::app().get_plugin< sophiatx::plugins::alexandria_api::alexandria_api_plugin >().plugin_startup(); - - db = std::static_pointer_cast(appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); + rpc_plugin = app->find_plugin() ; + app->initialize(appconfig, {"chain", "account_history", "debug_node", "witness","json_rpc", "block_api", "database_api", "witness_api", "alexandria_api"}); + + app->get_plugin< sophiatx::plugins::alexandria_api::alexandria_api_plugin >().plugin_startup(); + + db = std::static_pointer_cast(app->get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); BOOST_REQUIRE( db ); init_account_pub_key = init_account_priv_key.get_public_key(); diff --git a/tests/db_fixture/database_fixture.hpp b/tests/db_fixture/database_fixture.hpp index 6565cdf0..4a53fa64 100644 --- a/tests/db_fixture/database_fixture.hpp +++ b/tests/db_fixture/database_fixture.hpp @@ -193,12 +193,13 @@ struct database_fixture { uint32_t default_skip = 0 | database_interface::skip_undo_history_check | database_interface::skip_authority_check; fc::ecc::canonical_signature_type default_sig_canon = fc::ecc::fc_canonical; - plugins::debug_node::debug_node_plugin* db_plugin; + sophiatx::plugins::debug_node::debug_node_plugin* db_plugin; + std::weak_ptr w_app; optional data_dir; database_fixture() {} - virtual ~database_fixture() { appbase::reset(); } + virtual ~database_fixture() { auto app = w_app.lock(); app.reset(); } static fc::ecc::private_key generate_private_key( string seed = "init_key" ); static asset_symbol_type name_to_asset_symbol( const std::string& name, uint8_t decimal_places ); diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index 84a0dba1..a291dad4 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -747,18 +747,19 @@ BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) if( arg == "--show-test-names" ) std::cout << "running test " << boost::unit_test::framework::current_test_case().p_name << std::endl; } - appbase::app().register_plugin(); - appbase::app().register_plugin< sophiatx::plugins::account_history::account_history_plugin >(); - db_plugin = &appbase::app().register_plugin< sophiatx::plugins::debug_node::debug_node_plugin >(); - init_account_pub_key = init_account_priv_key.get_public_key(); - - appbase::app().initialize< - sophiatx::plugins::chain::chain_plugin_full, - sophiatx::plugins::account_history::account_history_plugin, - sophiatx::plugins::debug_node::debug_node_plugin - >( argc, argv ); - - db = std::static_pointer_cast(appbase::app().get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); + + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().initialize(argc, argv, {"chain", "account_history", "debug_node", "witness"}, false); + auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + auto app = w_app.lock(); + auto _db_plugin = app->find_plugin() ; + db_plugin = _db_plugin; + app->initialize(appconfig, {"chain", "account_history", "debug_node"}); + + db = std::static_pointer_cast(app->get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); BOOST_REQUIRE( db ); From 60b82caaf79378a0746b05717ff2d31f82ade62f Mon Sep 17 00:00:00 2001 From: ejossev Date: Wed, 30 Jan 2019 18:23:30 +0100 Subject: [PATCH 05/17] test fix --- tests/db_fixture/database_fixture.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/db_fixture/database_fixture.cpp b/tests/db_fixture/database_fixture.cpp index 9422b6c7..13588495 100644 --- a/tests/db_fixture/database_fixture.cpp +++ b/tests/db_fixture/database_fixture.cpp @@ -274,8 +274,8 @@ live_database_fixture::live_database_fixture() { try { - int argc = boost::unit_test::framework::master_test_suite().argc; - char** argv = boost::unit_test::framework::master_test_suite().argv; + //int argc = boost::unit_test::framework::master_test_suite().argc; + //char** argv = boost::unit_test::framework::master_test_suite().argv; ilog( "Loading saved chain" ); _chain_dir = fc::current_path() / "test_blockchain"; @@ -709,6 +709,8 @@ json_rpc_database_fixture::json_rpc_database_fixture() appbase::app_factory().register_plugin_factory(); appbase::app_factory().register_plugin_factory(); + auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); auto app = w_app.lock(); From e8bdec80987a9a04412508433ca746339e708cd0 Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 31 Jan 2019 11:02:20 +0100 Subject: [PATCH 06/17] test fixes --- tests/db_fixture/database_fixture.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/db_fixture/database_fixture.cpp b/tests/db_fixture/database_fixture.cpp index 13588495..3cae79d0 100644 --- a/tests/db_fixture/database_fixture.cpp +++ b/tests/db_fixture/database_fixture.cpp @@ -196,15 +196,16 @@ private_database_fixture::private_database_fixture() appbase::app_factory().register_plugin_factory(); appbase::app_factory().register_plugin_factory(); appbase::app_factory().register_plugin_factory(); - appbase::app_factory().register_plugin_factory(); appbase::app_factory().register_plugin_factory(); - + appbase::app_factory().register_plugin_factory(); + appbase::app_factory().initialize(argc, argv, {"chain", "account_history", "debug_node", "witness"}, false); auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); auto app = w_app.lock(); - db_plugin = app->find_plugin() ; + auto _db_plugin = app->find_plugin() ; + db_plugin = _db_plugin; db_plugin->logging = false; - app->initialize(appconfig, {"chain", "account_history", "debug", "witness"}); + app->initialize(appconfig, {"chain", "account_history", "debug_node", "witness"}); db = std::static_pointer_cast(app->get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); BOOST_REQUIRE( db ); From 4dacf1a8c2f44d67281ad5f3da2a51e7bc64324d Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 31 Jan 2019 11:09:30 +0100 Subject: [PATCH 07/17] fixing merge issues --- libraries/SQLiteCpp/CMakeLists.txt | 60 ++++++++---------------------- libraries/chain/database.cpp | 1 - 2 files changed, 16 insertions(+), 45 deletions(-) diff --git a/libraries/SQLiteCpp/CMakeLists.txt b/libraries/SQLiteCpp/CMakeLists.txt index c2694d01..96fdc289 100644 --- a/libraries/SQLiteCpp/CMakeLists.txt +++ b/libraries/SQLiteCpp/CMakeLists.txt @@ -18,7 +18,6 @@ endif (WIN32) # then Compiler/IDE differences: if (MSVC) - set(CPPLINT_ARG_OUTPUT "--output=vs7") set(CPPCHECK_ARG_TEMPLATE "--template=vs") # disable Visual Studio warnings for fopen() used in the example add_definitions(-D_CRT_SECURE_NO_WARNINGS) @@ -35,7 +34,6 @@ if (MSVC) message(WARNING " MSVC < 2015 detected: Visual Studio prior to 2015 is not fully supported. BLOB storage seems to be corrupted.") endif (MSVC_TOOLSET_VERSION LESS 140) else (MSVC) - set(CPPLINT_ARG_OUTPUT "--output=eclipse") set(CPPCHECK_ARG_TEMPLATE "--template=gcc") # Useful compile flags and extra warnings add_compile_options(-fstack-protector -Wall -Wextra -Wpedantic -Wno-long-long -Wswitch-enum -Wshadow -Winline) @@ -54,7 +52,6 @@ else (MSVC) endif (CMAKE_COMPILER_IS_GNUCXX) endif (MSVC) # and then common variables -set(CPPLINT_ARG_VERBOSE "--verbose=3") set(CPPLINT_ARG_LINELENGTH "--linelength=120") # Print CXX compiler information @@ -100,6 +97,16 @@ if (SQLITE_USE_LEGACY_STRUCT) add_definitions(-DSQLITE_USE_LEGACY_STRUCT) endif (SQLITE_USE_LEGACY_STRUCT) +# Flag if static or shared sqlite library should be searched for +if(SOPHIA_STATIC_BUILD) + SET(CMAKE_FIND_LIBRARY_SUFFIXES ".a") +endif(SOPHIA_STATIC_BUILD) + +# Fing sqlite library +find_package (SQLite3 3.25.3 REQUIRED) +if (SQLite3_FOUND) + message (STATUS "Found SQLite version: ${SQLite3_VERSION}") +endif (SQLite3_FOUND) ## Build the C++ Wrapper ## @@ -165,23 +172,12 @@ set(SQLITECPP_DOC ) source_group(doc FILES ${SQLITECPP_DOC}) -# list of script files of the library -set(SQLITECPP_SCRIPT - .travis.yml - appveyor.yml - build.bat - build.sh - cpplint.py - Doxyfile - FindSQLiteCpp.cmake -) -source_group(scripts FILES ${SQLITECPP_SCRIPT}) - # All includes are relative to the "include" directory include_directories("${PROJECT_SOURCE_DIR}/include") +include_directories("${SQLite3_INCLUDE_DIRS}") # add sources of the wrapper as a "SQLiteCpp" static library -add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC} ${SQLITECPP_SCRIPT}) +add_library(SQLiteCpp ${SQLITECPP_SRC} ${SQLITECPP_INC} ${SQLITECPP_DOC}) # make the sqlite3 library part of the interface of the SQLiteCpp wrapper itself (the client app does not need to link to sqlite3) # PR https://github.com/SRombauts/SQLiteCpp/pull/111 "linked SQLiteCpp to sqlite3" commented out since it breacks install step from PR #118 #target_link_libraries(SQLiteCpp PUBLIC sqlite3) @@ -191,8 +187,7 @@ if (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Cla set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-fPIC") endif (UNIX AND (CMAKE_COMPILER_IS_GNUCXX OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")) - -target_link_libraries(SQLiteCpp PUBLIC sqlite3 fc) +target_link_libraries(SQLiteCpp PUBLIC ${SQLite3_LIBRARIES} fc) target_include_directories(SQLiteCpp PUBLIC $ $) @@ -219,31 +214,8 @@ target_include_directories(SQLiteCpp PUBLIC # set_target_properties(SQLiteCpp PROPERTIES COMPILE_FLAGS "-DSQLITECPP_HAS_MEM_STRUCT") #endif() -option(SQLITECPP_INTERNAL_SQLITE "Add the internal SQLite3 source to the project." ON) -if (SQLITECPP_INTERNAL_SQLITE) - # build the SQLite3 C library (for ease of use/compatibility) versus Linux sqlite3-dev package - add_subdirectory(sqlite3) - include_directories("${PROJECT_SOURCE_DIR}/sqlite3") - target_include_directories(sqlite3 PUBLIC "${PROJECT_SOURCE_DIR}/sqlite3") -endif (SQLITECPP_INTERNAL_SQLITE) - - # Optional additional targets: -option(SQLITECPP_RUN_CPPLINT "Run cpplint.py tool for Google C++ StyleGuide." ON) -if (SQLITECPP_RUN_CPPLINT) - find_package(PythonInterp) - if (PYTHONINTERP_FOUND) - # add a cpplint target to the "all" target - add_custom_target(SQLiteCpp_cpplint - ALL - COMMAND ${PYTHON_EXECUTABLE} ${PROJECT_SOURCE_DIR}/cpplint.py ${CPPLINT_ARG_OUTPUT} ${CPPLINT_ARG_VERBOSE} ${CPPLINT_ARG_LINELENGTH} ${SQLITECPP_SRC} ${SQLITECPP_INC} - ) - endif (PYTHONINTERP_FOUND) -else (SQLITECPP_RUN_CPPLINT) - message(STATUS "SQLITECPP_RUN_CPPLINT OFF") -endif (SQLITECPP_RUN_CPPLINT) - option(SQLITECPP_RUN_CPPCHECK "Run cppcheck C++ static analysis tool." ON) if (SQLITECPP_RUN_CPPCHECK) find_program(CPPCHECK_EXECUTABLE NAMES cppcheck) @@ -281,7 +253,7 @@ option(SQLITECPP_BUILD_EXAMPLES "Build examples." ON) if (SQLITECPP_BUILD_EXAMPLES) # add the basic example executable add_executable(SQLiteCpp_example1 ${SQLITECPP_EXAMPLES}) - target_link_libraries(SQLiteCpp_example1 SQLiteCpp sqlite3) + target_link_libraries(SQLiteCpp_example1 SQLiteCpp ${SQLite3_LIBRARIES}) # Link target with pthread and dl for linux if (UNIX) target_link_libraries(SQLiteCpp_example1 pthread) @@ -294,7 +266,7 @@ if (SQLITECPP_BUILD_EXAMPLES) add_executable(SQLiteCpp_example_fc_variant ${SQLITECPP_FC_VARIANT_EXAMPLES}) - target_link_libraries(SQLiteCpp_example_fc_variant SQLiteCpp sqlite3 fc) + target_link_libraries(SQLiteCpp_example_fc_variant SQLiteCpp ${SQLite3_LIBRARIES} fc) # Link target with pthread and dl for linux if (UNIX) target_link_libraries(SQLiteCpp_example_fc_variant pthread) @@ -337,7 +309,7 @@ if (SQLITECPP_BUILD_TESTS) # add the unit test executable add_executable(SQLiteCpp_tests ${SQLITECPP_TESTS}) - target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp sqlite3) + target_link_libraries(SQLiteCpp_tests gtest_main SQLiteCpp ${SQLite3_LIBRARIES}) # Link target with dl for linux if (UNIX AND NOT APPLE) target_link_libraries(SQLiteCpp_tests dl) diff --git a/libraries/chain/database.cpp b/libraries/chain/database.cpp index b6540f58..2e765ec0 100644 --- a/libraries/chain/database.cpp +++ b/libraries/chain/database.cpp @@ -1,5 +1,4 @@ #include -#include #include #include From 62c6ecf9504ab5192dba788be775487f4b9716fa Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 31 Jan 2019 11:35:42 +0100 Subject: [PATCH 08/17] remove definition of plugin methods to separate file to solve gcc compilation issues --- CMakeDoxyfile.in | 276 -------- CMakeDoxygenDefaults.cmake | 664 ------------------- libraries/appbase/CMakeLists.txt | 1 + libraries/appbase/include/appbase/plugin.hpp | 40 +- libraries/appbase/plugin.cpp | 53 ++ 5 files changed, 60 insertions(+), 974 deletions(-) delete mode 100644 CMakeDoxyfile.in delete mode 100644 CMakeDoxygenDefaults.cmake create mode 100644 libraries/appbase/plugin.cpp diff --git a/CMakeDoxyfile.in b/CMakeDoxyfile.in deleted file mode 100644 index 688769fa..00000000 --- a/CMakeDoxyfile.in +++ /dev/null @@ -1,276 +0,0 @@ -# -# DO NOT EDIT! THIS FILE WAS GENERATED BY CMAKE! -# - -DOXYFILE_ENCODING = @DOXYGEN_DOXYFILE_ENCODING@ -PROJECT_NAME = @DOXYGEN_PROJECT_NAME@ -PROJECT_NUMBER = @DOXYGEN_PROJECT_NUMBER@ -PROJECT_BRIEF = @DOXYGEN_PROJECT_BRIEF@ -PROJECT_LOGO = @DOXYGEN_PROJECT_LOGO@ -OUTPUT_DIRECTORY = @DOXYGEN_OUTPUT_DIRECTORY@ -CREATE_SUBDIRS = @DOXYGEN_CREATE_SUBDIRS@ -ALLOW_UNICODE_NAMES = @DOXYGEN_ALLOW_UNICODE_NAMES@ -OUTPUT_LANGUAGE = @DOXYGEN_OUTPUT_LANGUAGE@ -OUTPUT_TEXT_DIRECTION = @DOXYGEN_OUTPUT_TEXT_DIRECTION@ -BRIEF_MEMBER_DESC = @DOXYGEN_BRIEF_MEMBER_DESC@ -REPEAT_BRIEF = @DOXYGEN_REPEAT_BRIEF@ -ABBREVIATE_BRIEF = @DOXYGEN_ABBREVIATE_BRIEF@ -ALWAYS_DETAILED_SEC = @DOXYGEN_ALWAYS_DETAILED_SEC@ -INLINE_INHERITED_MEMB = @DOXYGEN_INLINE_INHERITED_MEMB@ -FULL_PATH_NAMES = @DOXYGEN_FULL_PATH_NAMES@ -STRIP_FROM_PATH = @DOXYGEN_STRIP_FROM_PATH@ -STRIP_FROM_INC_PATH = @DOXYGEN_STRIP_FROM_INC_PATH@ -SHORT_NAMES = @DOXYGEN_SHORT_NAMES@ -JAVADOC_AUTOBRIEF = @DOXYGEN_JAVADOC_AUTOBRIEF@ -QT_AUTOBRIEF = @DOXYGEN_QT_AUTOBRIEF@ -MULTILINE_CPP_IS_BRIEF = @DOXYGEN_MULTILINE_CPP_IS_BRIEF@ -INHERIT_DOCS = @DOXYGEN_INHERIT_DOCS@ -SEPARATE_MEMBER_PAGES = @DOXYGEN_SEPARATE_MEMBER_PAGES@ -TAB_SIZE = @DOXYGEN_TAB_SIZE@ -ALIASES = @DOXYGEN_ALIASES@ -TCL_SUBST = @DOXYGEN_TCL_SUBST@ -OPTIMIZE_OUTPUT_FOR_C = @DOXYGEN_OPTIMIZE_OUTPUT_FOR_C@ -OPTIMIZE_OUTPUT_JAVA = @DOXYGEN_OPTIMIZE_OUTPUT_JAVA@ -OPTIMIZE_FOR_FORTRAN = @DOXYGEN_OPTIMIZE_FOR_FORTRAN@ -OPTIMIZE_OUTPUT_VHDL = @DOXYGEN_OPTIMIZE_OUTPUT_VHDL@ -OPTIMIZE_OUTPUT_SLICE = @DOXYGEN_OPTIMIZE_OUTPUT_SLICE@ -EXTENSION_MAPPING = @DOXYGEN_EXTENSION_MAPPING@ -MARKDOWN_SUPPORT = @DOXYGEN_MARKDOWN_SUPPORT@ -TOC_INCLUDE_HEADINGS = @DOXYGEN_TOC_INCLUDE_HEADINGS@ -AUTOLINK_SUPPORT = @DOXYGEN_AUTOLINK_SUPPORT@ -BUILTIN_STL_SUPPORT = @DOXYGEN_BUILTIN_STL_SUPPORT@ -CPP_CLI_SUPPORT = @DOXYGEN_CPP_CLI_SUPPORT@ -SIP_SUPPORT = @DOXYGEN_SIP_SUPPORT@ -IDL_PROPERTY_SUPPORT = @DOXYGEN_IDL_PROPERTY_SUPPORT@ -DISTRIBUTE_GROUP_DOC = @DOXYGEN_DISTRIBUTE_GROUP_DOC@ -GROUP_NESTED_COMPOUNDS = @DOXYGEN_GROUP_NESTED_COMPOUNDS@ -SUBGROUPING = @DOXYGEN_SUBGROUPING@ -INLINE_GROUPED_CLASSES = @DOXYGEN_INLINE_GROUPED_CLASSES@ -INLINE_SIMPLE_STRUCTS = @DOXYGEN_INLINE_SIMPLE_STRUCTS@ -TYPEDEF_HIDES_STRUCT = @DOXYGEN_TYPEDEF_HIDES_STRUCT@ -LOOKUP_CACHE_SIZE = @DOXYGEN_LOOKUP_CACHE_SIZE@ -EXTRACT_ALL = @DOXYGEN_EXTRACT_ALL@ -EXTRACT_PRIVATE = @DOXYGEN_EXTRACT_PRIVATE@ -EXTRACT_PACKAGE = @DOXYGEN_EXTRACT_PACKAGE@ -EXTRACT_STATIC = @DOXYGEN_EXTRACT_STATIC@ -EXTRACT_LOCAL_CLASSES = @DOXYGEN_EXTRACT_LOCAL_CLASSES@ -EXTRACT_LOCAL_METHODS = @DOXYGEN_EXTRACT_LOCAL_METHODS@ -EXTRACT_ANON_NSPACES = @DOXYGEN_EXTRACT_ANON_NSPACES@ -HIDE_UNDOC_MEMBERS = @DOXYGEN_HIDE_UNDOC_MEMBERS@ -HIDE_UNDOC_CLASSES = @DOXYGEN_HIDE_UNDOC_CLASSES@ -HIDE_FRIEND_COMPOUNDS = @DOXYGEN_HIDE_FRIEND_COMPOUNDS@ -HIDE_IN_BODY_DOCS = @DOXYGEN_HIDE_IN_BODY_DOCS@ -INTERNAL_DOCS = @DOXYGEN_INTERNAL_DOCS@ -CASE_SENSE_NAMES = @DOXYGEN_CASE_SENSE_NAMES@ -HIDE_SCOPE_NAMES = @DOXYGEN_HIDE_SCOPE_NAMES@ -HIDE_COMPOUND_REFERENCE= @DOXYGEN_HIDE_COMPOUND_REFERENCE@ -SHOW_INCLUDE_FILES = @DOXYGEN_SHOW_INCLUDE_FILES@ -SHOW_GROUPED_MEMB_INC = @DOXYGEN_SHOW_GROUPED_MEMB_INC@ -FORCE_LOCAL_INCLUDES = @DOXYGEN_FORCE_LOCAL_INCLUDES@ -INLINE_INFO = @DOXYGEN_INLINE_INFO@ -SORT_MEMBER_DOCS = @DOXYGEN_SORT_MEMBER_DOCS@ -SORT_BRIEF_DOCS = @DOXYGEN_SORT_BRIEF_DOCS@ -SORT_MEMBERS_CTORS_1ST = @DOXYGEN_SORT_MEMBERS_CTORS_1ST@ -SORT_GROUP_NAMES = @DOXYGEN_SORT_GROUP_NAMES@ -SORT_BY_SCOPE_NAME = @DOXYGEN_SORT_BY_SCOPE_NAME@ -STRICT_PROTO_MATCHING = @DOXYGEN_STRICT_PROTO_MATCHING@ -GENERATE_TODOLIST = @DOXYGEN_GENERATE_TODOLIST@ -GENERATE_TESTLIST = @DOXYGEN_GENERATE_TESTLIST@ -GENERATE_BUGLIST = @DOXYGEN_GENERATE_BUGLIST@ -GENERATE_DEPRECATEDLIST= @DOXYGEN_GENERATE_DEPRECATEDLIST@ -ENABLED_SECTIONS = @DOXYGEN_ENABLED_SECTIONS@ -MAX_INITIALIZER_LINES = @DOXYGEN_MAX_INITIALIZER_LINES@ -SHOW_USED_FILES = @DOXYGEN_SHOW_USED_FILES@ -SHOW_FILES = @DOXYGEN_SHOW_FILES@ -SHOW_NAMESPACES = @DOXYGEN_SHOW_NAMESPACES@ -FILE_VERSION_FILTER = @DOXYGEN_FILE_VERSION_FILTER@ -LAYOUT_FILE = @DOXYGEN_LAYOUT_FILE@ -CITE_BIB_FILES = @DOXYGEN_CITE_BIB_FILES@ -QUIET = @DOXYGEN_QUIET@ -WARNINGS = @DOXYGEN_WARNINGS@ -WARN_IF_UNDOCUMENTED = @DOXYGEN_WARN_IF_UNDOCUMENTED@ -WARN_IF_DOC_ERROR = @DOXYGEN_WARN_IF_DOC_ERROR@ -WARN_NO_PARAMDOC = @DOXYGEN_WARN_NO_PARAMDOC@ -WARN_AS_ERROR = @DOXYGEN_WARN_AS_ERROR@ -WARN_FORMAT = @DOXYGEN_WARN_FORMAT@ -WARN_LOGFILE = @DOXYGEN_WARN_LOGFILE@ -INPUT = @DOXYGEN_INPUT@ -INPUT_ENCODING = @DOXYGEN_INPUT_ENCODING@ -FILE_PATTERNS = @DOXYGEN_FILE_PATTERNS@ -RECURSIVE = @DOXYGEN_RECURSIVE@ -EXCLUDE = @DOXYGEN_EXCLUDE@ -EXCLUDE_SYMLINKS = @DOXYGEN_EXCLUDE_SYMLINKS@ -EXCLUDE_PATTERNS = @DOXYGEN_EXCLUDE_PATTERNS@ -EXCLUDE_SYMBOLS = @DOXYGEN_EXCLUDE_SYMBOLS@ -EXAMPLE_PATH = @DOXYGEN_EXAMPLE_PATH@ -EXAMPLE_PATTERNS = @DOXYGEN_EXAMPLE_PATTERNS@ -EXAMPLE_RECURSIVE = @DOXYGEN_EXAMPLE_RECURSIVE@ -IMAGE_PATH = @DOXYGEN_IMAGE_PATH@ -INPUT_FILTER = @DOXYGEN_INPUT_FILTER@ -FILTER_PATTERNS = @DOXYGEN_FILTER_PATTERNS@ -FILTER_SOURCE_FILES = @DOXYGEN_FILTER_SOURCE_FILES@ -FILTER_SOURCE_PATTERNS = @DOXYGEN_FILTER_SOURCE_PATTERNS@ -USE_MDFILE_AS_MAINPAGE = @DOXYGEN_USE_MDFILE_AS_MAINPAGE@ -SOURCE_BROWSER = @DOXYGEN_SOURCE_BROWSER@ -INLINE_SOURCES = @DOXYGEN_INLINE_SOURCES@ -STRIP_CODE_COMMENTS = @DOXYGEN_STRIP_CODE_COMMENTS@ -REFERENCED_BY_RELATION = @DOXYGEN_REFERENCED_BY_RELATION@ -REFERENCES_RELATION = @DOXYGEN_REFERENCES_RELATION@ -REFERENCES_LINK_SOURCE = @DOXYGEN_REFERENCES_LINK_SOURCE@ -SOURCE_TOOLTIPS = @DOXYGEN_SOURCE_TOOLTIPS@ -USE_HTAGS = @DOXYGEN_USE_HTAGS@ -VERBATIM_HEADERS = @DOXYGEN_VERBATIM_HEADERS@ -ALPHABETICAL_INDEX = @DOXYGEN_ALPHABETICAL_INDEX@ -COLS_IN_ALPHA_INDEX = @DOXYGEN_COLS_IN_ALPHA_INDEX@ -IGNORE_PREFIX = @DOXYGEN_IGNORE_PREFIX@ -GENERATE_HTML = @DOXYGEN_GENERATE_HTML@ -HTML_OUTPUT = @DOXYGEN_HTML_OUTPUT@ -HTML_FILE_EXTENSION = @DOXYGEN_HTML_FILE_EXTENSION@ -HTML_HEADER = @DOXYGEN_HTML_HEADER@ -HTML_FOOTER = @DOXYGEN_HTML_FOOTER@ -HTML_STYLESHEET = @DOXYGEN_HTML_STYLESHEET@ -HTML_EXTRA_STYLESHEET = @DOXYGEN_HTML_EXTRA_STYLESHEET@ -HTML_EXTRA_FILES = @DOXYGEN_HTML_EXTRA_FILES@ -HTML_COLORSTYLE_HUE = @DOXYGEN_HTML_COLORSTYLE_HUE@ -HTML_COLORSTYLE_SAT = @DOXYGEN_HTML_COLORSTYLE_SAT@ -HTML_COLORSTYLE_GAMMA = @DOXYGEN_HTML_COLORSTYLE_GAMMA@ -HTML_TIMESTAMP = @DOXYGEN_HTML_TIMESTAMP@ -HTML_DYNAMIC_MENUS = @DOXYGEN_HTML_DYNAMIC_MENUS@ -HTML_DYNAMIC_SECTIONS = @DOXYGEN_HTML_DYNAMIC_SECTIONS@ -HTML_INDEX_NUM_ENTRIES = @DOXYGEN_HTML_INDEX_NUM_ENTRIES@ -GENERATE_DOCSET = @DOXYGEN_GENERATE_DOCSET@ -DOCSET_FEEDNAME = @DOXYGEN_DOCSET_FEEDNAME@ -DOCSET_BUNDLE_ID = @DOXYGEN_DOCSET_BUNDLE_ID@ -DOCSET_PUBLISHER_ID = @DOXYGEN_DOCSET_PUBLISHER_ID@ -DOCSET_PUBLISHER_NAME = @DOXYGEN_DOCSET_PUBLISHER_NAME@ -GENERATE_HTMLHELP = @DOXYGEN_GENERATE_HTMLHELP@ -CHM_FILE = @DOXYGEN_CHM_FILE@ -HHC_LOCATION = @DOXYGEN_HHC_LOCATION@ -GENERATE_CHI = @DOXYGEN_GENERATE_CHI@ -CHM_INDEX_ENCODING = @DOXYGEN_CHM_INDEX_ENCODING@ -BINARY_TOC = @DOXYGEN_BINARY_TOC@ -TOC_EXPAND = @DOXYGEN_TOC_EXPAND@ -GENERATE_QHP = @DOXYGEN_GENERATE_QHP@ -QCH_FILE = @DOXYGEN_QCH_FILE@ -QHP_NAMESPACE = @DOXYGEN_QHP_NAMESPACE@ -QHP_VIRTUAL_FOLDER = @DOXYGEN_QHP_VIRTUAL_FOLDER@ -QHP_CUST_FILTER_NAME = @DOXYGEN_QHP_CUST_FILTER_NAME@ -QHP_CUST_FILTER_ATTRS = @DOXYGEN_QHP_CUST_FILTER_ATTRS@ -QHP_SECT_FILTER_ATTRS = @DOXYGEN_QHP_SECT_FILTER_ATTRS@ -QHG_LOCATION = @DOXYGEN_QHG_LOCATION@ -GENERATE_ECLIPSEHELP = @DOXYGEN_GENERATE_ECLIPSEHELP@ -ECLIPSE_DOC_ID = @DOXYGEN_ECLIPSE_DOC_ID@ -DISABLE_INDEX = @DOXYGEN_DISABLE_INDEX@ -GENERATE_TREEVIEW = @DOXYGEN_GENERATE_TREEVIEW@ -ENUM_VALUES_PER_LINE = @DOXYGEN_ENUM_VALUES_PER_LINE@ -TREEVIEW_WIDTH = @DOXYGEN_TREEVIEW_WIDTH@ -EXT_LINKS_IN_WINDOW = @DOXYGEN_EXT_LINKS_IN_WINDOW@ -FORMULA_FONTSIZE = @DOXYGEN_FORMULA_FONTSIZE@ -FORMULA_TRANSPARENT = @DOXYGEN_FORMULA_TRANSPARENT@ -USE_MATHJAX = @DOXYGEN_USE_MATHJAX@ -MATHJAX_FORMAT = @DOXYGEN_MATHJAX_FORMAT@ -MATHJAX_RELPATH = @DOXYGEN_MATHJAX_RELPATH@ -MATHJAX_EXTENSIONS = @DOXYGEN_MATHJAX_EXTENSIONS@ -MATHJAX_CODEFILE = @DOXYGEN_MATHJAX_CODEFILE@ -SEARCHENGINE = @DOXYGEN_SEARCHENGINE@ -SERVER_BASED_SEARCH = @DOXYGEN_SERVER_BASED_SEARCH@ -EXTERNAL_SEARCH = @DOXYGEN_EXTERNAL_SEARCH@ -SEARCHENGINE_URL = @DOXYGEN_SEARCHENGINE_URL@ -SEARCHDATA_FILE = @DOXYGEN_SEARCHDATA_FILE@ -EXTERNAL_SEARCH_ID = @DOXYGEN_EXTERNAL_SEARCH_ID@ -EXTRA_SEARCH_MAPPINGS = @DOXYGEN_EXTRA_SEARCH_MAPPINGS@ -GENERATE_LATEX = @DOXYGEN_GENERATE_LATEX@ -LATEX_OUTPUT = @DOXYGEN_LATEX_OUTPUT@ -LATEX_CMD_NAME = @DOXYGEN_LATEX_CMD_NAME@ -MAKEINDEX_CMD_NAME = @DOXYGEN_MAKEINDEX_CMD_NAME@ -LATEX_MAKEINDEX_CMD = @DOXYGEN_LATEX_MAKEINDEX_CMD@ -COMPACT_LATEX = @DOXYGEN_COMPACT_LATEX@ -PAPER_TYPE = @DOXYGEN_PAPER_TYPE@ -EXTRA_PACKAGES = @DOXYGEN_EXTRA_PACKAGES@ -LATEX_HEADER = @DOXYGEN_LATEX_HEADER@ -LATEX_FOOTER = @DOXYGEN_LATEX_FOOTER@ -LATEX_EXTRA_STYLESHEET = @DOXYGEN_LATEX_EXTRA_STYLESHEET@ -LATEX_EXTRA_FILES = @DOXYGEN_LATEX_EXTRA_FILES@ -PDF_HYPERLINKS = @DOXYGEN_PDF_HYPERLINKS@ -USE_PDFLATEX = @DOXYGEN_USE_PDFLATEX@ -LATEX_BATCHMODE = @DOXYGEN_LATEX_BATCHMODE@ -LATEX_HIDE_INDICES = @DOXYGEN_LATEX_HIDE_INDICES@ -LATEX_SOURCE_CODE = @DOXYGEN_LATEX_SOURCE_CODE@ -LATEX_BIB_STYLE = @DOXYGEN_LATEX_BIB_STYLE@ -LATEX_TIMESTAMP = @DOXYGEN_LATEX_TIMESTAMP@ -LATEX_EMOJI_DIRECTORY = @DOXYGEN_LATEX_EMOJI_DIRECTORY@ -GENERATE_RTF = @DOXYGEN_GENERATE_RTF@ -RTF_OUTPUT = @DOXYGEN_RTF_OUTPUT@ -COMPACT_RTF = @DOXYGEN_COMPACT_RTF@ -RTF_HYPERLINKS = @DOXYGEN_RTF_HYPERLINKS@ -RTF_STYLESHEET_FILE = @DOXYGEN_RTF_STYLESHEET_FILE@ -RTF_EXTENSIONS_FILE = @DOXYGEN_RTF_EXTENSIONS_FILE@ -RTF_SOURCE_CODE = @DOXYGEN_RTF_SOURCE_CODE@ -GENERATE_MAN = @DOXYGEN_GENERATE_MAN@ -MAN_OUTPUT = @DOXYGEN_MAN_OUTPUT@ -MAN_EXTENSION = @DOXYGEN_MAN_EXTENSION@ -MAN_SUBDIR = @DOXYGEN_MAN_SUBDIR@ -MAN_LINKS = @DOXYGEN_MAN_LINKS@ -GENERATE_XML = @DOXYGEN_GENERATE_XML@ -XML_OUTPUT = @DOXYGEN_XML_OUTPUT@ -XML_PROGRAMLISTING = @DOXYGEN_XML_PROGRAMLISTING@ -XML_NS_MEMB_FILE_SCOPE = @DOXYGEN_XML_NS_MEMB_FILE_SCOPE@ -GENERATE_DOCBOOK = @DOXYGEN_GENERATE_DOCBOOK@ -DOCBOOK_OUTPUT = @DOXYGEN_DOCBOOK_OUTPUT@ -DOCBOOK_PROGRAMLISTING = @DOXYGEN_DOCBOOK_PROGRAMLISTING@ -GENERATE_AUTOGEN_DEF = @DOXYGEN_GENERATE_AUTOGEN_DEF@ -GENERATE_PERLMOD = @DOXYGEN_GENERATE_PERLMOD@ -PERLMOD_LATEX = @DOXYGEN_PERLMOD_LATEX@ -PERLMOD_PRETTY = @DOXYGEN_PERLMOD_PRETTY@ -PERLMOD_MAKEVAR_PREFIX = @DOXYGEN_PERLMOD_MAKEVAR_PREFIX@ -ENABLE_PREPROCESSING = @DOXYGEN_ENABLE_PREPROCESSING@ -MACRO_EXPANSION = @DOXYGEN_MACRO_EXPANSION@ -EXPAND_ONLY_PREDEF = @DOXYGEN_EXPAND_ONLY_PREDEF@ -SEARCH_INCLUDES = @DOXYGEN_SEARCH_INCLUDES@ -INCLUDE_PATH = @DOXYGEN_INCLUDE_PATH@ -INCLUDE_FILE_PATTERNS = @DOXYGEN_INCLUDE_FILE_PATTERNS@ -PREDEFINED = @DOXYGEN_PREDEFINED@ -EXPAND_AS_DEFINED = @DOXYGEN_EXPAND_AS_DEFINED@ -SKIP_FUNCTION_MACROS = @DOXYGEN_SKIP_FUNCTION_MACROS@ -TAGFILES = @DOXYGEN_TAGFILES@ -GENERATE_TAGFILE = @DOXYGEN_GENERATE_TAGFILE@ -ALLEXTERNALS = @DOXYGEN_ALLEXTERNALS@ -EXTERNAL_GROUPS = @DOXYGEN_EXTERNAL_GROUPS@ -EXTERNAL_PAGES = @DOXYGEN_EXTERNAL_PAGES@ -PERL_PATH = @DOXYGEN_PERL_PATH@ -CLASS_DIAGRAMS = @DOXYGEN_CLASS_DIAGRAMS@ -MSCGEN_PATH = @DOXYGEN_MSCGEN_PATH@ -DIA_PATH = @DOXYGEN_DIA_PATH@ -HIDE_UNDOC_RELATIONS = @DOXYGEN_HIDE_UNDOC_RELATIONS@ -HAVE_DOT = @DOXYGEN_HAVE_DOT@ -DOT_NUM_THREADS = @DOXYGEN_DOT_NUM_THREADS@ -DOT_FONTNAME = @DOXYGEN_DOT_FONTNAME@ -DOT_FONTSIZE = @DOXYGEN_DOT_FONTSIZE@ -DOT_FONTPATH = @DOXYGEN_DOT_FONTPATH@ -CLASS_GRAPH = @DOXYGEN_CLASS_GRAPH@ -COLLABORATION_GRAPH = @DOXYGEN_COLLABORATION_GRAPH@ -GROUP_GRAPHS = @DOXYGEN_GROUP_GRAPHS@ -UML_LOOK = @DOXYGEN_UML_LOOK@ -UML_LIMIT_NUM_FIELDS = @DOXYGEN_UML_LIMIT_NUM_FIELDS@ -TEMPLATE_RELATIONS = @DOXYGEN_TEMPLATE_RELATIONS@ -INCLUDE_GRAPH = @DOXYGEN_INCLUDE_GRAPH@ -INCLUDED_BY_GRAPH = @DOXYGEN_INCLUDED_BY_GRAPH@ -CALL_GRAPH = @DOXYGEN_CALL_GRAPH@ -CALLER_GRAPH = @DOXYGEN_CALLER_GRAPH@ -GRAPHICAL_HIERARCHY = @DOXYGEN_GRAPHICAL_HIERARCHY@ -DIRECTORY_GRAPH = @DOXYGEN_DIRECTORY_GRAPH@ -DOT_IMAGE_FORMAT = @DOXYGEN_DOT_IMAGE_FORMAT@ -INTERACTIVE_SVG = @DOXYGEN_INTERACTIVE_SVG@ -DOT_PATH = @DOXYGEN_DOT_PATH@ -DOTFILE_DIRS = @DOXYGEN_DOTFILE_DIRS@ -MSCFILE_DIRS = @DOXYGEN_MSCFILE_DIRS@ -DIAFILE_DIRS = @DOXYGEN_DIAFILE_DIRS@ -PLANTUML_JAR_PATH = @DOXYGEN_PLANTUML_JAR_PATH@ -PLANTUML_CFG_FILE = @DOXYGEN_PLANTUML_CFG_FILE@ -PLANTUML_INCLUDE_PATH = @DOXYGEN_PLANTUML_INCLUDE_PATH@ -DOT_GRAPH_MAX_NODES = @DOXYGEN_DOT_GRAPH_MAX_NODES@ -MAX_DOT_GRAPH_DEPTH = @DOXYGEN_MAX_DOT_GRAPH_DEPTH@ -DOT_TRANSPARENT = @DOXYGEN_DOT_TRANSPARENT@ -DOT_MULTI_TARGETS = @DOXYGEN_DOT_MULTI_TARGETS@ -GENERATE_LEGEND = @DOXYGEN_GENERATE_LEGEND@ -DOT_CLEANUP = @DOXYGEN_DOT_CLEANUP@ diff --git a/CMakeDoxygenDefaults.cmake b/CMakeDoxygenDefaults.cmake deleted file mode 100644 index 5bebcce5..00000000 --- a/CMakeDoxygenDefaults.cmake +++ /dev/null @@ -1,664 +0,0 @@ -# -# DO NOT EDIT! THIS FILE WAS GENERATED BY CMAKE! -# - -if(NOT DEFINED DOXYGEN_DOXYFILE_ENCODING) - set(DOXYGEN_DOXYFILE_ENCODING UTF-8) -endif() -if(NOT DEFINED DOXYGEN_PROJECT_NAME) - set(DOXYGEN_PROJECT_NAME "My Project") -endif() -if(NOT DEFINED DOXYGEN_CREATE_SUBDIRS) - set(DOXYGEN_CREATE_SUBDIRS NO) -endif() -if(NOT DEFINED DOXYGEN_ALLOW_UNICODE_NAMES) - set(DOXYGEN_ALLOW_UNICODE_NAMES NO) -endif() -if(NOT DEFINED DOXYGEN_OUTPUT_LANGUAGE) - set(DOXYGEN_OUTPUT_LANGUAGE English) -endif() -if(NOT DEFINED DOXYGEN_OUTPUT_TEXT_DIRECTION) - set(DOXYGEN_OUTPUT_TEXT_DIRECTION None) -endif() -if(NOT DEFINED DOXYGEN_BRIEF_MEMBER_DESC) - set(DOXYGEN_BRIEF_MEMBER_DESC YES) -endif() -if(NOT DEFINED DOXYGEN_REPEAT_BRIEF) - set(DOXYGEN_REPEAT_BRIEF YES) -endif() -if(NOT DEFINED DOXYGEN_ABBREVIATE_BRIEF) - set(DOXYGEN_ABBREVIATE_BRIEF "The $name class" - "The $name widget" - "The $name file" - is - provides - specifies - contains - represents - a - an - the) -endif() -if(NOT DEFINED DOXYGEN_ALWAYS_DETAILED_SEC) - set(DOXYGEN_ALWAYS_DETAILED_SEC NO) -endif() -if(NOT DEFINED DOXYGEN_INLINE_INHERITED_MEMB) - set(DOXYGEN_INLINE_INHERITED_MEMB NO) -endif() -if(NOT DEFINED DOXYGEN_FULL_PATH_NAMES) - set(DOXYGEN_FULL_PATH_NAMES YES) -endif() -if(NOT DEFINED DOXYGEN_SHORT_NAMES) - set(DOXYGEN_SHORT_NAMES NO) -endif() -if(NOT DEFINED DOXYGEN_JAVADOC_AUTOBRIEF) - set(DOXYGEN_JAVADOC_AUTOBRIEF NO) -endif() -if(NOT DEFINED DOXYGEN_QT_AUTOBRIEF) - set(DOXYGEN_QT_AUTOBRIEF NO) -endif() -if(NOT DEFINED DOXYGEN_MULTILINE_CPP_IS_BRIEF) - set(DOXYGEN_MULTILINE_CPP_IS_BRIEF NO) -endif() -if(NOT DEFINED DOXYGEN_INHERIT_DOCS) - set(DOXYGEN_INHERIT_DOCS YES) -endif() -if(NOT DEFINED DOXYGEN_SEPARATE_MEMBER_PAGES) - set(DOXYGEN_SEPARATE_MEMBER_PAGES NO) -endif() -if(NOT DEFINED DOXYGEN_TAB_SIZE) - set(DOXYGEN_TAB_SIZE 4) -endif() -if(NOT DEFINED DOXYGEN_OPTIMIZE_OUTPUT_FOR_C) - set(DOXYGEN_OPTIMIZE_OUTPUT_FOR_C NO) -endif() -if(NOT DEFINED DOXYGEN_OPTIMIZE_OUTPUT_JAVA) - set(DOXYGEN_OPTIMIZE_OUTPUT_JAVA NO) -endif() -if(NOT DEFINED DOXYGEN_OPTIMIZE_FOR_FORTRAN) - set(DOXYGEN_OPTIMIZE_FOR_FORTRAN NO) -endif() -if(NOT DEFINED DOXYGEN_OPTIMIZE_OUTPUT_VHDL) - set(DOXYGEN_OPTIMIZE_OUTPUT_VHDL NO) -endif() -if(NOT DEFINED DOXYGEN_OPTIMIZE_OUTPUT_SLICE) - set(DOXYGEN_OPTIMIZE_OUTPUT_SLICE NO) -endif() -if(NOT DEFINED DOXYGEN_MARKDOWN_SUPPORT) - set(DOXYGEN_MARKDOWN_SUPPORT YES) -endif() -if(NOT DEFINED DOXYGEN_TOC_INCLUDE_HEADINGS) - set(DOXYGEN_TOC_INCLUDE_HEADINGS 0) -endif() -if(NOT DEFINED DOXYGEN_AUTOLINK_SUPPORT) - set(DOXYGEN_AUTOLINK_SUPPORT YES) -endif() -if(NOT DEFINED DOXYGEN_BUILTIN_STL_SUPPORT) - set(DOXYGEN_BUILTIN_STL_SUPPORT NO) -endif() -if(NOT DEFINED DOXYGEN_CPP_CLI_SUPPORT) - set(DOXYGEN_CPP_CLI_SUPPORT NO) -endif() -if(NOT DEFINED DOXYGEN_SIP_SUPPORT) - set(DOXYGEN_SIP_SUPPORT NO) -endif() -if(NOT DEFINED DOXYGEN_IDL_PROPERTY_SUPPORT) - set(DOXYGEN_IDL_PROPERTY_SUPPORT YES) -endif() -if(NOT DEFINED DOXYGEN_DISTRIBUTE_GROUP_DOC) - set(DOXYGEN_DISTRIBUTE_GROUP_DOC NO) -endif() -if(NOT DEFINED DOXYGEN_GROUP_NESTED_COMPOUNDS) - set(DOXYGEN_GROUP_NESTED_COMPOUNDS NO) -endif() -if(NOT DEFINED DOXYGEN_SUBGROUPING) - set(DOXYGEN_SUBGROUPING YES) -endif() -if(NOT DEFINED DOXYGEN_INLINE_GROUPED_CLASSES) - set(DOXYGEN_INLINE_GROUPED_CLASSES NO) -endif() -if(NOT DEFINED DOXYGEN_INLINE_SIMPLE_STRUCTS) - set(DOXYGEN_INLINE_SIMPLE_STRUCTS NO) -endif() -if(NOT DEFINED DOXYGEN_TYPEDEF_HIDES_STRUCT) - set(DOXYGEN_TYPEDEF_HIDES_STRUCT NO) -endif() -if(NOT DEFINED DOXYGEN_LOOKUP_CACHE_SIZE) - set(DOXYGEN_LOOKUP_CACHE_SIZE 0) -endif() -if(NOT DEFINED DOXYGEN_EXTRACT_ALL) - set(DOXYGEN_EXTRACT_ALL NO) -endif() -if(NOT DEFINED DOXYGEN_EXTRACT_PRIVATE) - set(DOXYGEN_EXTRACT_PRIVATE NO) -endif() -if(NOT DEFINED DOXYGEN_EXTRACT_PACKAGE) - set(DOXYGEN_EXTRACT_PACKAGE NO) -endif() -if(NOT DEFINED DOXYGEN_EXTRACT_STATIC) - set(DOXYGEN_EXTRACT_STATIC NO) -endif() -if(NOT DEFINED DOXYGEN_EXTRACT_LOCAL_CLASSES) - set(DOXYGEN_EXTRACT_LOCAL_CLASSES YES) -endif() -if(NOT DEFINED DOXYGEN_EXTRACT_LOCAL_METHODS) - set(DOXYGEN_EXTRACT_LOCAL_METHODS NO) -endif() -if(NOT DEFINED DOXYGEN_EXTRACT_ANON_NSPACES) - set(DOXYGEN_EXTRACT_ANON_NSPACES NO) -endif() -if(NOT DEFINED DOXYGEN_HIDE_UNDOC_MEMBERS) - set(DOXYGEN_HIDE_UNDOC_MEMBERS NO) -endif() -if(NOT DEFINED DOXYGEN_HIDE_UNDOC_CLASSES) - set(DOXYGEN_HIDE_UNDOC_CLASSES NO) -endif() -if(NOT DEFINED DOXYGEN_HIDE_FRIEND_COMPOUNDS) - set(DOXYGEN_HIDE_FRIEND_COMPOUNDS NO) -endif() -if(NOT DEFINED DOXYGEN_HIDE_IN_BODY_DOCS) - set(DOXYGEN_HIDE_IN_BODY_DOCS NO) -endif() -if(NOT DEFINED DOXYGEN_INTERNAL_DOCS) - set(DOXYGEN_INTERNAL_DOCS NO) -endif() -if(NOT DEFINED DOXYGEN_CASE_SENSE_NAMES) - set(DOXYGEN_CASE_SENSE_NAMES NO) -endif() -if(NOT DEFINED DOXYGEN_HIDE_SCOPE_NAMES) - set(DOXYGEN_HIDE_SCOPE_NAMES NO) -endif() -if(NOT DEFINED DOXYGEN_HIDE_COMPOUND_REFERENCE) - set(DOXYGEN_HIDE_COMPOUND_REFERENCE NO) -endif() -if(NOT DEFINED DOXYGEN_SHOW_INCLUDE_FILES) - set(DOXYGEN_SHOW_INCLUDE_FILES YES) -endif() -if(NOT DEFINED DOXYGEN_SHOW_GROUPED_MEMB_INC) - set(DOXYGEN_SHOW_GROUPED_MEMB_INC NO) -endif() -if(NOT DEFINED DOXYGEN_FORCE_LOCAL_INCLUDES) - set(DOXYGEN_FORCE_LOCAL_INCLUDES NO) -endif() -if(NOT DEFINED DOXYGEN_INLINE_INFO) - set(DOXYGEN_INLINE_INFO YES) -endif() -if(NOT DEFINED DOXYGEN_SORT_MEMBER_DOCS) - set(DOXYGEN_SORT_MEMBER_DOCS YES) -endif() -if(NOT DEFINED DOXYGEN_SORT_BRIEF_DOCS) - set(DOXYGEN_SORT_BRIEF_DOCS NO) -endif() -if(NOT DEFINED DOXYGEN_SORT_MEMBERS_CTORS_1ST) - set(DOXYGEN_SORT_MEMBERS_CTORS_1ST NO) -endif() -if(NOT DEFINED DOXYGEN_SORT_GROUP_NAMES) - set(DOXYGEN_SORT_GROUP_NAMES NO) -endif() -if(NOT DEFINED DOXYGEN_SORT_BY_SCOPE_NAME) - set(DOXYGEN_SORT_BY_SCOPE_NAME NO) -endif() -if(NOT DEFINED DOXYGEN_STRICT_PROTO_MATCHING) - set(DOXYGEN_STRICT_PROTO_MATCHING NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_TODOLIST) - set(DOXYGEN_GENERATE_TODOLIST YES) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_TESTLIST) - set(DOXYGEN_GENERATE_TESTLIST YES) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_BUGLIST) - set(DOXYGEN_GENERATE_BUGLIST YES) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_DEPRECATEDLIST) - set(DOXYGEN_GENERATE_DEPRECATEDLIST YES) -endif() -if(NOT DEFINED DOXYGEN_MAX_INITIALIZER_LINES) - set(DOXYGEN_MAX_INITIALIZER_LINES 30) -endif() -if(NOT DEFINED DOXYGEN_SHOW_USED_FILES) - set(DOXYGEN_SHOW_USED_FILES YES) -endif() -if(NOT DEFINED DOXYGEN_SHOW_FILES) - set(DOXYGEN_SHOW_FILES YES) -endif() -if(NOT DEFINED DOXYGEN_SHOW_NAMESPACES) - set(DOXYGEN_SHOW_NAMESPACES YES) -endif() -if(NOT DEFINED DOXYGEN_QUIET) - set(DOXYGEN_QUIET NO) -endif() -if(NOT DEFINED DOXYGEN_WARNINGS) - set(DOXYGEN_WARNINGS YES) -endif() -if(NOT DEFINED DOXYGEN_WARN_IF_UNDOCUMENTED) - set(DOXYGEN_WARN_IF_UNDOCUMENTED YES) -endif() -if(NOT DEFINED DOXYGEN_WARN_IF_DOC_ERROR) - set(DOXYGEN_WARN_IF_DOC_ERROR YES) -endif() -if(NOT DEFINED DOXYGEN_WARN_NO_PARAMDOC) - set(DOXYGEN_WARN_NO_PARAMDOC NO) -endif() -if(NOT DEFINED DOXYGEN_WARN_AS_ERROR) - set(DOXYGEN_WARN_AS_ERROR NO) -endif() -if(NOT DEFINED DOXYGEN_WARN_FORMAT) - set(DOXYGEN_WARN_FORMAT "$file:$line: $text") -endif() -if(NOT DEFINED DOXYGEN_INPUT_ENCODING) - set(DOXYGEN_INPUT_ENCODING UTF-8) -endif() -if(NOT DEFINED DOXYGEN_FILE_PATTERNS) - set(DOXYGEN_FILE_PATTERNS *.c - *.cc - *.cxx - *.cpp - *.c++ - *.java - *.ii - *.ixx - *.ipp - *.i++ - *.inl - *.idl - *.ddl - *.odl - *.h - *.hh - *.hxx - *.hpp - *.h++ - *.cs - *.d - *.php - *.php4 - *.php5 - *.phtml - *.inc - *.m - *.markdown - *.md - *.mm - *.dox - *.py - *.pyw - *.f90 - *.f95 - *.f03 - *.f08 - *.f - *.for - *.tcl - *.vhd - *.vhdl - *.ucf - *.qsf - *.ice) -endif() -if(NOT DEFINED DOXYGEN_RECURSIVE) - set(DOXYGEN_RECURSIVE NO) -endif() -if(NOT DEFINED DOXYGEN_EXCLUDE_SYMLINKS) - set(DOXYGEN_EXCLUDE_SYMLINKS NO) -endif() -if(NOT DEFINED DOXYGEN_EXAMPLE_PATTERNS) - set(DOXYGEN_EXAMPLE_PATTERNS *) -endif() -if(NOT DEFINED DOXYGEN_EXAMPLE_RECURSIVE) - set(DOXYGEN_EXAMPLE_RECURSIVE NO) -endif() -if(NOT DEFINED DOXYGEN_FILTER_SOURCE_FILES) - set(DOXYGEN_FILTER_SOURCE_FILES NO) -endif() -if(NOT DEFINED DOXYGEN_SOURCE_BROWSER) - set(DOXYGEN_SOURCE_BROWSER NO) -endif() -if(NOT DEFINED DOXYGEN_INLINE_SOURCES) - set(DOXYGEN_INLINE_SOURCES NO) -endif() -if(NOT DEFINED DOXYGEN_STRIP_CODE_COMMENTS) - set(DOXYGEN_STRIP_CODE_COMMENTS YES) -endif() -if(NOT DEFINED DOXYGEN_REFERENCED_BY_RELATION) - set(DOXYGEN_REFERENCED_BY_RELATION NO) -endif() -if(NOT DEFINED DOXYGEN_REFERENCES_RELATION) - set(DOXYGEN_REFERENCES_RELATION NO) -endif() -if(NOT DEFINED DOXYGEN_REFERENCES_LINK_SOURCE) - set(DOXYGEN_REFERENCES_LINK_SOURCE YES) -endif() -if(NOT DEFINED DOXYGEN_SOURCE_TOOLTIPS) - set(DOXYGEN_SOURCE_TOOLTIPS YES) -endif() -if(NOT DEFINED DOXYGEN_USE_HTAGS) - set(DOXYGEN_USE_HTAGS NO) -endif() -if(NOT DEFINED DOXYGEN_VERBATIM_HEADERS) - set(DOXYGEN_VERBATIM_HEADERS YES) -endif() -if(NOT DEFINED DOXYGEN_ALPHABETICAL_INDEX) - set(DOXYGEN_ALPHABETICAL_INDEX YES) -endif() -if(NOT DEFINED DOXYGEN_COLS_IN_ALPHA_INDEX) - set(DOXYGEN_COLS_IN_ALPHA_INDEX 5) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_HTML) - set(DOXYGEN_GENERATE_HTML YES) -endif() -if(NOT DEFINED DOXYGEN_HTML_OUTPUT) - set(DOXYGEN_HTML_OUTPUT html) -endif() -if(NOT DEFINED DOXYGEN_HTML_FILE_EXTENSION) - set(DOXYGEN_HTML_FILE_EXTENSION .html) -endif() -if(NOT DEFINED DOXYGEN_HTML_COLORSTYLE_HUE) - set(DOXYGEN_HTML_COLORSTYLE_HUE 220) -endif() -if(NOT DEFINED DOXYGEN_HTML_COLORSTYLE_SAT) - set(DOXYGEN_HTML_COLORSTYLE_SAT 100) -endif() -if(NOT DEFINED DOXYGEN_HTML_COLORSTYLE_GAMMA) - set(DOXYGEN_HTML_COLORSTYLE_GAMMA 80) -endif() -if(NOT DEFINED DOXYGEN_HTML_TIMESTAMP) - set(DOXYGEN_HTML_TIMESTAMP NO) -endif() -if(NOT DEFINED DOXYGEN_HTML_DYNAMIC_MENUS) - set(DOXYGEN_HTML_DYNAMIC_MENUS YES) -endif() -if(NOT DEFINED DOXYGEN_HTML_DYNAMIC_SECTIONS) - set(DOXYGEN_HTML_DYNAMIC_SECTIONS NO) -endif() -if(NOT DEFINED DOXYGEN_HTML_INDEX_NUM_ENTRIES) - set(DOXYGEN_HTML_INDEX_NUM_ENTRIES 100) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_DOCSET) - set(DOXYGEN_GENERATE_DOCSET NO) -endif() -if(NOT DEFINED DOXYGEN_DOCSET_FEEDNAME) - set(DOXYGEN_DOCSET_FEEDNAME "Doxygen generated docs") -endif() -if(NOT DEFINED DOXYGEN_DOCSET_BUNDLE_ID) - set(DOXYGEN_DOCSET_BUNDLE_ID org.doxygen.Project) -endif() -if(NOT DEFINED DOXYGEN_DOCSET_PUBLISHER_ID) - set(DOXYGEN_DOCSET_PUBLISHER_ID org.doxygen.Publisher) -endif() -if(NOT DEFINED DOXYGEN_DOCSET_PUBLISHER_NAME) - set(DOXYGEN_DOCSET_PUBLISHER_NAME Publisher) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_HTMLHELP) - set(DOXYGEN_GENERATE_HTMLHELP NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_CHI) - set(DOXYGEN_GENERATE_CHI NO) -endif() -if(NOT DEFINED DOXYGEN_BINARY_TOC) - set(DOXYGEN_BINARY_TOC NO) -endif() -if(NOT DEFINED DOXYGEN_TOC_EXPAND) - set(DOXYGEN_TOC_EXPAND NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_QHP) - set(DOXYGEN_GENERATE_QHP NO) -endif() -if(NOT DEFINED DOXYGEN_QHP_NAMESPACE) - set(DOXYGEN_QHP_NAMESPACE org.doxygen.Project) -endif() -if(NOT DEFINED DOXYGEN_QHP_VIRTUAL_FOLDER) - set(DOXYGEN_QHP_VIRTUAL_FOLDER doc) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_ECLIPSEHELP) - set(DOXYGEN_GENERATE_ECLIPSEHELP NO) -endif() -if(NOT DEFINED DOXYGEN_ECLIPSE_DOC_ID) - set(DOXYGEN_ECLIPSE_DOC_ID org.doxygen.Project) -endif() -if(NOT DEFINED DOXYGEN_DISABLE_INDEX) - set(DOXYGEN_DISABLE_INDEX NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_TREEVIEW) - set(DOXYGEN_GENERATE_TREEVIEW NO) -endif() -if(NOT DEFINED DOXYGEN_ENUM_VALUES_PER_LINE) - set(DOXYGEN_ENUM_VALUES_PER_LINE 4) -endif() -if(NOT DEFINED DOXYGEN_TREEVIEW_WIDTH) - set(DOXYGEN_TREEVIEW_WIDTH 250) -endif() -if(NOT DEFINED DOXYGEN_EXT_LINKS_IN_WINDOW) - set(DOXYGEN_EXT_LINKS_IN_WINDOW NO) -endif() -if(NOT DEFINED DOXYGEN_FORMULA_FONTSIZE) - set(DOXYGEN_FORMULA_FONTSIZE 10) -endif() -if(NOT DEFINED DOXYGEN_FORMULA_TRANSPARENT) - set(DOXYGEN_FORMULA_TRANSPARENT YES) -endif() -if(NOT DEFINED DOXYGEN_USE_MATHJAX) - set(DOXYGEN_USE_MATHJAX NO) -endif() -if(NOT DEFINED DOXYGEN_MATHJAX_FORMAT) - set(DOXYGEN_MATHJAX_FORMAT HTML-CSS) -endif() -if(NOT DEFINED DOXYGEN_MATHJAX_RELPATH) - set(DOXYGEN_MATHJAX_RELPATH https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/) -endif() -if(NOT DEFINED DOXYGEN_SEARCHENGINE) - set(DOXYGEN_SEARCHENGINE YES) -endif() -if(NOT DEFINED DOXYGEN_SERVER_BASED_SEARCH) - set(DOXYGEN_SERVER_BASED_SEARCH NO) -endif() -if(NOT DEFINED DOXYGEN_EXTERNAL_SEARCH) - set(DOXYGEN_EXTERNAL_SEARCH NO) -endif() -if(NOT DEFINED DOXYGEN_SEARCHDATA_FILE) - set(DOXYGEN_SEARCHDATA_FILE searchdata.xml) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_LATEX) - set(DOXYGEN_GENERATE_LATEX YES) -endif() -if(NOT DEFINED DOXYGEN_LATEX_OUTPUT) - set(DOXYGEN_LATEX_OUTPUT latex) -endif() -if(NOT DEFINED DOXYGEN_MAKEINDEX_CMD_NAME) - set(DOXYGEN_MAKEINDEX_CMD_NAME makeindex) -endif() -if(NOT DEFINED DOXYGEN_LATEX_MAKEINDEX_CMD) - set(DOXYGEN_LATEX_MAKEINDEX_CMD makeindex) -endif() -if(NOT DEFINED DOXYGEN_COMPACT_LATEX) - set(DOXYGEN_COMPACT_LATEX NO) -endif() -if(NOT DEFINED DOXYGEN_PAPER_TYPE) - set(DOXYGEN_PAPER_TYPE a4) -endif() -if(NOT DEFINED DOXYGEN_PDF_HYPERLINKS) - set(DOXYGEN_PDF_HYPERLINKS YES) -endif() -if(NOT DEFINED DOXYGEN_USE_PDFLATEX) - set(DOXYGEN_USE_PDFLATEX YES) -endif() -if(NOT DEFINED DOXYGEN_LATEX_BATCHMODE) - set(DOXYGEN_LATEX_BATCHMODE NO) -endif() -if(NOT DEFINED DOXYGEN_LATEX_HIDE_INDICES) - set(DOXYGEN_LATEX_HIDE_INDICES NO) -endif() -if(NOT DEFINED DOXYGEN_LATEX_SOURCE_CODE) - set(DOXYGEN_LATEX_SOURCE_CODE NO) -endif() -if(NOT DEFINED DOXYGEN_LATEX_BIB_STYLE) - set(DOXYGEN_LATEX_BIB_STYLE plain) -endif() -if(NOT DEFINED DOXYGEN_LATEX_TIMESTAMP) - set(DOXYGEN_LATEX_TIMESTAMP NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_RTF) - set(DOXYGEN_GENERATE_RTF NO) -endif() -if(NOT DEFINED DOXYGEN_RTF_OUTPUT) - set(DOXYGEN_RTF_OUTPUT rtf) -endif() -if(NOT DEFINED DOXYGEN_COMPACT_RTF) - set(DOXYGEN_COMPACT_RTF NO) -endif() -if(NOT DEFINED DOXYGEN_RTF_HYPERLINKS) - set(DOXYGEN_RTF_HYPERLINKS NO) -endif() -if(NOT DEFINED DOXYGEN_RTF_SOURCE_CODE) - set(DOXYGEN_RTF_SOURCE_CODE NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_MAN) - set(DOXYGEN_GENERATE_MAN NO) -endif() -if(NOT DEFINED DOXYGEN_MAN_OUTPUT) - set(DOXYGEN_MAN_OUTPUT man) -endif() -if(NOT DEFINED DOXYGEN_MAN_EXTENSION) - set(DOXYGEN_MAN_EXTENSION .3) -endif() -if(NOT DEFINED DOXYGEN_MAN_LINKS) - set(DOXYGEN_MAN_LINKS NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_XML) - set(DOXYGEN_GENERATE_XML NO) -endif() -if(NOT DEFINED DOXYGEN_XML_OUTPUT) - set(DOXYGEN_XML_OUTPUT xml) -endif() -if(NOT DEFINED DOXYGEN_XML_PROGRAMLISTING) - set(DOXYGEN_XML_PROGRAMLISTING YES) -endif() -if(NOT DEFINED DOXYGEN_XML_NS_MEMB_FILE_SCOPE) - set(DOXYGEN_XML_NS_MEMB_FILE_SCOPE NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_DOCBOOK) - set(DOXYGEN_GENERATE_DOCBOOK NO) -endif() -if(NOT DEFINED DOXYGEN_DOCBOOK_OUTPUT) - set(DOXYGEN_DOCBOOK_OUTPUT docbook) -endif() -if(NOT DEFINED DOXYGEN_DOCBOOK_PROGRAMLISTING) - set(DOXYGEN_DOCBOOK_PROGRAMLISTING NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_AUTOGEN_DEF) - set(DOXYGEN_GENERATE_AUTOGEN_DEF NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_PERLMOD) - set(DOXYGEN_GENERATE_PERLMOD NO) -endif() -if(NOT DEFINED DOXYGEN_PERLMOD_LATEX) - set(DOXYGEN_PERLMOD_LATEX NO) -endif() -if(NOT DEFINED DOXYGEN_PERLMOD_PRETTY) - set(DOXYGEN_PERLMOD_PRETTY YES) -endif() -if(NOT DEFINED DOXYGEN_ENABLE_PREPROCESSING) - set(DOXYGEN_ENABLE_PREPROCESSING YES) -endif() -if(NOT DEFINED DOXYGEN_MACRO_EXPANSION) - set(DOXYGEN_MACRO_EXPANSION NO) -endif() -if(NOT DEFINED DOXYGEN_EXPAND_ONLY_PREDEF) - set(DOXYGEN_EXPAND_ONLY_PREDEF NO) -endif() -if(NOT DEFINED DOXYGEN_SEARCH_INCLUDES) - set(DOXYGEN_SEARCH_INCLUDES YES) -endif() -if(NOT DEFINED DOXYGEN_SKIP_FUNCTION_MACROS) - set(DOXYGEN_SKIP_FUNCTION_MACROS YES) -endif() -if(NOT DEFINED DOXYGEN_ALLEXTERNALS) - set(DOXYGEN_ALLEXTERNALS NO) -endif() -if(NOT DEFINED DOXYGEN_EXTERNAL_GROUPS) - set(DOXYGEN_EXTERNAL_GROUPS YES) -endif() -if(NOT DEFINED DOXYGEN_EXTERNAL_PAGES) - set(DOXYGEN_EXTERNAL_PAGES YES) -endif() -if(NOT DEFINED DOXYGEN_PERL_PATH) - set(DOXYGEN_PERL_PATH /usr/bin/perl) -endif() -if(NOT DEFINED DOXYGEN_CLASS_DIAGRAMS) - set(DOXYGEN_CLASS_DIAGRAMS YES) -endif() -if(NOT DEFINED DOXYGEN_HIDE_UNDOC_RELATIONS) - set(DOXYGEN_HIDE_UNDOC_RELATIONS YES) -endif() -if(NOT DEFINED DOXYGEN_HAVE_DOT) - set(DOXYGEN_HAVE_DOT NO) -endif() -if(NOT DEFINED DOXYGEN_DOT_NUM_THREADS) - set(DOXYGEN_DOT_NUM_THREADS 0) -endif() -if(NOT DEFINED DOXYGEN_DOT_FONTNAME) - set(DOXYGEN_DOT_FONTNAME Helvetica) -endif() -if(NOT DEFINED DOXYGEN_DOT_FONTSIZE) - set(DOXYGEN_DOT_FONTSIZE 10) -endif() -if(NOT DEFINED DOXYGEN_CLASS_GRAPH) - set(DOXYGEN_CLASS_GRAPH YES) -endif() -if(NOT DEFINED DOXYGEN_COLLABORATION_GRAPH) - set(DOXYGEN_COLLABORATION_GRAPH YES) -endif() -if(NOT DEFINED DOXYGEN_GROUP_GRAPHS) - set(DOXYGEN_GROUP_GRAPHS YES) -endif() -if(NOT DEFINED DOXYGEN_UML_LOOK) - set(DOXYGEN_UML_LOOK NO) -endif() -if(NOT DEFINED DOXYGEN_UML_LIMIT_NUM_FIELDS) - set(DOXYGEN_UML_LIMIT_NUM_FIELDS 10) -endif() -if(NOT DEFINED DOXYGEN_TEMPLATE_RELATIONS) - set(DOXYGEN_TEMPLATE_RELATIONS NO) -endif() -if(NOT DEFINED DOXYGEN_INCLUDE_GRAPH) - set(DOXYGEN_INCLUDE_GRAPH YES) -endif() -if(NOT DEFINED DOXYGEN_INCLUDED_BY_GRAPH) - set(DOXYGEN_INCLUDED_BY_GRAPH YES) -endif() -if(NOT DEFINED DOXYGEN_CALL_GRAPH) - set(DOXYGEN_CALL_GRAPH NO) -endif() -if(NOT DEFINED DOXYGEN_CALLER_GRAPH) - set(DOXYGEN_CALLER_GRAPH NO) -endif() -if(NOT DEFINED DOXYGEN_GRAPHICAL_HIERARCHY) - set(DOXYGEN_GRAPHICAL_HIERARCHY YES) -endif() -if(NOT DEFINED DOXYGEN_DIRECTORY_GRAPH) - set(DOXYGEN_DIRECTORY_GRAPH YES) -endif() -if(NOT DEFINED DOXYGEN_DOT_IMAGE_FORMAT) - set(DOXYGEN_DOT_IMAGE_FORMAT png) -endif() -if(NOT DEFINED DOXYGEN_INTERACTIVE_SVG) - set(DOXYGEN_INTERACTIVE_SVG NO) -endif() -if(NOT DEFINED DOXYGEN_DOT_GRAPH_MAX_NODES) - set(DOXYGEN_DOT_GRAPH_MAX_NODES 50) -endif() -if(NOT DEFINED DOXYGEN_MAX_DOT_GRAPH_DEPTH) - set(DOXYGEN_MAX_DOT_GRAPH_DEPTH 0) -endif() -if(NOT DEFINED DOXYGEN_DOT_TRANSPARENT) - set(DOXYGEN_DOT_TRANSPARENT NO) -endif() -if(NOT DEFINED DOXYGEN_DOT_MULTI_TARGETS) - set(DOXYGEN_DOT_MULTI_TARGETS NO) -endif() -if(NOT DEFINED DOXYGEN_GENERATE_LEGEND) - set(DOXYGEN_GENERATE_LEGEND YES) -endif() -if(NOT DEFINED DOXYGEN_DOT_CLEANUP) - set(DOXYGEN_DOT_CLEANUP YES) -endif() diff --git a/libraries/appbase/CMakeLists.txt b/libraries/appbase/CMakeLists.txt index fddd3baa..887afbe2 100644 --- a/libraries/appbase/CMakeLists.txt +++ b/libraries/appbase/CMakeLists.txt @@ -40,6 +40,7 @@ endif() add_library( appbase application.cpp + plugin.cpp ) target_link_libraries( appbase fc ${Boost_LIBRARIES}) diff --git a/libraries/appbase/include/appbase/plugin.hpp b/libraries/appbase/include/appbase/plugin.hpp index 590316d9..0eadc445 100644 --- a/libraries/appbase/include/appbase/plugin.hpp +++ b/libraries/appbase/include/appbase/plugin.hpp @@ -87,42 +87,14 @@ class plugin : public abstract_plugin //this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){} ); } - virtual void initialize(const variables_map& options) override final - { - if( _state == registered ) - { - _state = initialized; - this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.initialize( options ); } ); - this->plugin_initialize( options ); - // std::cout << "Initializing plugin " << Impl::name() << std::endl; - app()->plugin_initialized( *this ); - } - if (_state != initialized) - BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not registered, so final state cannot be initialized.") ); - } + virtual void initialize(const variables_map& options) override final; - virtual void startup() override final - { - if( _state == initialized ) - { - _state = started; - this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.startup(); } ); - this->plugin_startup(); - app()->plugin_started( *this ); - } - if (_state != started ) - BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not initialized, so final state cannot be started.") ); - } - virtual void shutdown() override final - { - if( _state == started ) - { - _state = stopped; - //ilog( "shutting down plugin ${name}", ("name",name()) ); - this->plugin_shutdown(); - } - } + virtual void startup() override final; + + + virtual void shutdown() override final; + protected: plugin() = default; diff --git a/libraries/appbase/plugin.cpp b/libraries/appbase/plugin.cpp new file mode 100644 index 00000000..aecd191d --- /dev/null +++ b/libraries/appbase/plugin.cpp @@ -0,0 +1,53 @@ +#include + +#include +#include +#include + +#include +#include + +namespace appbase { + +template< typename Impl > +void plugin::initialize(const variables_map& options) +{ + if( _state == registered ) + { + _state = initialized; + this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.initialize( options ); } ); + this->plugin_initialize( options ); + // std::cout << "Initializing plugin " << Impl::name() << std::endl; + app()->plugin_initialized( *this ); + } + if (_state != initialized) + BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not registered, so final state cannot be initialized.") ); +} + +template< typename Impl > +void plugin::startup() +{ + if( _state == initialized ) + { + _state = started; + this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.startup(); } ); + this->plugin_startup(); + app()->plugin_started( *this ); + } + if (_state != started ) + BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not initialized, so final state cannot be started.") ); +} + +template< typename Impl > +void plugin::shutdown() +{ + if( _state == started ) + { + _state = stopped; + //ilog( "shutting down plugin ${name}", ("name",name()) ); + this->plugin_shutdown(); + } +} + + +} \ No newline at end of file From cbe25662300478624190c79b0937009081f6473a Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 31 Jan 2019 12:21:58 +0100 Subject: [PATCH 09/17] fixing gcc --- .../appbase/include/appbase/application.hpp | 4 +- libraries/appbase/include/appbase/plugin.hpp | 39 +++++++++++++++--- libraries/appbase/plugin.cpp | 41 +++---------------- 3 files changed, 41 insertions(+), 43 deletions(-) diff --git a/libraries/appbase/include/appbase/application.hpp b/libraries/appbase/include/appbase/application.hpp index 8acbad6a..cb728d9f 100644 --- a/libraries/appbase/include/appbase/application.hpp +++ b/libraries/appbase/include/appbase/application.hpp @@ -132,8 +132,8 @@ namespace appbase { boost::asio::io_service& get_io_service() { return *io_serv; } protected: - template< typename Impl > - friend class plugin; + template< typename Impl >friend class plugin; + friend class abstract_plugin; abstract_plugin* find_plugin( const string& name )const; abstract_plugin& get_plugin( const string& name )const; diff --git a/libraries/appbase/include/appbase/plugin.hpp b/libraries/appbase/include/appbase/plugin.hpp index 0eadc445..ec54a44c 100644 --- a/libraries/appbase/include/appbase/plugin.hpp +++ b/libraries/appbase/include/appbase/plugin.hpp @@ -69,6 +69,8 @@ class abstract_plugin : std::enable_shared_from_this */ virtual void plugin_shutdown() = 0; + void notify_app_initialize(); + void notify_app_startup(); private: std::shared_ptr _app; }; @@ -87,18 +89,45 @@ class plugin : public abstract_plugin //this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){} ); } - virtual void initialize(const variables_map& options) override final; - - - virtual void startup() override final; + virtual void initialize(const variables_map& options) override final{ + if( _state == registered ) + { + _state = initialized; + this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.initialize( options ); } ); + this->plugin_initialize( options ); + // std::cout << "Initializing plugin " << Impl::name() << std::endl; + notify_app_initialize(); + } + if (_state != initialized) + BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not registered, so final state cannot be initialized.") ); + } + virtual void startup() override final{ + if( _state == initialized ) + { + _state = started; + this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.startup(); } ); + this->plugin_startup(); + notify_app_startup(); + } + if (_state != started ) + BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not initialized, so final state cannot be started.") ); + } - virtual void shutdown() override final; + virtual void shutdown() override final{ + if( _state == started ) + { + _state = stopped; + //ilog( "shutting down plugin ${name}", ("name",name()) ); + this->plugin_shutdown(); + } + } protected: plugin() = default; + private: state _state = abstract_plugin::registered; }; diff --git a/libraries/appbase/plugin.cpp b/libraries/appbase/plugin.cpp index aecd191d..1a4118f2 100644 --- a/libraries/appbase/plugin.cpp +++ b/libraries/appbase/plugin.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -9,45 +10,13 @@ namespace appbase { -template< typename Impl > -void plugin::initialize(const variables_map& options) -{ - if( _state == registered ) - { - _state = initialized; - this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.initialize( options ); } ); - this->plugin_initialize( options ); - // std::cout << "Initializing plugin " << Impl::name() << std::endl; - app()->plugin_initialized( *this ); - } - if (_state != initialized) - BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not registered, so final state cannot be initialized.") ); +void abstract_plugin::notify_app_initialize() { + app()->plugin_initialized(*this); } -template< typename Impl > -void plugin::startup() -{ - if( _state == initialized ) - { - _state = started; - this->plugin_for_each_dependency( [&]( abstract_plugin& plug ){ plug.startup(); } ); - this->plugin_startup(); - app()->plugin_started( *this ); - } - if (_state != started ) - BOOST_THROW_EXCEPTION( std::runtime_error("Initial state was not initialized, so final state cannot be started.") ); -} -template< typename Impl > -void plugin::shutdown() -{ - if( _state == started ) - { - _state = stopped; - //ilog( "shutting down plugin ${name}", ("name",name()) ); - this->plugin_shutdown(); - } +void abstract_plugin::notify_app_startup() { + app()->plugin_started(*this); } - } \ No newline at end of file From fd1f72f3d08f68b9c8586f6829606013124f5936 Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 31 Jan 2019 12:42:42 +0100 Subject: [PATCH 10/17] fix in plugin directory creation --- libraries/appbase/application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index 4edf42cb..f72372e2 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -390,7 +390,7 @@ map> application_factory::initialize( int a plugins_dir = data_dir / plugins_dir; if (bfs::exists(plugins_dir) == false) { - bfs::create_directory(plugins_dir); + bfs::create_directories(plugins_dir); } } From 4846d48f1d3f9c014211873ba4d562947bf6313e Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 31 Jan 2019 13:40:47 +0100 Subject: [PATCH 11/17] Options handling --- libraries/appbase/application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index f72372e2..b114dd99 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -323,7 +323,7 @@ const variables_map& application::get_args() const void application_factory::add_program_options( const options_description& cli ) { - app_options.add( cli ); + global_options.add( cli ); } application_factory& app_factory() { return application_factory::get_app_factory(); } From a9af2b5df98a2d80d75e2079f71f15e43e095b04 Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 31 Jan 2019 18:18:30 +0100 Subject: [PATCH 12/17] change the application handling from pointers to refs --- libraries/appbase/CMakeLists.txt | 4 +- libraries/appbase/application.cpp | 64 ++- .../appbase/include/appbase/application.hpp | 422 +++++++++--------- libraries/appbase/include/appbase/plugin.hpp | 15 +- .../manifest/gensrc/plugins/CMakeLists.txt | 2 + .../plugins/json_rpc/json_rpc_plugin.hpp | 2 +- .../json_rpc/{plugins.json => plugin.json} | 0 programs/sophiatxd/main.cpp | 2 +- tests/db_fixture/database_fixture.cpp | 31 +- tests/db_fixture/database_fixture.hpp | 4 +- tests/tests/block_tests.cpp | 10 +- 11 files changed, 287 insertions(+), 269 deletions(-) rename libraries/plugins/json_rpc/{plugins.json => plugin.json} (100%) diff --git a/libraries/appbase/CMakeLists.txt b/libraries/appbase/CMakeLists.txt index 887afbe2..a5f03b3e 100644 --- a/libraries/appbase/CMakeLists.txt +++ b/libraries/appbase/CMakeLists.txt @@ -21,11 +21,11 @@ set( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" ) if( APPLE ) # Apple Specific Options Here message( STATUS "Configuring AppBase on OS X" ) - set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14 -stdlib=libc++ -Wall -Wno-conversion -Wno-deprecated-declarations" ) + set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++17 -stdlib=libc++ -Wall -Wno-conversion -Wno-deprecated-declarations" ) else( APPLE ) # Linux Specific Options Here message( STATUS "Configuring AppBase on Linux" ) - set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++14 -Wall -pthread" ) + set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++17 -Wall -pthread" ) set( rt_library rt ) set( pthread_library pthread) if ( SOPHIATX_STATIC_BUILD ) diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index b114dd99..49cfba14 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -181,7 +181,7 @@ bool application::load_external_plugins() { return false; } - loaded_plugin->set_app( shared_from_this() ); + loaded_plugin->set_app( *this ); // Registers loaded plugin for application register_external_plugin(loaded_plugin); @@ -222,6 +222,11 @@ bool application::initialize( const variables_map& app_settings, const vector_args = app_settings; + //first start the autostart plugins, then the config.ini defined plugins and then the external ones + + vector plugin_names; + std::copy(autostart_plugins.begin(), autostart_plugins.end(), std::back_inserter(plugin_names)); + if(my->_args.count("plugin") > 0) { auto plugins = my->_args.at("plugin").as>(); @@ -229,22 +234,18 @@ bool application::initialize( const variables_map& app_settings, const vector names; boost::split(names, arg, boost::is_any_of(" \t,")); - for(const std::string& name : names) - get_plugin(name).initialize(my->_args); + std::copy(names.begin(), names.end(), std::back_inserter(plugin_names)); } } + for(const std::string& name : plugin_names) + get_register_plugin(name)->initialize(my->_args); + // Loads external plugins specified in config if (load_external_plugins() == false) { return false; } - for (const auto& plugin_name : autostart_plugins){ - auto plugin = find_plugin( plugin_name ); - if (plugin != nullptr && plugin->get_state() == abstract_plugin::registered) - plugin->initialize(my->_args); - } - return true; } catch (const boost::program_options::error& e) @@ -356,11 +357,11 @@ void application_factory::set_program_options() global_options.add(app_cli_opts); } -map> application_factory::initialize( int argc, char** argv, vector< string > _autostart_plugins, bool start_apps ) +map application_factory::initialize( int argc, char** argv, vector< string > _autostart_plugins, bool start_apps ) { try { - map> ret; + map< string, application& > ret; bpo::store( bpo::parse_command_line( argc, argv, global_options ), global_args ); std::copy(_autostart_plugins.begin(), _autostart_plugins.end(), std::back_inserter(autostart_plugins)); @@ -394,8 +395,6 @@ map> application_factory::initialize( int a } } - - // config par (even if it is default) must be always present assert(global_args.count( "config" )); @@ -416,29 +415,54 @@ map> application_factory::initialize( int a boost::split(names, arg, boost::is_any_of(" \t,")); for( const std::string &name : names ) { variables_map app_args = read_app_config(name); - auto new_app = new_application(name); - new_app->initialize(app_args, autostart_plugins); - ret[ name ] = new_app; + auto& new_app = new_application(name); + new_app.initialize(app_args, autostart_plugins); + ret.emplace(name, new_app); } } } else { //load default (public) one. variables_map app_args = read_app_config(_public_net_chain_id); - auto new_app = new_application(_public_net_chain_id); - new_app->initialize(app_args, autostart_plugins); - ret[ _public_net_chain_id ] = new_app; + auto& new_app = new_application(_public_net_chain_id); + new_app.initialize(app_args, autostart_plugins); + ret.emplace(_public_net_chain_id, new_app); } } return ret; } catch (const boost::program_options::error& e) { - map> ret; + map ret; std::cerr << "Error parsing command line: " << e.what() << "\n"; return ret; } } +void application_factory::startup(){ + for(auto& app : apps) + app.second.startup(); +}; + +void application_factory::exec(){ + for(auto& app : apps) + app.second.exec(); +}; +void application_factory::shutdown(){ + for(auto& app : apps) + app.second.shutdown(); +} +void application_factory::quit(){ + for(auto& app : apps) + app.second.quit(); +} + +application& application_factory::new_application( const string& id){ + if(apps.count(id)) + apps.erase(id); + apps.emplace(id, id); + return apps.at(id); +} + variables_map application_factory::read_app_config(std::string name) { bfs::path config_file_path = write_default_config(app_options, global_args[ "config" ].as(), diff --git a/libraries/appbase/include/appbase/application.hpp b/libraries/appbase/include/appbase/application.hpp index cb728d9f..b6dcb1bf 100644 --- a/libraries/appbase/include/appbase/application.hpp +++ b/libraries/appbase/include/appbase/application.hpp @@ -11,234 +11,230 @@ namespace appbase { - namespace bpo = boost::program_options; - namespace bfs = boost::filesystem; +namespace bpo = boost::program_options; +namespace bfs = boost::filesystem; + +class application; + +/** + * @brief Simple data holder for plugin program options + */ +class plugin_program_options { +public: + plugin_program_options(const options_description& cli_options, const options_description& cfg_options) : + _cli_options(cli_options), + _cfg_options(cfg_options) + {} + + const options_description& get_cli_options() const { return _cli_options; } + const options_description& get_cfg_options() const { return _cfg_options; } + +private: + // command line options + options_description _cli_options; + // configuration file options + options_description _cfg_options; +}; + + +class application_factory +{ +public: + static application_factory &get_app_factory() { + static application_factory instance; + return instance; + } + + application_factory(application_factory const &) = delete; + void operator=(application_factory const &) = delete; + + template void register_plugin_factory(){ + if( plugin_factories.find(P::name()) != plugin_factories.end() ) + return; + std::shared_ptr> new_plugin_factory = std::make_shared>(); + plugin_factories[P::name()] = new_plugin_factory; + const plugin_program_options& plugin_options = get_plugin_program_options(new_plugin_factory); + const options_description& plugin_cfg_options = plugin_options.get_cfg_options(); + if (plugin_cfg_options.options().size()) { + app_options.add(plugin_cfg_options); + } + + const options_description& plugin_cli_options = plugin_options.get_cli_options(); + if (plugin_cli_options.options().size()) { + app_options.add(plugin_cli_options); + } + } + + application& new_application( const string& id); + + template + std::shared_ptr< abstract_plugin > new_plugin(){ + return new_plugin(Plugin::name()); + } + + std::shared_ptr< abstract_plugin > new_plugin(string name){ + const auto& pf = plugin_factories.at(name); + auto new_plugin = pf->new_plugin(); + return new_plugin; + } + + void add_program_options( const bpo::options_description& cli ); + variables_map read_app_config(string name); + + map initialize( int argc, char** argv, vector< string > autostart_plugins, bool start_apps = true ); + void set_version_string( const string& version ) { version_info = version; } + + options_description app_options; + options_description global_options; + bfs::path data_dir; + bfs::path plugins_dir; + variables_map global_args; + + void startup(); + void exec(); + void shutdown(); + void quit(); + +private: + void set_program_options(); + std::map> plugin_factories; + vector autostart_plugins; + std::map apps; + string version_info; + + application_factory():global_options("Application Options") { + set_program_options(); + }; + - class application; + plugin_program_options get_plugin_program_options(std::shared_ptr plugin_factory); +}; + +application_factory& app_factory(); + + +class application +{ +public: + ~application(); + application(const string& _id); + application() = delete; + application(const application &) = delete; /** - * @brief Simple data holder for plugin program options + * @brief Looks for the --plugin commandline / config option and calls initialize on those plugins + * + * @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 */ - class plugin_program_options { - public: - plugin_program_options(const options_description& cli_options, const options_description& cfg_options) : - _cli_options(cli_options), - _cfg_options(cfg_options) - {} - - const options_description& get_cli_options() const { return _cli_options; } - const options_description& get_cfg_options() const { return _cfg_options; } - - private: - // command line options - options_description _cli_options; - // configuration file options - options_description _cfg_options; - }; + bool initialize( const variables_map& app_settings, const vector& autostart_plugins ); + void startup(); + void shutdown(); - class application : std::enable_shared_from_this - { - public: - ~application(); - application(const string& _id); - - /** - * @brief Looks for the --plugin commandline / config option and calls initialize on those plugins - * - * @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( const variables_map& app_settings, const vector& autostart_plugins ); - - void startup(); - void shutdown(); - - /** - * Wait until quit(), SIGINT or SIGTERM and then shutdown - */ - void exec(); - void quit(); - - void register_plugin( const std::shared_ptr& plugin ){ - auto existing = find_plugin( plugin->get_name() ); - if(existing) - return; - - plugins[plugin->get_name()] = plugin; - plugin->register_dependencies(); - } - - /** - * @brief Loads external plugins specified in config - * - * @return - */ - bool load_external_plugins(); - - /** - * @brief Registers external plugin into the list of all app plugins - * - * @param plugin - */ - void register_external_plugin(const std::shared_ptr& plugin); - - /** - * @brief Loads external plugin config - * - * @param plugin - */ - void load_external_plugin_config(const std::function options_setter, const std::string& cfg_plugin_name); - - template< typename Plugin > - Plugin* find_plugin()const - { - Plugin* plugin = dynamic_cast< Plugin* >( find_plugin( Plugin::name() ) ); - - return plugin; - } - - template< typename Plugin > - Plugin& get_plugin()const - { - auto ptr = find_plugin< Plugin >(); - if( ptr == nullptr ) - BOOST_THROW_EXCEPTION( std::runtime_error( "unable to find plugin: " + Plugin::name() ) ); - return *ptr; - } - - template< typename Plugin > - Plugin& get_or_create_plugin() - { - Plugin* plugin = dynamic_cast< Plugin* >( find_plugin( Plugin::name() ) ); - if( plugin != nullptr ) - return *plugin; - auto new_plg = std::make_shared(); - new_plg->set_app( shared_from_this() ); - plugins[ Plugin::name() ] = new_plg; - return *new_plg; - } - - void reset(){ - plugins.clear(); - } - - bfs::path data_dir()const; - - const bpo::variables_map& get_args() const; - string id; - - boost::asio::io_service& get_io_service() { return *io_serv; } - - protected: - template< typename Impl >friend class plugin; - friend class abstract_plugin; - - abstract_plugin* find_plugin( const string& name )const; - abstract_plugin& get_plugin( const string& name )const; - - /** these notifications get called from the plugin when their state changes so that - * the application can call shutdown in the reverse order. - */ - ///@{ - void plugin_initialized( abstract_plugin& plug ) { initialized_plugins.push_back( &plug ); } - void plugin_started( abstract_plugin& plug ) { running_plugins.push_back( &plug ); } - ///@} - - private: - - map< string, std::shared_ptr< abstract_plugin > > plugins; ///< all registered plugins - vector< abstract_plugin* > initialized_plugins; ///< stored in the order they were started running - vector< abstract_plugin* > running_plugins; ///< stored in the order they were started running - std::shared_ptr< boost::asio::io_service > io_serv; - - std::unique_ptr< class application_impl > my; + /** + * Wait until quit(), SIGINT or SIGTERM and then shutdown + */ + void exec(); + void quit(); - }; + void register_plugin( const std::shared_ptr& plugin ){ + auto existing = find_plugin( plugin->get_name() ); + if(existing) + return; + + plugin->set_app(*this); + plugins[plugin->get_name()] = plugin; + plugin->register_dependencies(); + } + + /** + * @brief Loads external plugins specified in config + * + * @return + */ + bool load_external_plugins(); + + /** + * @brief Registers external plugin into the list of all app plugins + * + * @param plugin + */ + void register_external_plugin(const std::shared_ptr& plugin); - class application_factory + /** + * @brief Loads external plugin config + * + * @param plugin + */ + void load_external_plugin_config(const std::function options_setter, const std::string& cfg_plugin_name); + + template< typename Plugin > + Plugin* find_plugin()const { - public: - static application_factory &get_app_factory() { - static application_factory instance; - return instance; - } + Plugin* plugin = dynamic_cast< Plugin* >( find_plugin( Plugin::name() ) ); + return plugin; + } - application_factory(application_factory const &) = delete; - void operator=(application_factory const &) = delete; - - template void register_plugin_factory(){ - if( plugin_factories.find(P::name()) != plugin_factories.end() ) - return; - std::shared_ptr> new_plugin_factory = std::make_shared>(); - plugin_factories[P::name()] = new_plugin_factory; - const plugin_program_options& plugin_options = get_plugin_program_options(new_plugin_factory); - const options_description& plugin_cfg_options = plugin_options.get_cfg_options(); - if (plugin_cfg_options.options().size()) { - app_options.add(plugin_cfg_options); - } - - const options_description& plugin_cli_options = plugin_options.get_cli_options(); - if (plugin_cli_options.options().size()) { - app_options.add(plugin_cli_options); - } - } + template< typename Plugin > + Plugin& get_plugin()const + { + auto ptr = find_plugin< Plugin >(); + if( ptr == nullptr ) + BOOST_THROW_EXCEPTION( std::runtime_error( "unable to find plugin: " + Plugin::name() ) ); + return *ptr; + } - std::shared_ptr new_application( const string& id){ - std::shared_ptr new_app = std::make_shared(id ); - apps[id] = new_app; - for( const auto& pf : plugin_factories){ - auto new_plugin = pf.second->new_plugin(new_app); - new_app->register_plugin(new_plugin); - } - return new_app; - } + std::shared_ptr get_register_plugin( std::string name ){ + if( plugins.count(name) ) + return plugins[name]; + auto new_plugin = app_factory().new_plugin(name); + register_plugin( new_plugin ); + return new_plugin; + } - void add_program_options( const bpo::options_description& cli ); - variables_map read_app_config(string name); - - map> initialize( int argc, char** argv, vector< string > autostart_plugins, bool start_apps = true ); - void set_version_string( const string& version ) { version_info = version; } - - options_description app_options; - options_description global_options; - bfs::path data_dir; - bfs::path plugins_dir; - variables_map global_args; - - void startup(){ - for(auto& app : apps) - app.second->startup(); - }; - - void exec(){ - for(auto& app : apps) - app.second->exec(); - }; - void shutdown(){ - for(auto& app : apps) - app.second->shutdown(); - } - void quit(){ - for(auto& app : apps) - app.second->quit(); - } + template std::shared_ptr get_register_plugin(){ + return get_register_plugin( Plugin::name() ); + } - private: - void set_program_options(); - std::map> plugin_factories; - vector autostart_plugins; - std::map> apps; - string version_info; + void reset(){ + plugins.clear(); + } - application_factory():global_options("Application Options") { - set_program_options(); - }; + bfs::path data_dir()const; + + const bpo::variables_map& get_args() const; + string id; + + boost::asio::io_service& get_io_service() { return *io_serv; } + +protected: + template< typename Impl >friend class plugin; + friend class abstract_plugin; + + abstract_plugin* find_plugin( const string& name )const; + abstract_plugin& get_plugin( const string& name )const; + + /** these notifications get called from the plugin when their state changes so that + * the application can call shutdown in the reverse order. + */ + ///@{ + void plugin_initialized( abstract_plugin& plug ) { initialized_plugins.push_back( &plug ); } + void plugin_started( abstract_plugin& plug ) { running_plugins.push_back( &plug ); } + ///@} + +private: + + map< string, std::shared_ptr< abstract_plugin > > plugins; ///< all registered plugins + vector< abstract_plugin* > initialized_plugins; ///< stored in the order they were started running + vector< abstract_plugin* > running_plugins; ///< stored in the order they were started running + std::shared_ptr< boost::asio::io_service > io_serv; + + std::unique_ptr< class application_impl > my; + +}; - plugin_program_options get_plugin_program_options(std::shared_ptr plugin_factory); - }; - application_factory& app_factory(); } diff --git a/libraries/appbase/include/appbase/plugin.hpp b/libraries/appbase/include/appbase/plugin.hpp index ec54a44c..356453d1 100644 --- a/libraries/appbase/include/appbase/plugin.hpp +++ b/libraries/appbase/include/appbase/plugin.hpp @@ -8,7 +8,7 @@ #include #define APPBASE_PLUGIN_REQUIRES_VISIT( r, visitor, elem ) \ - visitor( ( app()->get_or_create_plugin() ) ); + visitor( *( app()->get_register_plugin() ) ); #define APPBASE_PLUGIN_REQUIRES( PLUGINS ) \ virtual void plugin_for_each_dependency( plugin_processor&& l ) override { \ @@ -25,7 +25,7 @@ using std::map; class application; -class abstract_plugin : std::enable_shared_from_this +class abstract_plugin : public std::enable_shared_from_this { public: enum state { @@ -44,8 +44,8 @@ class abstract_plugin : std::enable_shared_from_this virtual void initialize(const variables_map& options) = 0; virtual void startup() = 0; virtual void shutdown() = 0; - void set_app(std::shared_ptr my_app) { _app = my_app; } - std::shared_ptr app() { return _app; } + void set_app(application& my_app) { _app = &my_app; } + application* app() { return _app; } protected: typedef std::function plugin_processor; @@ -72,7 +72,7 @@ class abstract_plugin : std::enable_shared_from_this void notify_app_initialize(); void notify_app_startup(); private: - std::shared_ptr _app; + application* _app; }; template< typename Impl > @@ -136,7 +136,7 @@ class abstract_plugin_factory { public: virtual ~abstract_plugin_factory(){} - virtual std::shared_ptr new_plugin( std::shared_ptr new_app ) const = 0; + virtual std::shared_ptr new_plugin( ) const = 0; virtual void set_program_options( options_description& cli, options_description& cfg ) = 0; virtual std::string get_name() = 0; }; @@ -147,9 +147,8 @@ class plugin_factory : public abstract_plugin_factory { public: virtual ~plugin_factory(){} - virtual std::shared_ptr new_plugin( std::shared_ptr new_app ) const final { + virtual std::shared_ptr new_plugin( ) const final { std::shared_ptr new_plg = std::make_shared(); - new_plg->set_app( new_app ); return new_plg; } diff --git a/libraries/manifest/gensrc/plugins/CMakeLists.txt b/libraries/manifest/gensrc/plugins/CMakeLists.txt index 1b8f0133..a8b84ed2 100644 --- a/libraries/manifest/gensrc/plugins/CMakeLists.txt +++ b/libraries/manifest/gensrc/plugins/CMakeLists.txt @@ -34,6 +34,8 @@ target_link_libraries( sophiatx_plugins appbase fc account_history_plugin + json_rpc_plugin + chain_plugin debug_node_plugin diff --git a/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp b/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp index ad75c28f..41c2cb1c 100644 --- a/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp +++ b/libraries/plugins/json_rpc/include/sophiatx/plugins/json_rpc/json_rpc_plugin.hpp @@ -123,7 +123,7 @@ namespace detail { class register_api_method_visitor { public: - register_api_method_visitor( const std::string& api_name, std::shared_ptr app ) + register_api_method_visitor( const std::string& api_name, application* app ) : _api_name( api_name ), _json_rpc_plugin( app->get_plugin< sophiatx::plugins::json_rpc::json_rpc_plugin >() ) {} diff --git a/libraries/plugins/json_rpc/plugins.json b/libraries/plugins/json_rpc/plugin.json similarity index 100% rename from libraries/plugins/json_rpc/plugins.json rename to libraries/plugins/json_rpc/plugin.json diff --git a/programs/sophiatxd/main.cpp b/programs/sophiatxd/main.cpp index ec5ffa99..a82aa58c 100644 --- a/programs/sophiatxd/main.cpp +++ b/programs/sophiatxd/main.cpp @@ -79,7 +79,7 @@ int main( int argc, char** argv ) sophiatx::plugins::register_plugins(); appbase::app_factory().set_version_string( version_string() ); - auto initialized = appbase::app_factory().initialize( argc, argv, {"chain_plugin_full", "p2p_plugin", "webserver_plugin"} ); + auto initialized = appbase::app_factory().initialize( argc, argv, {"chain", "p2p", "json_rpc", "webserver"} ); info(); diff --git a/tests/db_fixture/database_fixture.cpp b/tests/db_fixture/database_fixture.cpp index 3cae79d0..0027b002 100644 --- a/tests/db_fixture/database_fixture.cpp +++ b/tests/db_fixture/database_fixture.cpp @@ -57,10 +57,9 @@ clean_database_fixture::clean_database_fixture() appbase::app_factory().register_plugin_factory(); appbase::app_factory().initialize(argc, argv, {"chain", "account_history", "debug_node", "witness"}, false); auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - auto app = w_app.lock(); - auto _db_plugin = app->find_plugin() ; - db_plugin = _db_plugin; + app = &appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + auto _db_plugin = app->get_register_plugin() ; + db_plugin = static_cast(_db_plugin.get()); db_plugin->logging = false; app->initialize(appconfig, {"chain", "account_history", "debug_node", "witness"}); @@ -200,10 +199,9 @@ private_database_fixture::private_database_fixture() appbase::app_factory().register_plugin_factory(); appbase::app_factory().initialize(argc, argv, {"chain", "account_history", "debug_node", "witness"}, false); auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - auto app = w_app.lock(); - auto _db_plugin = app->find_plugin() ; - db_plugin = _db_plugin; + app = &appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + auto _db_plugin = app->get_register_plugin() ; + db_plugin = static_cast(_db_plugin.get()); db_plugin->logging = false; app->initialize(appconfig, {"chain", "account_history", "debug_node", "witness"}); @@ -287,10 +285,9 @@ live_database_fixture::live_database_fixture() appbase::app_factory().register_plugin_factory(); auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - auto app = w_app.lock(); - db_plugin = app->find_plugin() ; - db_plugin->logging = false; + app = &appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + auto _db_plugin = app->get_register_plugin() ; + db_plugin = static_cast(_db_plugin.get()); app->initialize(appconfig, {"chain", "account_history_", "debug_node"}); db = std::static_pointer_cast(app->get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); @@ -712,12 +709,12 @@ json_rpc_database_fixture::json_rpc_database_fixture() auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - auto app = w_app.lock(); + app = &appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - db_plugin = app->find_plugin() ; - db_plugin->logging = false; - rpc_plugin = app->find_plugin() ; + auto _db_plugin = app->get_register_plugin() ; + db_plugin = static_cast(_db_plugin.get()); + auto _rpc_plugin = app->get_register_plugin() ; + rpc_plugin = static_cast(_rpc_plugin.get()); app->initialize(appconfig, {"chain", "account_history", "debug_node", "witness","json_rpc", "block_api", "database_api", "witness_api", "alexandria_api"}); app->get_plugin< sophiatx::plugins::alexandria_api::alexandria_api_plugin >().plugin_startup(); diff --git a/tests/db_fixture/database_fixture.hpp b/tests/db_fixture/database_fixture.hpp index 4a53fa64..ce56eeb0 100644 --- a/tests/db_fixture/database_fixture.hpp +++ b/tests/db_fixture/database_fixture.hpp @@ -194,12 +194,12 @@ struct database_fixture { fc::ecc::canonical_signature_type default_sig_canon = fc::ecc::fc_canonical; sophiatx::plugins::debug_node::debug_node_plugin* db_plugin; - std::weak_ptr w_app; + appbase::application* app; optional data_dir; database_fixture() {} - virtual ~database_fixture() { auto app = w_app.lock(); app.reset(); } + virtual ~database_fixture() { } static fc::ecc::private_key generate_private_key( string seed = "init_key" ); static asset_symbol_type name_to_asset_symbol( const std::string& name, uint8_t decimal_places ); diff --git a/tests/tests/block_tests.cpp b/tests/tests/block_tests.cpp index a291dad4..e87ca302 100644 --- a/tests/tests/block_tests.cpp +++ b/tests/tests/block_tests.cpp @@ -751,14 +751,14 @@ BOOST_FIXTURE_TEST_CASE( hardfork_test, database_fixture ) appbase::app_factory().register_plugin_factory(); appbase::app_factory().register_plugin_factory(); appbase::app_factory().register_plugin_factory(); - appbase::app_factory().initialize(argc, argv, {"chain", "account_history", "debug_node", "witness"}, false); + appbase::app_factory().initialize(argc, argv, {"chain", "account_history", "debug_node"}, false); auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - w_app = appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); - auto app = w_app.lock(); - auto _db_plugin = app->find_plugin() ; - db_plugin = _db_plugin; + app = &appbase::app_factory().new_application("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); + auto _db_plugin = app->get_register_plugin() ; + db_plugin = static_cast(_db_plugin.get()); app->initialize(appconfig, {"chain", "account_history", "debug_node"}); + db = std::static_pointer_cast(app->get_plugin< sophiatx::plugins::chain::chain_plugin >().db()); BOOST_REQUIRE( db ); From 200bddc64cc88669c053b70a42243d4d38d7172e Mon Sep 17 00:00:00 2001 From: ejossev Date: Fri, 1 Feb 2019 12:20:57 +0100 Subject: [PATCH 13/17] test fix --- tests/db_fixture/database_fixture.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/db_fixture/database_fixture.cpp b/tests/db_fixture/database_fixture.cpp index 0027b002..cd8a0fff 100644 --- a/tests/db_fixture/database_fixture.cpp +++ b/tests/db_fixture/database_fixture.cpp @@ -706,6 +706,7 @@ json_rpc_database_fixture::json_rpc_database_fixture() appbase::app_factory().register_plugin_factory(); appbase::app_factory().register_plugin_factory(); appbase::app_factory().register_plugin_factory(); + appbase::app_factory().initialize(argc, argv, {"chain", "account_history", "debug_node", "witness","json_rpc", "block_api", "database_api", "witness_api", "alexandria_api"}, false); auto appconfig = appbase::app_factory().read_app_config("1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"); From eb9ab73e05859523880a5cc912d35a06f1e66638 Mon Sep 17 00:00:00 2001 From: ejossev Date: Mon, 4 Feb 2019 16:06:51 +0100 Subject: [PATCH 14/17] review fixes --- CMakeLists.txt | 6 +++--- libraries/appbase/CMakeLists.txt | 9 +++++---- libraries/appbase/application.cpp | 6 +++--- libraries/appbase/include/appbase/application.hpp | 6 +++--- libraries/appbase/include/appbase/plugin.hpp | 2 +- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a17bc8bb..6beecea9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -207,7 +207,7 @@ if( WIN32 ) ADD_DEFINITIONS("-DBOOST_ALL_NO_LIB") elseif( MINGW ) - SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fpermissive -msse4.2 -Wa,-mbig-obj") + SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fpermissive -msse4.2 -Wa,-mbig-obj") SET(CMAKE_CXX_FLAGS_RELEASE "-O3") # Optimization flag apparently needed to get rid of "File too big" assembler errors when compiling in Debug mode # See: https://stackoverflow.com/questions/14125007/gcc-string-table-overflow-error-during-compilation/14601779#29479701 @@ -222,11 +222,11 @@ else( WIN32 ) # Apple AND Linux if( APPLE ) # Apple Specific Options Here message( STATUS "Configuring SophiaTX on OS X" ) - set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -stdlib=libc++ -Wall -Wno-conversion -Wno-deprecated-declarations" ) + set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -stdlib=libc++ -Wall -Wno-conversion -Wno-deprecated-declarations" ) else( APPLE ) # Linux Specific Options Here message( STATUS "Configuring SophiaTX on Linux" ) - set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++11 -Wall" ) + set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall" ) set( rt_library rt ) set( pthread_library pthread) set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") diff --git a/libraries/appbase/CMakeLists.txt b/libraries/appbase/CMakeLists.txt index a5f03b3e..db505b4e 100644 --- a/libraries/appbase/CMakeLists.txt +++ b/libraries/appbase/CMakeLists.txt @@ -18,20 +18,20 @@ LIST(APPEND BOOST_COMPONENTS thread FIND_PACKAGE(Boost 1.58 REQUIRED COMPONENTS ${BOOST_COMPONENTS}) set( Boost_USE_STATIC_LIBS ON CACHE STRING "ON or OFF" ) -if( APPLE ) +#[[if( APPLE ) # Apple Specific Options Here message( STATUS "Configuring AppBase on OS X" ) - set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++17 -stdlib=libc++ -Wall -Wno-conversion -Wno-deprecated-declarations" ) + set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -stdlib=libc++ -Wall -Wno-conversion -Wno-deprecated-declarations" ) else( APPLE ) # Linux Specific Options Here message( STATUS "Configuring AppBase on Linux" ) - set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -std=c++17 -Wall -pthread" ) + set( CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -Wall -pthread" ) set( rt_library rt ) set( pthread_library pthread) if ( SOPHIATX_STATIC_BUILD ) set( CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc") endif ( SOPHIATX_STATIC_BUILD ) -endif( APPLE ) +endif( APPLE )]] if(ENABLE_COVERAGE_TESTING) @@ -44,6 +44,7 @@ add_library( appbase ) target_link_libraries( appbase fc ${Boost_LIBRARIES}) +set_property(TARGET appbase PROPERTY CXX_STANDARD 17) target_include_directories( appbase PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/include" ${Boost_INCLUDE_DIR}) diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index 49cfba14..7a4cf9ae 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -140,7 +140,7 @@ void application::startup() { plugin->startup(); } -plugin_program_options application_factory::get_plugin_program_options(std::shared_ptr plugin_factory) { +plugin_program_options application_factory::get_plugin_program_options(const std::shared_ptr& plugin_factory) { options_description plugin_cli_opts("Command Line Options for " + plugin_factory->get_name()); options_description plugin_cfg_opts("Config Options for " + plugin_factory->get_name()); plugin_factory->set_program_options(plugin_cli_opts, plugin_cfg_opts); @@ -357,7 +357,7 @@ void application_factory::set_program_options() global_options.add(app_cli_opts); } -map application_factory::initialize( int argc, char** argv, vector< string > _autostart_plugins, bool start_apps ) +map application_factory::initialize( int argc, char** argv, const vector< string >& _autostart_plugins, bool start_apps ) { try { @@ -463,7 +463,7 @@ application& application_factory::new_application( const string& id){ return apps.at(id); } -variables_map application_factory::read_app_config(std::string name) +variables_map application_factory::read_app_config(const std::string& name) { bfs::path config_file_path = write_default_config(app_options, global_args[ "config" ].as(), name); diff --git a/libraries/appbase/include/appbase/application.hpp b/libraries/appbase/include/appbase/application.hpp index b6dcb1bf..b50a45b2 100644 --- a/libraries/appbase/include/appbase/application.hpp +++ b/libraries/appbase/include/appbase/application.hpp @@ -79,9 +79,9 @@ class application_factory } void add_program_options( const bpo::options_description& cli ); - variables_map read_app_config(string name); + variables_map read_app_config(const string& name); - map initialize( int argc, char** argv, vector< string > autostart_plugins, bool start_apps = true ); + map initialize( int argc, char** argv, const vector< string >& autostart_plugins, bool start_apps = true ); void set_version_string( const string& version ) { version_info = version; } options_description app_options; @@ -107,7 +107,7 @@ class application_factory }; - plugin_program_options get_plugin_program_options(std::shared_ptr plugin_factory); + plugin_program_options get_plugin_program_options(const std::shared_ptr& plugin_factory); }; application_factory& app_factory(); diff --git a/libraries/appbase/include/appbase/plugin.hpp b/libraries/appbase/include/appbase/plugin.hpp index 356453d1..ed1b32a0 100644 --- a/libraries/appbase/include/appbase/plugin.hpp +++ b/libraries/appbase/include/appbase/plugin.hpp @@ -48,7 +48,7 @@ class abstract_plugin : public std::enable_shared_from_this application* app() { return _app; } protected: - typedef std::function plugin_processor; + using plugin_processor = std::function; /** Abstract method to be reimplemented in final plugin implementation. It is a part of initialization/startup process triggerred by main application. From 7f5fcabcfcdd5846e70e7312df0dd21bd54029ab Mon Sep 17 00:00:00 2001 From: ejossev Date: Wed, 6 Feb 2019 16:58:53 +0100 Subject: [PATCH 15/17] config migration --- libraries/appbase/application.cpp | 106 +++++++++++++++--- libraries/plugins/chain/chain_plugin_lite.cpp | 2 +- .../multiparty_messaging_plugin.cpp | 4 +- 3 files changed, 95 insertions(+), 17 deletions(-) diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index 7a4cf9ae..b3c6bd26 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -9,7 +9,7 @@ #include #include - +#include namespace appbase { @@ -19,6 +19,9 @@ using bpo::variables_map; using std::cout; namespace{ +const static string _public_net_id = "mainnet"; + + // TODO: delete after HF2 /** * @brief Fix which renames default data directory and also moves config into subdirectory configs, so users do not need to do it themselves @@ -28,7 +31,7 @@ namespace{ * @param cfg_data_dir * @param cfg_config */ -/*void fix_deprecated_data_folder_structure(const bfs::path& actual_data_dir, +void fix_deprecated_data_folder_structure(const bfs::path& actual_data_dir, const boost::program_options::variable_value& cfg_data_dir, const boost::program_options::variable_value& cfg_config) { @@ -56,15 +59,87 @@ namespace{ bfs::rename(deprecated_default_config_path, configs_dir / cfg_config.as()); } } -}*/ +} + +void migrate_configs( const bfs::path& cfg_file, const string chain_suffix, + const options_description& global_options_desc, const options_description& chain_options_desc) +{ + bfs::path config_file_name = app_factory().data_dir / "configs" / cfg_file; + + if( cfg_file.is_absolute() == true ) { + config_file_name = cfg_file; + } + + bfs::path chain_config_file_name = config_file_name; + bfs::path temp_config_file_name = config_file_name; + chain_config_file_name += std::string(".") + chain_suffix; + temp_config_file_name += std::string(".backup"); + + if( ! bfs::exists(config_file_name) || bfs::exists(chain_config_file_name) ) + return; + + bfs::copy_file(config_file_name, temp_config_file_name, bfs::copy_option::overwrite_if_exists ); + + std::ifstream infile(temp_config_file_name.make_preferred().string().c_str()); + std::ofstream outfile(config_file_name.make_preferred().string().c_str()); + std::ofstream chainfile(chain_config_file_name.make_preferred().string().c_str()); + + std::string line; + while (std::getline(infile, line)) + { + while( line.size() && isspace(line[0])) + line = line.substr(1); + if(line.size() == 0 ){ + outfile << '\n'; + chainfile << '\n'; + continue; + } + + if( line[0] == '#' ){ + outfile << line <<'\n'; + chainfile << line <<'\n'; + continue; + } + + int epos = line.find( '=' ); + if( epos == string::npos ){//huh? + outfile << line <<'\n'; + chainfile << line <<'\n'; + continue; + } + + string key = line.substr(0, epos ); + string value = line.substr( epos + 1); + boost::algorithm::trim(key); + boost::algorithm::trim(value); + + if(global_options_desc.find_nothrow(key, false)){ + outfile << line <<'\n'; + chainfile << "# This option is not used in chain config\n# " <description() <<"\n"; + outfile << global_options_desc.find_nothrow("startup-apps", false)->long_name() << " = " << _public_net_id <<"\n"; + + outfile.close(); + chainfile.close(); +} + + /** - * @brief Writes options_desc data into cfg_file file - * - * @param options_desc - * @param cfg_file - * @return created config file absolute path - */ + * @brief Writes options_desc data into cfg_file file + * + * @param options_desc + * @param cfg_file + * @return created config file absolute path + */ bfs::path write_default_config( const options_description& options_desc, const bfs::path& cfg_file, std::string suffix = "" ) { bfs::path _cfg_file = cfg_file; if( suffix != "" ){ @@ -112,7 +187,6 @@ bfs::path write_default_config( const options_description& options_desc, const b return config_file_name; } -const static string _public_net_chain_id = "1a058d1a89aff240ab203abe8a429d1a1699c339032a87e70e01022842a98324"; } @@ -398,6 +472,10 @@ map application_factory::initialize( int argc, char** arg // config par (even if it is default) must be always present assert(global_args.count( "config" )); + //Migrate the config here + fix_deprecated_data_folder_structure(data_dir, global_args["data-dir"], global_args["config"]); + migrate_configs(global_args["config"].as(), _public_net_id, global_options, app_options); + // Writes config if it does not already exists bfs::path config_file_path = write_default_config(global_options, global_args["config"].as()); @@ -405,7 +483,7 @@ map application_factory::initialize( int argc, char** arg bpo::store(bpo::parse_config_file< char >( config_file_path.make_preferred().string().c_str(), global_options, true ), global_args ); - //TODO: migrate the config here + if(start_apps) { if( global_args.count("startup-apps") > 0 ) { @@ -422,10 +500,10 @@ map application_factory::initialize( int argc, char** arg } } else { //load default (public) one. - variables_map app_args = read_app_config(_public_net_chain_id); - auto& new_app = new_application(_public_net_chain_id); + variables_map app_args = read_app_config(_public_net_id); + auto& new_app = new_application(_public_net_id); new_app.initialize(app_args, autostart_plugins); - ret.emplace(_public_net_chain_id, new_app); + ret.emplace(_public_net_id, new_app); } } return ret; diff --git a/libraries/plugins/chain/chain_plugin_lite.cpp b/libraries/plugins/chain/chain_plugin_lite.cpp index d5588428..9592dc3c 100644 --- a/libraries/plugins/chain/chain_plugin_lite.cpp +++ b/libraries/plugins/chain/chain_plugin_lite.cpp @@ -25,7 +25,7 @@ void chain_plugin_lite::set_program_options(options_description &cli, options_de cfg.add_options() ("server-rpc-endpoint", bpo::value()->default_value("ws://127.0.0.1:9191"), "Server websocket RPC endpoint") - ("app-id", bpo::value()->default_value(1), + ("app-id", bpo::value()->default_value(1), "App id used by the hybrid DB") ("shared-file-dir", bpo::value()->default_value("blockchain"), "the location of the chain shared memory files (absolute path or relative to application data dir)") diff --git a/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp b/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp index 47fdc58f..2ccc5e3e 100644 --- a/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp +++ b/libraries/plugins/multiparty_messaging/multiparty_messaging_plugin.cpp @@ -208,7 +208,7 @@ multiparty_messaging_plugin::multiparty_messaging_plugin() {} void multiparty_messaging_plugin::set_program_options( options_description& cli, options_description& cfg ) { cfg.add_options() - ("mpm-app-id", boost::program_options::value< long long >()->default_value( 2 ), "App id used by the multiparty messaging" ) + ("mpm-app-id", boost::program_options::value< uint64_t >()->default_value( 2 ), "App id used by the multiparty messaging" ) ("mpm-account", boost::program_options::value>()->composing()->multitoken(), "Accounts tracked by the plugin. If not specified, tries to listen to all messages within the given app ID") ("mpm-private-key", bpo::value>()->composing()->multitoken(), "WIF MEMO PRIVATE KEY to be used by one or more tracked accounts" ) ; @@ -217,7 +217,7 @@ void multiparty_messaging_plugin::set_program_options( options_description& cli, void multiparty_messaging_plugin::plugin_initialize( const boost::program_options::variables_map& options ) { if( options.count( "mpm-app-id" ) ){ - app_id = options[ "mpm-app-id" ].as< long long >(); + app_id = options[ "mpm-app-id" ].as< uint64_t >(); }else{ ilog("App ID not given, multiparty messaging is disabled"); return; From e496d3213824eec8e54ebc0d687e7c078bfde34d Mon Sep 17 00:00:00 2001 From: ejossev Date: Thu, 7 Feb 2019 11:18:32 +0100 Subject: [PATCH 16/17] gcc compilation fix --- libraries/appbase/application.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/appbase/application.cpp b/libraries/appbase/application.cpp index b3c6bd26..b373a824 100644 --- a/libraries/appbase/application.cpp +++ b/libraries/appbase/application.cpp @@ -101,7 +101,7 @@ void migrate_configs( const bfs::path& cfg_file, const string chain_suffix, continue; } - int epos = line.find( '=' ); + auto epos = line.find( '=' ); if( epos == string::npos ){//huh? outfile << line <<'\n'; chainfile << line <<'\n'; From d01d7b5418d3c1a8ad25c293f1c0f256bf5d7c92 Mon Sep 17 00:00:00 2001 From: ejossev Date: Fri, 8 Feb 2019 10:39:32 +0100 Subject: [PATCH 17/17] plugin options cleanup --- libraries/appbase/include/appbase/application.hpp | 2 +- libraries/plugins/chain/chain_plugin_full.cpp | 11 ++++------- libraries/plugins/chain/chain_plugin_lite.cpp | 3 +-- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/libraries/appbase/include/appbase/application.hpp b/libraries/appbase/include/appbase/application.hpp index b50a45b2..046d6138 100644 --- a/libraries/appbase/include/appbase/application.hpp +++ b/libraries/appbase/include/appbase/application.hpp @@ -61,7 +61,7 @@ class application_factory const options_description& plugin_cli_options = plugin_options.get_cli_options(); if (plugin_cli_options.options().size()) { - app_options.add(plugin_cli_options); + global_options.add(plugin_cli_options); } } diff --git a/libraries/plugins/chain/chain_plugin_full.cpp b/libraries/plugins/chain/chain_plugin_full.cpp index eb38ef28..a4828d31 100644 --- a/libraries/plugins/chain/chain_plugin_full.cpp +++ b/libraries/plugins/chain/chain_plugin_full.cpp @@ -225,18 +225,15 @@ void chain_plugin_full::set_program_options(options_description& cli, options_de ("checkpoint,c", bpo::value>()->composing(), "Pairs of [BLOCK_NUM,BLOCK_ID] that should be enforced as checkpoints.") ("flush-state-interval", bpo::value(), "flush shared memory changes to disk every N blocks") + ("check-locks", bpo::bool_switch()->default_value(false), "Check correctness of chainbase locking" ) + ("validate-database-invariants", bpo::bool_switch()->default_value(false), "Validate all supply invariants check out" ) ("initminer-mining-pubkey", bpo::value(), "initminer public key for mining. Used only for private nets.") ("initminer-account-pubkey", bpo::value(), "initminer public key for account operations. Used only for private nets.") - ; - cli.add_options() + ("set-benchmark-interval", bpo::value(), "Print time and memory usage every given number of blocks") + ("dump-memory-details", bpo::bool_switch()->default_value(false), "Dump database objects memory usage info. Use set-benchmark-interval to set dump interval.") ("replay-blockchain", bpo::bool_switch()->default_value(false), "clear chain database and replay all blocks" ) ("resync-blockchain", bpo::bool_switch()->default_value(false), "clear chain database and block log" ) ("stop-replay-at-block", bpo::value(), "Stop and exit after reaching given block number") - ("set-benchmark-interval", bpo::value(), "Print time and memory usage every given number of blocks") - ("dump-memory-details", bpo::bool_switch()->default_value(false), "Dump database objects memory usage info. Use set-benchmark-interval to set dump interval.") - ("check-locks", bpo::bool_switch()->default_value(false), "Check correctness of chainbase locking" ) - ("validate-database-invariants", bpo::bool_switch()->default_value(false), "Validate all supply invariants check out" ) - ; } diff --git a/libraries/plugins/chain/chain_plugin_lite.cpp b/libraries/plugins/chain/chain_plugin_lite.cpp index 9592dc3c..506a6b04 100644 --- a/libraries/plugins/chain/chain_plugin_lite.cpp +++ b/libraries/plugins/chain/chain_plugin_lite.cpp @@ -33,8 +33,7 @@ void chain_plugin_lite::set_program_options(options_description &cli, options_de ("shared-file-full-threshold", bpo::value()->default_value(0), "A 2 precision percentage (0-10000) that defines the threshold for when to autoscale the shared memory file. Setting this to 0 disables autoscaling. Recommended value for consensus node is 9500 (95%). Full node is 9900 (99%)") ("shared-file-scale-rate", bpo::value()->default_value(0), - "A 2 precision percentage (0-10000) that defines how quickly to scale the shared memory file. When autoscaling occurs the file's size will be increased by this percent. Setting this to 0 disables autoscaling. Recommended value is between 1000-2000 (10-20%)"); - cli.add_options() + "A 2 precision percentage (0-10000) that defines how quickly to scale the shared memory file. When autoscaling occurs the file's size will be increased by this percent. Setting this to 0 disables autoscaling. Recommended value is between 1000-2000 (10-20%)") ("resync-blockchain", bpo::bool_switch()->default_value(false), "clear chain database and block log"); }