github.com/igggame/nebulas-go@v2.1.0+incompatible/nbre/core/net_ipc/nipc_pkg.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 <ff/network.h>
    22  
    23  enum ipc_pkg_type {
    24    heart_beat_pkg,
    25  #define define_ipc_param(type, name)
    26  
    27  #define define_ipc_pkg(type, ...) JOIN(type, _pkg),
    28  
    29  #define define_ipc_api(req, ack)
    30  
    31  #include "core/net_ipc/ipc_interface_impl.h"
    32  
    33  #undef define_ipc_api
    34  #undef define_ipc_pkg
    35  #undef define_ipc_param
    36    nipc_last_pkg_id,
    37  };
    38  
    39  typedef ::ff::net::ntpackage<heart_beat_pkg> heart_beat_t;
    40  
    41  #define define_ipc_param(type, name) define_nt(name, type);
    42  
    43  #define define_ipc_pkg(type, ...)                                              \
    44    typedef ::ff::net::ntpackage<JOIN(type, _pkg), __VA_ARGS__> type;
    45  
    46  #define define_ipc_api(req, ack)
    47  
    48  #include "core/net_ipc/ipc_interface_impl.h"
    49  
    50  #undef define_ipc_api
    51  #undef define_ipc_pkg
    52  #undef define_ipc_param
    53  
    54  namespace neb {
    55  namespace core {
    56  template <typename PkgType1, typename PkgType2>
    57  std::shared_ptr<PkgType1> new_ack_pkg(PkgType2 req) {
    58    auto ack = std::make_shared<PkgType1>();
    59    ack->template set<p_holder>(req->template get<p_holder>());
    60    return ack;
    61  }
    62  
    63  std::string pkg_type_id_to_name(uint64_t type);
    64  bool is_pkg_type_has_callback(uint64_t type);
    65  
    66  template <typename T> struct get_pkg_ack_type { typedef T type; };
    67  #define define_ipc_param(type, name)
    68  #define define_ipc_pkg(type, ...)
    69  
    70  #define define_ipc_api(req, ack)                                               \
    71    template <> struct get_pkg_ack_type<req> { typedef ack type; };
    72  
    73  #include "core/net_ipc/ipc_interface_impl.h"
    74  
    75  #undef define_ipc_api
    76  #undef define_ipc_pkg
    77  #undef define_ipc_param
    78  
    79  } // namespace core
    80  } // namespace neb