/* * Copyright (c) 2015, Cryptonomex, Inc. * All rights reserved. * * This source code is provided for evaluation in private test networks only, until September 8, 2015. After this date, this license expires and * the code may not be used, modified or distributed for any purpose. Redistribution and use in source and binary forms, with or without modification, * are permitted until September 8, 2015, provided that the following conditions are met: * * 1. The code and/or derivative works are used only for private test networks consisting of no more than 10 P2P nodes. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #pragma once #include #include #include namespace graphene { namespace app { namespace detail { class application_impl; } namespace bpo = boost::program_options; using std::string; class abstract_plugin; class application { public: application(); ~application(); void set_program_options( bpo::options_description& command_line_options, bpo::options_description& configuration_file_options )const; void initialize(const fc::path& data_dir, const bpo::variables_map&options); void initialize_plugins( const bpo::variables_map& options ); void startup(); void shutdown(); void startup_plugins(); void shutdown_plugins(); template std::shared_ptr register_plugin() { auto plug = std::make_shared(); plug->plugin_set_app(this); bpo::options_description plugin_cli_options("Options for plugin " + plug->plugin_name()), plugin_cfg_options; plug->plugin_set_program_options(plugin_cli_options, plugin_cfg_options); if( !plugin_cli_options.options().empty() ) _cli_options.add(plugin_cli_options); if( !plugin_cfg_options.options().empty() ) _cfg_options.add(plugin_cfg_options); add_plugin( plug->plugin_name(), plug ); return plug; } std::shared_ptr get_plugin( const string& name )const; template std::shared_ptr get_plugin( const string& name ) const { std::shared_ptr abs_plugin = get_plugin( name ); std::shared_ptr result = std::dynamic_pointer_cast( abs_plugin ); FC_ASSERT( result != std::shared_ptr() ); return result; } net::node_ptr p2p_node(); std::shared_ptr chain_database()const; void set_block_production(bool producing_blocks); private: void add_plugin( const string& name, std::shared_ptr p ); std::shared_ptr my; bpo::options_description _cli_options; bpo::options_description _cfg_options; }; } }