github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/core/neb_ipc/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 "common/timer_loop.h"
    25  #include "core/neb_ipc/client/ipc_client_endpoint.h"
    26  #include "core/neb_ipc/ipc_pkg.h"
    27  #include "fs/util.h"
    28  #include <atomic>
    29  
    30  namespace neb {
    31  namespace core {
    32  namespace internal {
    33  class driver_base {
    34  
    35  public:
    36    driver_base();
    37  
    38    virtual bool init();
    39  
    40    virtual void run();
    41  
    42    ipc_client_t *ipc_conn() { return m_ipc_conn; }
    43  
    44  protected:
    45    virtual void add_handlers() = 0;
    46  
    47    void handle_exception(const std::shared_ptr<neb::neb_exception> &p);
    48  
    49    void init_timer_thread();
    50  
    51    void init_nbre();
    52  
    53  protected:
    54    std::unique_ptr<ipc_client_endpoint> m_client;
    55    ipc_client_t *m_ipc_conn;
    56    std::unique_ptr<std::thread> m_client_thread;
    57    std::atomic_bool m_exit_flag;
    58    std::unique_ptr<std::thread> m_timer_thread;
    59    std::unique_ptr<timer_loop> m_timer_loop;
    60  };
    61  } // end namespace internal
    62  
    63  class driver : public internal::driver_base {
    64  public:
    65    driver();
    66  
    67  protected:
    68    virtual void add_handlers();
    69  };
    70  }
    71  }