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

The instance key and the {instance} placeholder (design 0018). More...

#include "instance_p.h"
#include "sonde_wordlist_p.h"
#include <sonde/instance.h>
#include <QtCore/QCoreApplication>
#include <QtCore/QCryptographicHash>
#include <QtCore/QDir>
#include <QtCore/QFileInfo>
#include <QtCore/QRegularExpression>
#include <QtNetwork/QTcpServer>

Namespaces

namespace  Sonde
 Embeddable Model Context Protocol server for Qt applications.

Functions

QString Sonde::Instance::canonicalPath (const QString &path)
 path as sonde computes it too: absolute, with links resolved, or empty if it doesn't exist.
QString Sonde::Instance::executablePath ()
 canonicalPath() of the application's executable.
quint64 Sonde::Instance::keyBits (const QString &path)
 The 33-bit number behind the instance key of path.
QString Sonde::Instance::expandLocal (const QString &value)
 value with {instance} replaced by the instance key.
const QRegularExpression & Sonde::Instance::anonymous_namespace{instance.cpp}::placeholder ()
 {instance} or {instance:<low>-<high>}.
std::optional< PortRange > Sonde::Instance::portRange (const QString &value, QString *error)
 The range of {instance} or {instance:<low>-<high>} in value.
std::optional< PortRange > Sonde::Instance::portRange (const QString &value, const QString &executable, QString *error)
 portRange() for the executable at executable (canonical) instead of this one: what the sonde command computes for the application it starts.
quint16 Sonde::Instance::freePort (const QHostAddress &host, const PortRange &range)
 The first port of range, from its first choice on and wrapping around, that host can listen on right now, or 0 if none.
std::optional< QString > Sonde::Instance::expandHttp (const QString &value, QString *error)
 value with {instance} or {instance:<low>-<high>} replaced by the key's first-choice port.
std::optional< QString > Sonde::Instance::expandHttp (const QString &value, const QString &executable, QString *error)
 expandHttp() for the executable at executable (canonical) instead of this one.
QString Sonde::instanceKeyFor (const QString &path)
 The instance key of the executable at path.
QString Sonde::instanceKey ()
 This build's instance key: three words, such as amber-falcon-tide.

Detailed Description

The instance key and the {instance} placeholder (design 0018).

Function Documentation

◆ canonicalPath()

QString Sonde::Instance::canonicalPath ( const QString & path)

path as sonde computes it too: absolute, with links resolved, or empty if it doesn't exist.

QFileInfo::canonicalFilePath(), and on Windows then the path Windows reports for the file (GetFinalPathNameByHandleW, as Python's realpath uses), which also expands 8.3 short names such as RUNNER~1. Used for the instance key, app_info's executable and the paths trust grants store.

◆ expandHttp()

std::optional< QString > Sonde::Instance::expandHttp ( const QString & value,
QString * error )

value with {instance} or {instance:<low>-<high>} replaced by the key's first-choice port.

Returns
The expanded value, or std::nullopt with error set if the range is invalid.

◆ freePort()

quint16 Sonde::Instance::freePort ( const QHostAddress & host,
const PortRange & range )

The first port of range, from its first choice on and wrapping around, that host can listen on right now, or 0 if none.

Tested quietly, with a throwaway QTcpServer, so taken ports print nothing (design 0019).

◆ portRange()

std::optional< PortRange > Sonde::Instance::portRange ( const QString & value,
QString * error )

The range of {instance} or {instance:<low>-<high>} in value.

Returns
The range, or std::nullopt: with error empty if there is no placeholder, set if the range is invalid.