Eliminate std::function: fn-pointer callbacks, per-test test_state structs, udp.cpp with link-time udp::client::handler, udp::address
This commit is contained in:
@@ -1,11 +1,9 @@
|
||||
#pragma once
|
||||
#include <expected>
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
#include <span>
|
||||
#include "eth.h"
|
||||
#include "ipv4.h"
|
||||
#include "span_writer.h"
|
||||
#include "msgpack.h"
|
||||
#include "callback_list.h"
|
||||
|
||||
struct net_state {
|
||||
@@ -13,22 +11,16 @@ struct net_state {
|
||||
ipv4::ip4_addr ip;
|
||||
};
|
||||
|
||||
using encode_fn = std::function<msgpack::result<size_t>(span_writer&)>;
|
||||
using send_fn = std::function<void(encode_fn)>;
|
||||
|
||||
using net_handler = std::function<void(std::span<const uint8_t> payload,
|
||||
send_fn send)>;
|
||||
|
||||
using net_frame_callback = std::function<bool(std::span<const uint8_t> frame)>;
|
||||
using net_frame_callback = bool (*)(std::span<const uint8_t> frame);
|
||||
|
||||
using frame_cb_list = callback_list<net_frame_callback, 16>;
|
||||
using frame_cb_handle = frame_cb_list::node*;
|
||||
|
||||
inline constexpr uint16_t PICOMAP_PORT_BE = __builtin_bswap16(28781);
|
||||
|
||||
bool net_init();
|
||||
const net_state& net_get_state();
|
||||
void net_set_handler(net_handler handler);
|
||||
frame_cb_handle net_add_frame_callback(net_frame_callback cb);
|
||||
void net_remove_frame_callback(frame_cb_handle h);
|
||||
void net_poll(std::span<uint8_t> tx);
|
||||
void net_send_raw(std::span<const uint8_t> data);
|
||||
void net_handle_udp(std::span<const uint8_t> frame, span_writer& tx);
|
||||
|
||||
Reference in New Issue
Block a user