Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
statetools.cpp File Reference

state_wait, state_snapshot and state_diff: waiting for and comparing application state. More...

#include "server_p.h"
#include <sonde/introspectiontools.h>
#include <sonde/objecttree.h>
#include <sonde/schema.h>
#include <QtCore/QElapsedTimer>
#include <QtCore/QJsonArray>
#include <QtCore/QMap>
#include <QtCore/QMetaProperty>
#include <QtCore/QPointer>
#include <QtCore/QSet>
#include <QtCore/QTimer>
#include <memory>

Classes

struct  Sonde::anonymous_namespace{statetools.cpp}::Condition
 What state_wait waits for. More...
struct  Sonde::anonymous_namespace{statetools.cpp}::ObjectState
 One object in a snapshot. More...
struct  Sonde::anonymous_namespace{statetools.cpp}::Snapshot
 A snapshot: objects by id, in tree order. More...
struct  Sonde::anonymous_namespace{statetools.cpp}::Snapshots
 The snapshots, oldest first, shared by the two tools. More...

Namespaces

namespace  Sonde
 Embeddable Model Context Protocol server for Qt applications.

Functions

bool Sonde::anonymous_namespace{statetools.cpp}::truthy (const QJsonValue &v)
 Whether v counts as true: true, non-zero, or a non-empty string, array or object.
bool Sonde::anonymous_namespace{statetools.cpp}::passes (const Condition &c, const QJsonValue &value)
 Whether value passes c's test.
std::optional< Condition > Sonde::anonymous_namespace{statetools.cpp}::parseCondition (const QJsonObject &args, QString *error)
 Parses state_wait's arguments.
bool Sonde::anonymous_namespace{statetools.cpp}::check (const Condition &c, QString *state, QJsonValue *value, QString *error)
 One check of c.
void Sonde::anonymous_namespace{statetools.cpp}::waitUntil (const ToolCall &call)
 The state_wait tool.
QMap< QString, QString > Sonde::anonymous_namespace{statetools.cpp}::propertyValues (const QObject *o)
 The readable properties of o, as compact JSON text.
Snapshot Sonde::anonymous_namespace{statetools.cpp}::takeSnapshot (const QObjectList &start, int maxObjects)
 Takes a snapshot of the objects under start (breadth-first, hidden ones included).
std::optional< QObjectList > Sonde::anonymous_namespace{statetools.cpp}::snapshotStart (const QString &root, QString *error)
 The objects a snapshot starts from: the object root names, or the roots of the tree.
ToolResult Sonde::anonymous_namespace{statetools.cpp}::stateSnapshot (Snapshots *snapshots, const QJsonObject &args)
 The state_snapshot tool.
int Sonde::anonymous_namespace{statetools.cpp}::objectChanges (const ObjectState &before, const ObjectState &after, const QSet< QString > &ignore, QStringList *lines)
 Appends the changes of one object to lines, skipping ignore.
int Sonde::anonymous_namespace{statetools.cpp}::diffLines (const Snapshot &from, const Snapshot &to, const QSet< QString > &ignore, QStringList *lines)
 The "+", "-" and "~" lines from from to to.
const Snapshot * Sonde::anonymous_namespace{statetools.cpp}::namedSnapshot (const Snapshots *snapshots, const QJsonObject &args, const QString &key, QString *error)
 The snapshot named by the argument key, with an error listing the kept ones if there is none.
ToolResult Sonde::anonymous_namespace{statetools.cpp}::stateDiff (const Snapshots *snapshots, const QJsonObject &args)
 The state_diff tool.
void Sonde::anonymous_namespace{statetools.cpp}::installAppStatus (Server &server)
 Registers app_status, which runs on the sessions' thread.
void Sonde::anonymous_namespace{statetools.cpp}::installStallArm (Server &server)
 Registers app_stall_arm, which runs on the sessions' thread (design 0016).
void Sonde::anonymous_namespace{statetools.cpp}::installWaitUntil (Server &server)
 Registers state_wait.
void Sonde::anonymous_namespace{statetools.cpp}::installSnapshots (Server &server)
 Registers state_snapshot and state_diff.
void Sonde::installStateTools (Server &server)
 Registers state_wait, state_snapshot and state_diff on server.

Variables

constexpr int Sonde::anonymous_namespace{statetools.cpp}::kPollMs = 50
 How often state_wait checks its condition.
constexpr int Sonde::anonymous_namespace{statetools.cpp}::kDefaultTimeoutMs = 5000
 Default and longest state_wait timeout.
constexpr int Sonde::anonymous_namespace{statetools.cpp}::kMaxTimeoutMs = 60000
 See kDefaultTimeoutMs.
constexpr qsizetype Sonde::anonymous_namespace{statetools.cpp}::kMaxSnapshots = 5
 Most snapshots kept; the oldest goes when another is taken.
constexpr int Sonde::anonymous_namespace{statetools.cpp}::kDefaultSnapshotObjects = 2000
 Default and largest number of objects in a snapshot.
constexpr int Sonde::anonymous_namespace{statetools.cpp}::kMaxSnapshotObjects = 10000
 See kDefaultSnapshotObjects.
constexpr qsizetype Sonde::anonymous_namespace{statetools.cpp}::kMaxValueText = 200
 Longest property value kept in a snapshot, as JSON text.
constexpr int Sonde::anonymous_namespace{statetools.cpp}::kDefaultChanges = 200
 Default and largest number of changes state_diff lists.
constexpr int Sonde::anonymous_namespace{statetools.cpp}::kMaxChanges = 2000
 See kDefaultChanges.

Detailed Description

state_wait, state_snapshot and state_diff: waiting for and comparing application state.