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

Private: the {instance} placeholder in SONDE_LOCAL and SONDE_HTTP (design 0018). More...

#include <sonde/sonde_core_export.h>
#include <QtCore/QString>
#include <QtNetwork/QHostAddress>
#include <optional>

Go to the source code of this file.

Classes

struct  Sonde::Instance::PortRange
 The ports {instance} in a SONDE_HTTP value may use, and the first choice. More...

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.
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.

Variables

constexpr quint16 Sonde::Instance::kDefaultPortLow = 28600
 The first port of the default {instance} range (design 0019: away from common development ports, below the ephemeral and NodePort ranges).
constexpr quint16 Sonde::Instance::kDefaultPortHigh = 29599
 The last port of the default {instance} range.

Detailed Description

Private: the {instance} placeholder in SONDE_LOCAL and SONDE_HTTP (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.