github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/core/net_ipc/client/client_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  #pragma once
    21  #include "common/common.h"
    22  #include "common/configuration.h"
    23  #include "common/exception_queue.h"
    24  #include "core/net_ipc/client/nipc_client.h"
    25  #include "core/net_ipc/nipc_pkg.h"
    26  #include "fs/util.h"
    27  #include "util/timer_loop.h"
    28  
    29  namespace neb {
    30  namespace core {
    31  namespace internal {
    32  class client_driver_base {
    33  
    34  public:
    35    client_driver_base();
    36    virtual ~client_driver_base();
    37  
    38    virtual bool init();
    39  
    40    virtual void run();
    41  
    42  protected:
    43    virtual void add_handlers() = 0;
    44  
    45    void handle_exception(const std::shared_ptr<neb::neb_exception> &p);
    46  
    47    void init_timer_thread();
    48  
    49    void init_nbre();
    50  
    51  protected:
    52    std::unique_ptr<nipc_client> m_client;
    53    ::ff::net::tcp_connection_base_ptr m_ipc_conn;
    54    std::atomic_bool m_exit_flag;
    55    std::unique_ptr<std::thread> m_timer_thread;
    56    std::unique_ptr<util::timer_loop> m_timer_loop;
    57  };
    58  } // end namespace internal
    59  
    60  class client_driver : public internal::client_driver_base {
    61  public:
    62    client_driver();
    63    virtual ~client_driver();
    64  
    65  protected:
    66    virtual void add_handlers();
    67  };
    68  } // namespace core
    69  } // namespace neb