3#include <Foundation/Communication/Implementation/TelemetryMessage.h>
4#include <Foundation/Containers/Deque.h>
5#include <Foundation/Containers/HybridArray.h>
6#include <Foundation/Containers/Map.h>
7#include <Foundation/Logging/Log.h>
8#include <Foundation/Strings/String.h>
9#include <Foundation/Threading/Mutex.h>
10#include <Foundation/Time/Time.h>
18 static plUInt16 s_uiPort ;
52 static void CreateServer();
58 static void CloseConnection();
66 static void Broadcast(TransmitMode tm, plUInt32 uiSystemID, plUInt32 uiMsgID,
const void* pData, plUInt32 uiDataBytes);
67 static void Broadcast(TransmitMode tm, plUInt32 uiSystemID, plUInt32 uiMsgID,
plStreamReader& inout_stream, plInt32 iDataBytes = -1);
70 static void SendToServer(plUInt32 uiSystemID, plUInt32 uiMsgID,
const void* pData =
nullptr, plUInt32 uiDataBytes = 0);
71 static void SendToServer(plUInt32 uiSystemID, plUInt32 uiMsgID,
plStreamReader& inout_stream, plInt32 iDataBytes = -1);
89 static bool IsConnectedToOther();
122 static plMutex& GetTelemetryMutex();
145 static void UpdateNetwork();
147 using ProcessMessagesCallback = void (*)(
void*);
149 static void AcceptMessagesForSystem(plUInt32 uiSystemID,
bool bAccept, ProcessMessagesCallback callback =
nullptr,
void* pPassThrough =
nullptr);
152 static void PerFrameUpdate();
161 static void SetOutgoingQueueSize(plUInt32 uiSystemID, plUInt16 uiMaxQueued);
179 EventType m_EventType;
193 static void UpdateServerPing();
197 static void Transmit(TransmitMode tm,
const void* pData, plUInt32 uiDataBytes);
199 static void Send(TransmitMode tm, plUInt32 uiSystemID, plUInt32 uiMsgID,
const void* pData, plUInt32 uiDataBytes);
200 static void Send(TransmitMode tm, plUInt32 uiSystemID, plUInt32 uiMsgID,
plStreamReader& Stream, plInt32 iDataBytes = -1);
203 friend class plTelemetryThread;
205 static void FlushOutgoingQueues();
207 static void InitializeAsServer();
209 static ConnectionMode s_ConnectionMode;
211 static plUInt32 s_uiApplicationID;
212 static plUInt32 s_uiServerID;
217 static bool s_bConnectedToServer;
218 static bool s_bConnectedToClient;
219 static bool s_bAllowNetworkUpdate;
221 static void QueueOutgoingMessage(TransmitMode tm, plUInt32 uiSystemID, plUInt32 uiMsgID,
const void* pData, plUInt32 uiDataBytes);
223 static void SendServerName();
225 static plTime s_PingToServer;
233 m_bAcceptMessages =
false;
234 m_uiMaxQueuedOutgoing = 1000;
235 m_Callback =
nullptr;
236 m_pPassThrough =
nullptr;
239 bool m_bAcceptMessages;
240 ProcessMessagesCallback m_Callback;
241 void* m_pPassThrough;
242 plUInt32 m_uiMaxQueuedOutgoing;
244 MessageDeque m_IncomingQueue;
245 MessageDeque m_OutgoingQueue;
250 static plEventTelemetry s_TelemetryEvents;
253 static plMutex s_TelemetryMutex;
254 static void StartTelemetryThread();
255 static void StopTelemetryThread();
Provides a simple mechanism for mutual exclusion to prevent multiple threads from accessing a shared ...
Definition Mutex.h:13
Interface for binary in (read) streams.
Definition Stream.h:22
plStringView represent a read-only sub-string of a larger string, as it can store a dedicated string ...
Definition StringView.h:34
Definition Telemetry.h:15
static plTime GetPingToServer()
Returns the last round trip time ('Ping') to the Server. Only meaningful if there is an active connec...
Definition Telemetry.h:92
static bool IsConnectedToServer()
Returns whether a Client has an active connection to a Server.
Definition Telemetry.h:83
static plStringView GetServerIP()
Returns the IP address of the machine on which the Server is running. Only meaningful if there is an ...
Definition Telemetry.h:107
static void AddEventHandler(plEventTelemetry::Handler handler)
Adds an event handler that is called for every plTelemetry event.
Definition Telemetry.h:185
static bool IsConnectedToClient()
Returns whether a Server has an active connection to at least one Client.
Definition Telemetry.h:86
static plUInt32 GetServerID()
Returns a 'unique' ID for the application instance to which this Client is connected.
Definition Telemetry.h:115
static plStringView GetServerName()
Returns the name of the machine on which the Server is running. Only meaningful if there is an active...
Definition Telemetry.h:96
TransmitMode
Describes how to send messages.
Definition Telemetry.h:30
@ Reliable
Messages should definitely arrive at the target, if necessary they are send several times,...
Definition Telemetry.h:31
static void RemoveEventHandler(plEventTelemetry::Handler handler)
Removes a previously added event handler.
Definition Telemetry.h:188
static ConnectionMode GetConnectionMode()
Returns whether the telemetry system is set up as Server, Client or not initialized at all.
Definition Telemetry.h:80
ConnectionMode
Defines how the plTelemetry system was configured.
Definition Telemetry.h:22
@ Client
Set up as a Client, i.e. this is a tool that gathers information from a Server, usually for debugging...
Definition Telemetry.h:25
@ Server
Set up as a Server, i.e. this is an application that broadcasts information about its current state t...
Definition Telemetry.h:24
@ None
Not configured yet, at all.
Definition Telemetry.h:23
Definition TelemetryMessage.h:6
Default enum for returning failure or success, instead of using a bool.
Definition Types.h:54
Definition Telemetry.h:169
EventType
Definition Telemetry.h:171
@ DisconnectedFromClient
Send every time the connection to a client is dropped.
Definition Telemetry.h:174
@ ConnectedToClient
brief Send whenever a new connection to a client has been established.
Definition Telemetry.h:172
@ ConnectedToServer
brief Send whenever a connection to the server has been established.
Definition Telemetry.h:173
@ PerFrameUpdate
Send once per frame, react to this to send per-frame statistics.
Definition Telemetry.h:176
@ DisconnectedFromServer
Send when the connection to the server has been lost.
Definition Telemetry.h:175
The time class encapsulates a double value storing the time in seconds.
Definition Time.h:12