github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/test/core/neb_ipc/simple/client.cpp (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 "common/common.h"
    21  #include "common/configuration.h"
    22  #include "core/driver.h"
    23  #include "core/ir_warden.h"
    24  #include "core/neb_ipc/ipc_interface.h"
    25  #include "core/neb_ipc/server/ipc_server_endpoint.h"
    26  #include "fs/util.h"
    27  #include <ff/functionflow.h>
    28  
    29  class simple_driver : public neb::core::internal::driver_base {
    30  public:
    31    virtual void add_handlers() {
    32      m_client->add_handler<neb::core::ipc_pkg::nbre_version_req>(
    33          [this](neb::core::ipc_pkg::nbre_version_req *req) {
    34            ff::para<void> p;
    35            p([req, this]() {
    36              LOG(INFO) << " to start jit driver for data";
    37              using mi = neb::core::pkg_type_to_module_info<
    38                  neb::core::ipc_pkg::nbre_version_req>;
    39  
    40              neb::core::ipc_pkg::nbre_version_ack *ack =
    41                  m_ipc_conn->construct<neb::core::ipc_pkg::nbre_version_ack>(
    42                      req->m_holder, m_ipc_conn->default_allocator());
    43              ack->set<neb::core::ipc_pkg::major>(1);
    44              ack->set<neb::core::ipc_pkg::minor>(1);
    45              ack->set<neb::core::ipc_pkg::patch>(1);
    46              m_ipc_conn->push_back(ack);
    47            });
    48          });
    49  
    50      m_client->add_handler<neb::core::ipc_pkg::nbre_init_ack>(
    51          [](neb::core::ipc_pkg::nbre_init_ack *ack) {
    52            std::string s =
    53                ack->get<neb::core::ipc_pkg::admin_pub_addr>().c_str();
    54            LOG(INFO) << "got admin_pub_addr: " << s;
    55            neb::configuration::instance().admin_pub_addr() = s;
    56          });
    57    }
    58  };
    59  
    60  int main(int argc, char *argv[]) {
    61    FLAGS_logtostderr = true;
    62  
    63    ::google::InitGoogleLogging(argv[0]);
    64    neb::program_name = "nbre";
    65  
    66    simple_driver d;
    67    d.init();
    68    d.run();
    69    LOG(INFO) << "to quit nbre";
    70  
    71    return 0;
    72  }