|
Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
|
The shared state of one tool call. More...
#include <server_p.h>
Public Member Functions | |
| ~ToolCallPrivate () | |
| Answers with an error if no handler finished the call. | |
| void | finish (const ToolResult &result) |
| Sends the result (unless cancelled) and releases the call's resources. | |
| bool | expire (const ToolResult &result) |
Finishes the call with result only if its handler hasn't started, in one step with the check. | |
| void | cancel () |
| Marks the call cancelled, runs cancel handlers, and finishes it silently. | |
Public Attributes | |
| QPointer< Server > | server |
| Owning server (may be gone; dereference on link's thread only). | |
| std::shared_ptr< HomeLink > | link |
| To the sessions' thread: replies, progress, bookkeeping. | |
| std::shared_ptr< HomeLink > | guiLink |
| To the server's thread: the handler and cancel callbacks. | |
| std::weak_ptr< Session > | session |
| Calling session (may be gone). | |
| QString | sessionId |
| Id of the calling session. | |
| QString | toolName |
| Called tool. | |
| QJsonObject | arguments |
| Call arguments. | |
| QJsonValue | requestId |
| JSON-RPC request id. | |
| QString | requestKey |
| requestId serialized, for lookups. | |
| QJsonValue | progressToken |
| _meta.progressToken, if any. | |
| std::mutex | mutex |
| Guards the fields below (the atomics are written under it too). | |
| ReplyFunction | reply |
| Delivers the response (call it on the server's thread). | |
| std::atomic< bool > | finished = false |
| Whether the call was answered or cancelled. | |
| std::atomic< bool > | cancelled = false |
| Whether the call was cancelled. | |
| std::atomic< bool > | started = false |
| Whether its handler started (set under mutex). | |
| qint64 | postedAtMs = 0 |
| When it was posted to the server's thread (ServerPrivate::nowMs()). | |
| QObject * | context = nullptr |
| Lifetime object for handlers; see ToolCall::context(). | |
| QList< std::function< void()> > | cancelHandlers |
| Callbacks registered with onCancelled(). | |
Private Member Functions | |
| bool | complete (const ToolResult &result, bool onlyIfNotStarted) |
finish() and expire(): finishes unless finished already (or, with onlyIfNotStarted, unless started). | |
The shared state of one tool call.
Thread safety: a handler may finish the call, report progress and register cancel handlers from any thread. The fields set when the call is created (server, session, ids, arguments, ...) never change. finished, cancelled, reply, context and cancelHandlers are guarded by mutex. Replies, progress notifications and the bookkeeping in the session always happen on the server's thread, through link.
|
private |
| bool Sonde::ToolCallPrivate::expire | ( | const ToolResult & | result | ) |
Finishes the call with result only if its handler hasn't started, in one step with the check.