Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
Sonde::Bridge::anonymous_namespace{bridge.cpp}::Bridge Class Reference

Copies lines between stdin/stdout and a QLocalSocket. More...

Inheritance diagram for Sonde::Bridge::anonymous_namespace{bridge.cpp}::Bridge:

Classes

struct  Held
 A line from stdin held while the application is away (–reconnect). More...

Public Member Functions

 Bridge (QString name, RetryPolicy policy)
 A bridge to the local server name.
void start ()
 Starts connecting once the event loop runs (so an immediate failure can exit() it).
void onStdinLine (const QByteArray &line)
 Forwards one line read from stdin (newline included).
void onStdinClosed ()
 Stdin reached end of file: finish once everything has been delivered and answered.

Private Member Functions

void connectNow ()
 Starts a connection attempt.
void onConnected ()
 Sends what arrived on stdin before the connection; after a reconnection, replays the handshake first and tells the client its lists may have changed.
void onDisconnected ()
 The server closed the connection: exit, or (with –reconnect) answer what was left unanswered and start waiting for the application to come back.
void expireHeld ()
 Answers held requests that waited longer than the hold time with an error.
void onError (QLocalSocket::LocalSocketError error)
 Retries (if the policy allows) or exits with status 1.
void onReadyRead ()
 Copies complete lines from the socket to stdout and notes which requests were answered.
void finishIfDone ()
 Exits once stdin is closed, everything was written and every request answered.

Static Private Member Functions

static void writeStdout (const QByteArray &data)
 Writes data to stdout and flushes it.

Private Attributes

QString m_name
 Server name or socket path.
RetryPolicy m_policy
 Whether and how long to retry.
QLocalSocket m_socket
 Connection to the application.
QByteArray m_pending
 Stdin data received before the first connection.
QList< Held > m_held
 Stdin lines received while reconnecting.
QByteArray m_buffer
 Socket data not yet ending in a newline.
QHash< QString, QJsonValue > m_outstanding
 Forwarded requests not yet answered, by idKey().
QSet< QString > m_ownIds
 Ids of replayed requests whose answers are swallowed.
Handshake m_handshake
 The client's session setup, for replaying.
bool m_everConnected = false
 Whether the first connection succeeded.
bool m_stdinClosed = false
 Whether stdin reached end of file.
bool m_announcedWait = false
 Whether "waiting for ..." was printed.
QTimer m_retry
 Delays connection retries.
QTimer m_holdCheck
 Expires held lines while reconnecting.
QElapsedTimer m_waited
 Time spent trying to connect.

Detailed Description

Copies lines between stdin/stdout and a QLocalSocket.


The documentation for this class was generated from the following file: