/
redgpu
/
ezEngine
Обзор
Документация
Войти
/
redgpu
/
ezEngine
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
dev
Code/Engine/Foundation/Communication/IpcProcessMessageProtocol.h
54 строки
2 KB
Sanakan8472
Improved IPC connection state handling (#1960)
09 июн 2026, 14:55
Не верифицирован
09 июн 2026, 14:55
ac44884
Код
Авторство
О чём код?
#pragma once #include <Foundation/Basics.h> #include <Foundation/Communication/RemoteInterface.h> #include <Foundation/Communication/RemoteMessage.h> #include <Foundation/Types/UniquePtr.h> class ezIpcChannel; class ezMessageLoop; /// \brief A protocol around ezIpcChannel to send reflected messages instead of byte array messages between client and server. /// /// This wrapper class hooks into an existing ezIpcChannel. The ezIpcChannel is still responsible for all connection logic. This class merely provides a high-level messaging protocol via reflected messages derived from ezProcessMessage. /// Note that if this class is used, ezIpcChannel::Send must not be called manually anymore, only use ezIpcProcessMessageProtocol::Send. /// Received messages are stored in a queue and must be flushed via calling ProcessMessages or WaitForMessages. class EZ_FOUNDATION_DLL ezIpcProcessMessageProtocol { public: ezIpcProcessMessageProtocol(ezIpcChannel* pChannel); ~ezIpcProcessMessageProtocol(); /// \brief Sends a message. pMsg can be destroyed after the call. bool Send(ezProcessMessage* pMsg); /// \brief Processes all pending messages by broadcasting m_MessageEvent. Not re-entrant. bool ProcessMessages(); /// \brief Block and wait for new messages and call ProcessMessages. ezResult WaitForMessages(ezTime timeout = ezTime::MakeZero()); public: struct Event { const ezProcessMessage* m_pMessage; // Set to true in a message handler to cancel the ProcessMessages function and return to the caller before all messages have been processed. mutable bool m_bInterruptMessageProcessing = false; }; ezEvent<const Event&> m_MessageEvent; ///< Will be sent from thread calling ProcessMessages or WaitForMessages. private: void EnqueueMessage(ezUniquePtr<ezProcessMessage>&& msg); ezUniquePtr<ezProcessMessage> PopMessage(); void ReceiveMessageData(ezArrayPtr<const ezUInt8> data); private: ezIpcChannel* m_pChannel = nullptr; ezUInt64 m_uiSendChannelId = 0; // UniqueID derived from channel address to correlate telemetry across processes. ezUInt64 m_uiReceiveChannelId = 0; // UniqueID derived from channel address to correlate telemetry across processes. ezAtomicInteger64 m_iSendMessageId = 0; ezMutex m_IncomingQueueMutex; ezDeque<ezUniquePtr<ezProcessMessage>> m_IncomingQueue; };