node_nng: hide some nng details

This commit is contained in:
Florian Lüke 2024-11-28 02:52:15 +01:00
parent 3c1ced7de5
commit 7ed57acdee
2 changed files with 57 additions and 40 deletions

View file

@ -2,13 +2,6 @@
#define B18E3651_CA9A_43BC_AA25_810EA16533CD
#include <nng/nng.h>
#include <nng/protocol/pair0/pair.h>
#include <nng/protocol/pipeline0/pull.h>
#include <nng/protocol/pipeline0/push.h>
#include <nng/protocol/pubsub0/pub.h>
#include <nng/protocol/pubsub0/sub.h>
#include <nng/protocol/reqrep0/req.h>
#include <nng/protocol/reqrep0/rep.h>
#include <spdlog/spdlog.h>
#include <optional>
@ -117,40 +110,16 @@ inline nng_socket make_socket(socket_factory factory, nng_duration timeout = Def
return socket;
}
inline nng_socket make_pair_socket(nng_duration timeout = DefaultTimeout)
{
return make_socket(nng_pair0_open, timeout);
}
nng_socket make_pair_socket(nng_duration timeout = DefaultTimeout);
inline nng_socket make_push_socket(nng_duration timeout = DefaultTimeout)
{
return make_socket(nng_push0_open, timeout);
}
nng_socket make_push_socket(nng_duration timeout = DefaultTimeout);
nng_socket make_pull_socket(nng_duration timeout = DefaultTimeout);
inline nng_socket make_pull_socket(nng_duration timeout = DefaultTimeout)
{
return make_socket(nng_pull0_open, timeout);
}
nng_socket make_pub_socket(nng_duration timeout = DefaultTimeout);
nng_socket make_sub_socket(nng_duration timeout = DefaultTimeout);
inline nng_socket make_pub_socket(nng_duration timeout = DefaultTimeout)
{
return make_socket(nng_pub0_open, timeout);
}
inline nng_socket make_sub_socket(nng_duration timeout = DefaultTimeout)
{
return make_socket(nng_sub0_open, timeout);
}
inline nng_socket make_req_socket(nng_duration timeout = DefaultTimeout)
{
return make_socket(nng_req0_open, timeout);
}
inline nng_socket make_rep_socket(nng_duration timeout = DefaultTimeout)
{
return make_socket(nng_rep0_open, timeout);
}
nng_socket make_req_socket(nng_duration timeout = DefaultTimeout);
nng_socket make_rep_socket(nng_duration timeout = DefaultTimeout);
inline std::string socket_get_string_opt(nng_socket s, const char *opt)
{
@ -440,11 +409,11 @@ inline unique_msg make_message(const std::string &data)
if (int res = nng_msg_alloc(&msg, data.size()))
{
mesy_nng_error("nng_msg_alloc", res);
return unique_msg(nullptr, nng_msg_free);
return make_unique_msg();
}
std::memcpy(nng_msg_body(msg), data.data(), data.size());
return unique_msg(msg, nng_msg_free);
return make_unique_msg(msg);
}
}

View file

@ -1 +1,49 @@
#include "mesytec-node/mesytec_node_nng.h"
#include <nng/protocol/pair0/pair.h>
#include <nng/protocol/pipeline0/pull.h>
#include <nng/protocol/pipeline0/push.h>
#include <nng/protocol/pubsub0/pub.h>
#include <nng/protocol/pubsub0/sub.h>
#include <nng/protocol/reqrep0/req.h>
#include <nng/protocol/reqrep0/rep.h>
namespace mesytec::nng
{
nng_socket make_pair_socket(nng_duration timeout)
{
return make_socket(nng_pair0_open, timeout);
}
nng_socket make_push_socket(nng_duration timeout)
{
return make_socket(nng_push0_open, timeout);
}
nng_socket make_pull_socket(nng_duration timeout)
{
return make_socket(nng_pull0_open, timeout);
}
nng_socket make_pub_socket(nng_duration timeout)
{
return make_socket(nng_pub0_open, timeout);
}
nng_socket make_sub_socket(nng_duration timeout)
{
return make_socket(nng_sub0_open, timeout);
}
nng_socket make_req_socket(nng_duration timeout)
{
return make_socket(nng_req0_open, timeout);
}
nng_socket make_rep_socket(nng_duration timeout)
{
return make_socket(nng_rep0_open, timeout);
}
}