github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/cmd/dummy_neb/dummy_driver.h (about)

     1  // Copyright (C) 2018 go-nebulas authors
     2  //
     3  // This file is part of the go-nebulas library.
     4  //
     5  // the go-nebulas library is free software: you can redistribute it and/or
     6  // modify
     7  // it under the terms of the GNU General Public License as published by
     8  // the Free Software Foundation, either version 3 of the License, or
     9  // (at your option) any later version.
    10  //
    11  // the go-nebulas library is distributed in the hope that it will be useful,
    12  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    14  // GNU General Public License for more details.
    15  //
    16  // You should have received a copy of the GNU General Public License
    17  // along with the go-nebulas library.  If not, see
    18  // <http://www.gnu.org/licenses/>.
    19  //
    20  #include "cmd/dummy_neb/dummies/dummies.h"
    21  #include "cmd/dummy_neb/dummy_common.h"
    22  #include "cmd/dummy_neb/generator/generators.h"
    23  #include "util/timer_loop.h"
    24  
    25  class dummy_driver {
    26  public:
    27    dummy_driver();
    28    ~dummy_driver();
    29    void add_dummy(const std::shared_ptr<dummy_base> &dummy);
    30    std::vector<std::string> get_all_dummy_names() const;
    31  
    32    std::shared_ptr<dummy_base>
    33    get_dummy_with_name(const std::string &dummy_name) const;
    34  
    35    void run(const std::string &dummy_name, uint64_t block_interval_seconds);
    36    void shutdown();
    37  
    38    void check_all_dummy_tasks(const std::string &dummy_name);
    39    void check_dummy_task(const std::string &dummy_name,
    40                          const std::string &task_name);
    41  
    42    void reset_dummy(const std::string &dummy_name);
    43  
    44  protected:
    45    boost::asio::io_service m_io_service;
    46    std::unordered_map<std::string, std::shared_ptr<dummy_base>> m_all_dummies;
    47    std::unique_ptr<neb::util::timer_loop> m_block_gen_timer;
    48    std::unique_ptr<neb::util::timer_loop> m_checker_gen_timer;
    49    uint64_t m_block_interval_seconds;
    50  };