3#include <Foundation/Basics.h>
4#include <Foundation/Communication/Event.h>
5#include <Foundation/Communication/RemoteMessage.h>
6#include <Foundation/Containers/Deque.h>
7#include <Foundation/Containers/HashTable.h>
8#include <Foundation/Threading/Mutex.h>
9#include <Foundation/Threading/Thread.h>
10#include <Foundation/Time/Time.h>
11#include <Foundation/Types/Delegate.h>
14enum class plRemoteMode
24enum class plRemoteTransmitMode
43 plUInt32 m_uiOtherAppID;
78 plResult StartServer(plUInt32 uiConnectionToken,
plStringView sAddress,
bool bStartUpdateThread =
true);
89 plResult ConnectToServer(plUInt32 uiConnectionToken,
plStringView sAddress,
bool bStartUpdateThread =
true);
97 void ShutdownConnection();
132 plUInt32
GetServerID()
const {
return m_uiConnectedToServerWithID; }
143 void UpdateRemoteInterface();
146 void UpdatePingToServer();
156 void Send(plUInt32 uiSystemID, plUInt32 uiMsgID);
168 void Send(plRemoteTransmitMode tm, plUInt32 uiSystemID, plUInt32 uiMsgID,
const void* pData =
nullptr, plUInt32 uiDataBytes = 0);
187 plUInt32 ExecuteMessageHandlers(plUInt32 uiSystem);
190 plUInt32 ExecuteAllMessageHandlers();
222 virtual plResult DetermineTargetAddress(
plStringView sConnectTo, plUInt32& out_IP, plUInt16& out_Port);
230 void ReportConnectionToServer(plUInt32 uiServerID);
232 void ReportConnectionToClient(plUInt32 uiApplicationID);
234 void ReportDisconnectedFromServer();
236 void ReportDisconnectedFromClient(plUInt32 uiApplicationID);
238 void ReportMessage(plUInt32 uiApplicationID, plUInt32 uiSystemID, plUInt32 uiMsgID,
const plArrayPtr<const plUInt8>& data);
244 void StartUpdateThread();
245 void StopUpdateThread();
247 plResult CreateConnection(plUInt32 uiConnectionToken, plRemoteMode mode,
plStringView sServerAddress,
bool bStartUpdateThread);
252 plRemoteMode m_RemoteMode = plRemoteMode::None;
255 plUInt32 m_uiApplicationID = 0;
256 plUInt32 m_uiConnectionToken = 0;
257 plUInt32 m_uiConnectedToServerWithID = 0;
258 plInt32 m_iConnectionsToClients = 0;
274 volatile bool m_bKeepRunning =
true;
277 virtual plUInt32 Run();
This class encapsulates an array and it's size. It is recommended to use this class instead of plain ...
Definition ArrayPtr.h:37
Definition MemoryStream.h:145
Definition DynamicArray.h:81
Definition HashTable.h:333
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Definition RemoteInterface.h:60
virtual void InternalUpdateRemoteInterface()=0
Derived classes have to implement this to update.
plRemoteMode GetRemoteMode() const
Whether the remote interface is inactive, a client or a server.
Definition RemoteInterface.h:109
virtual plResult InternalCreateConnection(plRemoteMode mode, plStringView sServerAddress)=0
Derived classes have to implement this to start a network connection.
plUInt32 GetServerID() const
Some random identifier, that allows to determine after a reconnect, whether the connected instance is...
Definition RemoteInterface.h:132
plTime GetPingToServer() const
Returns the current ping to the server.
Definition RemoteInterface.h:135
virtual plTime InternalGetPingToServer()=0
Derived classes have to implement this to get the ping to the server (client mode only)
const plString & GetServerInfoIP() const
For the client to display the name of the server.
Definition RemoteInterface.h:129
virtual plResult InternalTransmit(plRemoteTransmitMode tm, const plArrayPtr< const plUInt8 > &data)=0
Derived classes have to implement this to deliver messages to the server or client.
virtual void InternalShutdownConnection()=0
Derived classes have to implement this to shutdown a network connection.
plEvent< const plRemoteEvent & > m_RemoteEvents
Broadcasts events about connections.
Definition RemoteInterface.h:198
plUInt32 GetConnectionToken() const
Returns the connection token used to identify compatible servers/clients.
Definition RemoteInterface.h:118
bool IsConnectedToServer() const
Whether the client is connected to a server.
Definition RemoteInterface.h:100
const plString & GetServerAddress() const
The address through which the connection was started.
Definition RemoteInterface.h:112
bool IsConnectedToClients() const
Whether the server is connected to any client.
Definition RemoteInterface.h:103
plString m_sServerInfoIP
Derived classes should update this when the information is available.
Definition RemoteInterface.h:227
bool IsConnectedToOther() const
Whether the client or server is connected its counterpart.
Definition RemoteInterface.h:106
plMutex & GetMutex() const
Exposes the mutex that is internally used to secure multi-threaded access.
Definition RemoteInterface.h:65
plUInt32 GetApplicationID() const
Returns the own (random) application ID used to identify this instance.
Definition RemoteInterface.h:115
Encapsulates all the data that is transmitted when sending or receiving a message with plRemoteInterf...
Definition RemoteMessage.h:11
The remote interface thread updates in regular intervals to keep the connection alive.
Definition RemoteInterface.h:269
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
This class is the base class for platform independent long running threads.
Definition Thread.h:40
Event type for connections.
Definition RemoteInterface.h:33
Type
Definition RemoteInterface.h:35
@ ConnectedToClient
brief Sent whenever a new connection to a client has been established.
Definition RemoteInterface.h:36
@ ConnectedToServer
brief Sent whenever a connection to the server has been established.
Definition RemoteInterface.h:37
@ DisconnectedFromClient
Sent every time the connection to a client is dropped.
Definition RemoteInterface.h:38
@ DisconnectedFromServer
Sent when the connection to the server has been lost.
Definition RemoteInterface.h:39
Definition RemoteInterface.h:49
plDeque< plRemoteMessage > m_MessageQueueOut
To flush the message queue, m_MessageQueueIn and m_MessageQueueOut are swapped. Thus new messages can...
Definition RemoteInterface.h:56
plDeque< plRemoteMessage > m_MessageQueueIn
Messages are pushed into this container on arrival.
Definition RemoteInterface.h:52
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12
PL_ALWAYS_INLINE static constexpr plTime MakeFromSeconds(double fSeconds)
Creates an instance of plTime that was initialized from seconds.
Definition Time.h:30