/*! * * Copyright (c) 2024-2026 Diality Inc. - All Rights Reserved. * \copyright * THIS CODE MAY NOT BE COPIED OR REPRODUCED IN ANY FORM, IN PART OR IN * WHOLE, WITHOUT THE EXPLICIT PERMISSION OF THE COPYRIGHT OWNER. * * \file RtServer.h * \author (original) Stephen Quong * \date (original) 15-Jul-2026 * */ #pragma once #include #include #include #include #include #include "RtMessage.h" /*! * \brief Unix domain socket server for RtMessage frames. * \details Base class providing local-socket server support. Listens on a Unix * domain socket, accepts one client at a time, parses inbound * RtMessage frames, and emits didMessageReceive() for each complete * frame. Outbound: call send() to reply to the connected client. * Parser state is cleared automatically when the client disconnects. * * Intended to be inherited by controllers (e.g. AgentSimController, * CloudConnectController) that need to accept a connection and exchange * framed messages over a local socket. */ class RtServer : public QObject { Q_OBJECT public: explicit RtServer(QObject *parent = nullptr); bool listen(const QString &socketPath); bool send(RtMessage::MsgId msgId, quint16 sequence, const QByteArray &payload = {}); bool isConnected() const; Q_SIGNALS: /*! * \brief didMessageReceive * \details Emitted when a complete inbound RtMessage frame has been parsed. * \param msgId - message identifier from the frame header * \param sequence - sequence number from the frame header * \param payload - decoded payload bytes, empty for zero-length frames */ void didMessageReceive(RtMessage::MsgId msgId, quint16 sequence, QByteArray payload); /*! * \brief didConnect * \details Emitted when a client connects. */ void didConnect(); /*! * \brief didDisconnect * \details Emitted when the connected client disconnects. */ void didDisconnect(); private Q_SLOTS: void onNewConnection(); void onDisconnected(); void onReadyRead(); private: QLocalServer _server; QLocalSocket *_client = nullptr; QByteArray _rxBuf; RtMessage _rxMsg; };