/*! * * 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 AgentInterface.h * \author (original) Stephen Quong * \date (original) 24-May-2026 * */ #pragma once #include #include #include #include #include #include #include "AgentMessage.h" /*! * \brief UDS interface to the Connectivity Agent * \details Manages the QLocalSocket connection to the Connectivity Agent * including automatic reconnection on disconnect or error. * Outbound: call send() to write an AgentMessage frame to the socket. * Inbound: emits didMessageReceive() for each complete parsed frame. */ class AgentInterface : public QObject { Q_OBJECT public: AgentInterface(QObject *parent = nullptr); bool init(const QString &socketPath, int reconnectIntervalMs); bool init(const QString &socketPath, int reconnectIntervalMs, QThread &thread); bool send(AgentMessage::MsgId msgId, quint16 sequence, const QByteArray &payload = {}); public Q_SLOTS: void quit(); Q_SIGNALS: /*! * \brief didMessageReceive * \details Emitted when a complete inbound AgentMessage 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(AgentMessage::MsgId msgId, quint16 sequence, QByteArray payload); /*! * \brief didConnect * \details Emitted when the socket connects successfully. */ void didConnect(); /*! * \brief didDisconnect * \details Emitted when the socket disconnects. */ void didDisconnect(); private Q_SLOTS: void onConnected(); void onDisconnected(); void onError(QLocalSocket::LocalSocketError error); void onReadyRead(); void onReconnectTimer(); private: void connectToServer(); void initThread(QThread &thread); void quitThread(); QLocalSocket _socket; QTimer _reconnectTimer; QString _socketPath; QByteArray _rxBuf; AgentMessage _rxMsg; bool _init = false; };