Verified Commit 88d23c2b authored by Alberto Miranda's avatar Alberto Miranda ♨️
Browse files

scord_ctl: Update RPCs to mochi-thalium

parent ad78f509
Loading
Loading
Loading
Loading
+14 −21
Original line number Diff line number Diff line
@@ -23,8 +23,7 @@
 *****************************************************************************/

#include <logger/logger.hpp>
#include <net/proto/rpc_types.h>
#include <net/engine.hpp>
#include <net/request.hpp>
#include "rpc_handlers.hpp"

struct remote_procedure {
@@ -35,35 +34,29 @@ struct remote_procedure {
    }
};

static void
ADM_ping(hg_handle_t h) {
namespace scord::network::handlers {

    using scord::network::utils::get_address;
void
ping(const scord::network::request& req) {

    [[maybe_unused]] hg_return_t ret;
    using scord::network::generic_response;
    using scord::network::get_address;

    [[maybe_unused]] margo_instance_id mid = margo_hg_handle_get_instance(h);

    const auto id = remote_procedure::new_id();
    const auto rpc_id = remote_procedure::new_id();

    LOGGER_INFO("rpc id: {} name: {} from: {} => "
                "body: {{}}",
                id, std::quoted(__FUNCTION__), std::quoted(get_address(h)));
                rpc_id, std::quoted(__FUNCTION__),
                std::quoted(get_address(req)));

    ADM_ping_out_t out;
    out.op_id = id;
    out.retval = ADM_SUCCESS;
    const auto resp = generic_response{rpc_id, admire::error_code::success};

    LOGGER_INFO("rpc id: {} name: {} to: {} <= "
                "body: {{retval: {}}}",
                id, std::quoted(__FUNCTION__), std::quoted(get_address(h)),
                ADM_SUCCESS);

    ret = margo_respond(h, &out);
    assert(ret == HG_SUCCESS);
                rpc_id, std::quoted(__FUNCTION__),
                std::quoted(get_address(req)), admire::error_code::success);

    ret = margo_destroy(h);
    assert(ret == HG_SUCCESS);
    req.respond(resp);
}

DEFINE_MARGO_RPC_HANDLER(ADM_ping);
} // namespace scord::network::handlers
+7 −8
Original line number Diff line number Diff line
@@ -25,16 +25,15 @@
#ifndef SCORD_CTL_RPC_HANDLERS_HPP
#define SCORD_CTL_RPC_HANDLERS_HPP

#include <margo.h>
#include <net/request.hpp>
#include <net/serialization.hpp>
#include <admire_types.hpp>

#ifdef __cplusplus
extern "C" {
#endif
namespace scord::network::handlers {

DECLARE_MARGO_RPC_HANDLER(ADM_ping);
void
ping(const scord::network::request& req);

#ifdef __cplusplus
};
#endif
} // namespace scord::network::handlers

#endif // SCORD_CTL_RPC_HANDLERS_HPP
+6 −9
Original line number Diff line number Diff line
@@ -33,13 +33,13 @@

#include <version.hpp>
#include <net/server.hpp>
#include <net/proto/rpc_types.h>
#include <config/settings.hpp>
#include "rpc_handlers.hpp"
#include "env.hpp"

namespace fs = std::filesystem;
namespace bpo = boost::program_options;
using namespace std::literals;

void
print_version(const std::string& progname) {
@@ -178,17 +178,14 @@ main(int argc, char* argv[]) {
    try {
        scord::network::server daemon(cfg);

#if 0
        const auto rpc_registration_cb = [](auto&& ctx) {
            LOGGER_INFO(" * Registering RPCs handlers...");
// convenience macro to ensure the names of an RPC and its handler
// always match
#define EXPAND(rpc_name) "ADM_" #rpc_name##s, scord::network::handlers::rpc_name

            REGISTER_RPC(ctx, "ADM_ping", void, ADM_ping_out_t, ADM_ping, true);
        daemon.set_handler(EXPAND(ping));

            // TODO: add internal RPCs for communication with scord
        };
#undef EXPAND

        daemon.configure(cfg, rpc_registration_cb);
#endif
        return daemon.run();
    } catch(const std::exception& ex) {
        fmt::print(stderr,