Line data Source code
1 : #ifndef FELIX_NETWORK_UTILITY_HPP
2 : #define FELIX_NETWORK_UTILITY_HPP
3 :
4 : #include <memory>
5 :
6 : #include "bus.hpp"
7 : #include "config.hpp"
8 : #include "netio_buffered_publisher.hpp"
9 : #include "netio_buffered_receiver.hpp"
10 : #include "netio_unbuffered_receiver.hpp"
11 : #include "netio_zerocopy_publisher.hpp"
12 : #include "publisher.hpp"
13 : #include "receiver.hpp"
14 :
15 : namespace network::utility {
16 : [[nodiscard]] inline std::unique_ptr<Publisher>
17 14 : create_buffered_publisher(EventLoopType evloop_type, const std::string &ip,
18 : uint32_t port, Bus &bus, unsigned int netio_pn,
19 : unsigned int netio_ps, unsigned int netio_wm,
20 : unsigned int netio_to, std::uint32_t max_chunk_size) {
21 14 : switch (evloop_type) {
22 14 : case EventLoopType::netio_next:
23 14 : return std::make_unique<NetioBufferedPublisher>(
24 14 : ip, port, bus, netio_pn, netio_ps, netio_wm, netio_to, max_chunk_size);
25 0 : case EventLoopType::netio3_native:
26 0 : case EventLoopType::netio3_asio:
27 0 : throw std::runtime_error("Netio3 not implemented");
28 0 : default:
29 0 : throw std::logic_error("Invalid EventLoopType");
30 : }
31 : }
32 :
33 : [[nodiscard]] inline std::unique_ptr<Publisher>
34 10 : create_zero_copy_publisher(EventLoopType evloop_type, const std::string &ip,
35 : uint32_t port, Bus &bus, unsigned int netio_pn,
36 : unsigned int netio_ps, std::uint32_t max_chunk_size,
37 : uint64_t dma_buffer_vaddr, size_t dma_size) {
38 :
39 10 : switch (evloop_type) {
40 10 : case EventLoopType::netio_next:
41 10 : return std::make_unique<NetioZerocopyPublisher>(ip, port, bus, netio_pn,
42 : netio_ps, max_chunk_size,
43 10 : dma_buffer_vaddr, dma_size);
44 0 : case EventLoopType::netio3_native:
45 0 : case EventLoopType::netio3_asio:
46 0 : throw std::runtime_error("Netio3 not implemented");
47 0 : default:
48 0 : throw std::logic_error("Invalid EventLoopType");
49 : }
50 : }
51 :
52 : [[nodiscard]] inline std::unique_ptr<Receiver>
53 5 : create_buffered_receiver(EventLoopType evloop_type, const std::string &ip,
54 : uint32_t port, Bus &bus, unsigned int netio_pn,
55 : unsigned int netio_ps) {
56 :
57 5 : switch (evloop_type) {
58 5 : case EventLoopType::netio_next:
59 5 : return std::make_unique<NetioBufferedReceiver>(ip, port, bus, netio_pn,
60 5 : netio_ps);
61 0 : case EventLoopType::netio3_native:
62 0 : case EventLoopType::netio3_asio:
63 0 : throw std::runtime_error("Netio3 not implemented");
64 0 : default:
65 0 : throw std::logic_error("Invalid EventLoopType");
66 : }
67 : }
68 :
69 : [[nodiscard]] inline std::unique_ptr<Receiver>
70 0 : create_unbuffered_receiver(EventLoopType evloop_type, const std::string &ip,
71 : uint32_t port, Bus &bus, unsigned int netio_pn,
72 : unsigned int netio_ps) {
73 :
74 0 : switch (evloop_type) {
75 0 : case EventLoopType::netio_next:
76 0 : return std::make_unique<NetioUnbufferedReceiver>(ip, port, bus, netio_pn,
77 0 : netio_ps);
78 0 : case EventLoopType::netio3_native:
79 0 : case EventLoopType::netio3_asio:
80 0 : throw std::runtime_error("Netio3 not implemented");
81 0 : default:
82 0 : throw std::logic_error("Invalid EventLoopType");
83 : }
84 : }
85 : } // namespace network::utility
86 :
87 : #endif
|