// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. #pragma once #include "Engine/Scripting/ScriptingType.h" #include "Types.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; public: /// /// 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. virtual void Initialize(NetworkPeer* host, const NetworkConfig& config) = 0; /// /// Disposes this driver making it no longer usable. /// Reserved for resource deallocation etc. /// virtual void Dispose() = 0; /// /// Starts listening for incoming connections. /// Once this is called, this driver becomes a server. /// /// True when succeeded. 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. virtual bool Connect() = 0; /// /// Disconnects from the server. /// /// Can be used only by the client! virtual void Disconnect() = 0; /// /// Disconnects given connection from the server. /// /// Can be used only by the server! 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. virtual bool PopEvent(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! /// /// Do not recycle the message after calling this. /// This function automatically recycles the message. 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! /// /// Do not recycle the message after calling this. /// This function automatically recycles the message. /// 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! /// /// Do not recycle the message after calling this. /// This function automatically recycles the message. /// virtual void SendMessage(NetworkChannelType channelType, const NetworkMessage& message, const Array& targets) = 0; // TODO: Stats API // TODO: Simulation API };