// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved.
#pragma once
#include "Types.h"
#include "Engine/Core/Types/String.h"
#include "Engine/Scripting/ScriptingType.h"
///
/// Basic interface for the low-level network transport/driver.
///
API_INTERFACE(Namespace="FlaxEngine.Networking") class FLAXENGINE_API INetworkDriver
{
DECLARE_SCRIPTING_TYPE_MINIMAL(INetworkDriver);
public:
///
/// Finalizes an instance of the class.
///
virtual ~INetworkDriver() = default;
///
/// Return name of this network driver implementation.
///
API_FUNCTION() virtual String DriverName()
{
return String("Unknown");
}
///
/// Initializes the instance of this network driver using given configuration.
///
/// The peer that this driver has been assigned to.
/// The network config to use to configure this driver.
/// True if failed to initialize network driver, false otherwise.
API_FUNCTION() virtual bool Initialize(NetworkPeer* host, const NetworkConfig& config) = 0;
///
/// Disposes this driver making it no longer usable.
/// Reserved for resource deallocation etc.
///
API_FUNCTION() virtual void Dispose() = 0;
///
/// Starts listening for incoming connections.
/// Once this is called, this driver becomes a server.
///
/// True when succeeded.
API_FUNCTION() virtual bool Listen() = 0;
///
/// Starts connection handshake with the end point specified in the structure.
/// Once this is called, this driver becomes a client.
///
/// True when succeeded.
API_FUNCTION() virtual bool Connect() = 0;
///
/// Disconnects from the server.
///
/// Can be used only by the client!
API_FUNCTION() virtual void Disconnect() = 0;
///
/// Disconnects given connection from the server.
///
/// Can be used only by the server!
API_FUNCTION() virtual void Disconnect(const NetworkConnection& connection) = 0;
///
/// Tries to pop an network event from the queue.
///
/// The pointer to event structure.
/// True when succeeded and the event can be processed.
API_FUNCTION() virtual bool PopEvent(API_PARAM(Out) NetworkEvent& eventPtr) = 0;
///
/// Sends given message over specified channel to the server.
///
/// The channel to send the message over.
/// The message.
/// Can be used only by the client!
API_FUNCTION() virtual void SendMessage(NetworkChannelType channelType, const NetworkMessage& message) = 0;
///
/// Sends given message over specified channel to the given client connection (target).
///
/// The channel to send the message over.
/// The message.
/// The client connection to send the message to.
/// Can be used only by the server!
API_FUNCTION() virtual void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, NetworkConnection target) = 0;
///
/// Sends given message over specified channel to the given client connection (target).
///
/// The channel to send the message over.
/// The message.
/// The connections list to send the message to.
/// Can be used only by the server!
API_FUNCTION() virtual void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, const Array& targets) = 0;
///
/// Gets the network transport layer stats.
///
/// Network transport statistics data for a given connection.
API_FUNCTION() virtual NetworkDriverStats GetStats() = 0;
///
/// Gets the network transport layer stats for a given connection.
///
/// The client connection to retrieve statistics for.
/// Network transport statistics data for a given connection.
API_FUNCTION() virtual NetworkDriverStats GetStats(NetworkConnection target) = 0;
};