SOLA
Loading...
Searching...
No Matches
network_facade.h
1// Copyright The SOLA Contributors
2//
3// Licensed under the MIT License.
4// For details on the licensing terms, see the LICENSE file.
5// SPDX-License-Identifier: MIT
6
7#ifndef NATTER_CORE_NETWORK_FACADE_H_
8#define NATTER_CORE_NETWORK_FACADE_H_
9
10#include "natter/network_info_ipv4.h"
11#include "solanet/network_udp/network_udp.h"
12#include "solanet/serializer/serializer.h"
13
14namespace natter::core {
18template <typename T> class NetworkFacade {
19public:
20 explicit NetworkFacade(std::function<void(const T &)> recv_fct)
21 : network_(
22 [this](auto &&message) { processMessage(std::forward<decltype(message)>(message)); }),
23 recv_fct_(std::move(recv_fct)) {}
24
25 void send(const NetworkInfoIPv4 &net_info, const T &message) {
26 network_.send({net_info.ip, net_info.port, solanet::serializer::serialize<T>(message)});
27 }
28
29 NetworkInfoIPv4 getNetworkInfo() const { return {network_.getIP(), network_.getPort()}; }
30
31private:
32 void processMessage(const solanet::Message &msg) {
33 recv_fct_(solanet::serializer::deserialize<T>(msg.getMessage()));
34 }
35 solanet::Network network_;
36 std::function<void(const T &)> recv_fct_;
37};
38} // namespace natter::core
39
40#endif // NATTER_CORE_NETWORK_FACADE_H_
Definition network_facade.h:18
Definition message.h:14
std::string getMessage() const
Definition message.h:37
Definition network_udp.h:18
void send(const Message &msg)
Definition ns3SolaNet.cpp:156
Definition network_info_ipv4.h:14