StormByte C++ Library: Network module 1.1.0
StormByte-Network is the C++26 networking module of the StormByte suite.
Loading...
Searching...
No Matches
endpoint.hxx
Go to the documentation of this file.
1/*
2 * Copyright (C) 2024-2026 David C. Manuelda (StormBytePP)
3 *
4 * This file is part of StormByte-Network.
5 *
6 * StormByte-Network is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License version 3
8 * or later, as published by the Free Software Foundation.
9 *
10 * StormByte-Network is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with StormByte-Network. If not, see
17 * <https://www.gnu.org/licenses/lgpl-3.0.html>.
18 */
19
20#pragma once
21
22#include <StormByte/buffer/pipeline.hxx>
23#include <StormByte/logger/threaded_log.hxx>
25
29namespace StormByte::Network {
30 namespace Connection {
31 class Client;
32 }
33
43 public:
49 Endpoint(const DeserializePacketFunction& deserialize_packet_function, std::shared_ptr<Logger::Log> logger) noexcept;
50
54 Endpoint(const Endpoint& other) = delete;
55
59 Endpoint(Endpoint&& other) noexcept = default;
60
64 virtual ~Endpoint() noexcept = default;
65
69 Endpoint& operator=(const Endpoint& other) = delete;
70
74 Endpoint& operator=(Endpoint&& other) noexcept = default;
75
83 virtual bool Connect(const Connection::Protocol& protocol, const std::string& address, const unsigned short& port) = 0;
84
88 virtual void Disconnect() noexcept = 0;
89
94 virtual Connection::Status Status() const noexcept = 0;
95
96 protected:
97 DeserializePacketFunction m_deserialize_packet_function;
98 std::shared_ptr<Logger::Log> m_logger;
99
105 std::shared_ptr<Connection::Client> CreateConnection(std::shared_ptr<Socket::Client> socket) noexcept;
106
111 virtual Buffer::Pipeline InputPipeline() const noexcept = 0;
112
117 virtual Buffer::Pipeline OutputPipeline() const noexcept = 0;
118
125 PacketPointer Send(std::shared_ptr<Connection::Client> client_connection, const Transport::Packet& packet) noexcept;
126
133 bool Reply(std::shared_ptr<Connection::Client> client_connection, const Transport::Packet& packet) noexcept;
134
135 private:
142 bool SendPacket(std::shared_ptr<Connection::Client> client_connection, const Transport::Packet& packet) noexcept;
143 };
144}
Abstract application client.
Definition client.hxx:43
Shared base for Client and Server.
Definition endpoint.hxx:42
Endpoint(Endpoint &&other) noexcept=default
Move constructor.
virtual ~Endpoint() noexcept=default
Destructor.
Endpoint(const Endpoint &other)=delete
Copy constructor (deleted).
Endpoint(const DeserializePacketFunction &deserialize_packet_function, std::shared_ptr< Logger::Log > logger) noexcept
Construct with a packet factory and a logger.
Network module of the StormByte suite.
Definition client.hxx:30
std::function< PacketPointer(Transport::Packet::OpcodeType, Buffer::Consumer, std::shared_ptr< Logger::Log >)> DeserializePacketFunction
Callback that builds a Packet from opcode + payload consumer.
Definition typedefs.hxx:68
std::shared_ptr< Transport::Packet > PacketPointer
Shared packet.
Definition typedefs.hxx:59
#define STORMBYTE_NETWORK_PUBLIC
Definition visibility.h:28