Sonde v1.1.0
Embeddable Model Context Protocol server for Qt applications
Loading...
Searching...
No Matches
endpoints.h
Go to the documentation of this file.
1#pragma once
2
6
7#include "project.h"
8
9#include <QtCore/QJsonObject>
10#include <QtCore/QList>
11#include <QtCore/QString>
12#include <QtCore/QStringList>
13
14#include <optional>
15#include <utility>
16
17namespace Sonde::Cli {
18
22QString realPath(const QString &path);
23
26QString resolveProgram(const QString &name, const QString &root);
27
30QString bundleBinary(const QString &path);
31
34std::optional<QString> applicationPath(const QJsonObject &config, const QString &root);
35
37bool httpReady(quint16 port);
38
40std::optional<QJsonObject> appInfoOverHttp(quint16 port);
41
44std::optional<QJsonObject> appInfoOverSocket(const QString &name);
45
48{
49public:
52 Endpoints(const QJsonObject &config, const QString &root);
53
55 QString url() const;
56
59 QList<quint16> candidatePorts() const;
60
67 bool learnPort(std::optional<qint64> pid = std::nullopt);
68
70 QStringList describe() const;
71
73 void write(const QString &path) const;
74
76 QString instance() const { return m_instance; }
78 std::optional<QString> executable() const { return m_executable; }
80 QString local() const { return m_local; }
82 quint16 port() const { return m_port; }
84 std::optional<std::pair<quint16, quint16>> portRange() const { return m_range; }
85
86private:
87 QString m_instance;
88 std::optional<QString> m_executable;
89 QString m_local;
90 quint16 m_port = 0;
91 std::optional<std::pair<quint16, quint16>> m_range;
92 bool m_confirmed = false;
93};
94
96void showEndpoint(const QJsonObject &config, const Project &project);
97
98} // namespace Sonde::Cli
QString local() const
The local socket's name, or an empty string for none.
Definition endpoints.h:80
quint16 m_port
See port().
Definition endpoints.h:90
bool learnPort(std::optional< qint64 > pid=std::nullopt)
Asks the running copy which port it took (design 0019).
Definition endpoints.cpp:330
void write(const QString &path) const
Writes them to path (endpoint.json), as the Python sonde did.
Definition endpoints.cpp:376
QString m_local
See local().
Definition endpoints.h:89
std::optional< std::pair< quint16, quint16 > > m_range
See portRange().
Definition endpoints.h:91
QString m_instance
See instance().
Definition endpoints.h:87
QString instance() const
The instance key, or an empty string if the executable wasn't found.
Definition endpoints.h:76
bool m_confirmed
Whether a running copy said m_port is its port.
Definition endpoints.h:92
std::optional< QString > executable() const
The executable's canonical path, or nothing if it wasn't found.
Definition endpoints.h:78
std::optional< QString > m_executable
See executable().
Definition endpoints.h:88
QString url() const
The MCP URL on the port, or an empty string if there is no port.
Definition endpoints.cpp:313
quint16 port() const
The HTTP port (with {instance}, the first choice until learnPort()), or 0.
Definition endpoints.h:82
QStringList describe() const
The endpoints, as sonde names them in its output.
Definition endpoints.cpp:366
std::optional< std::pair< quint16, quint16 > > portRange() const
The range {instance} chooses from, or nothing without {instance}.
Definition endpoints.h:84
QList< quint16 > candidatePorts() const
The ports the application may have taken: its first choice, then the rest of the range.
Definition endpoints.cpp:318
Endpoints(const QJsonObject &config, const QString &root)
The endpoints of config, whose paths are relative to root.
Definition endpoints.cpp:269
std::optional< QJsonObject > appInfoOverHttp(quint16 port)
app_info's structured result from the Sonde server on port port, or nothing.
Definition endpoints.cpp:219
bool httpReady(quint16 port)
Whether something accepts connections on port port of 127.0.0.1.
Definition endpoints.cpp:209
std::optional< QJsonObject > appInfoOverSocket(const QString &name)
app_info's structured result from the Sonde server on local socket name, or nothing.
Definition endpoints.cpp:238
void showEndpoint(const QJsonObject &config, const Project &project)
sonde endpoint: prints this checkout's endpoints, and writes endpoint.json.
Definition endpoints.cpp:397
QString realPath(const QString &path)
path absolute, with links resolved, as Python's os.path.realpath() gives it: canonical if it exists,...
Definition endpoints.cpp:140
QString resolveProgram(const QString &name, const QString &root)
The program name refers to, from root or PATH, or an empty string.
Definition endpoints.cpp:160
QString bundleBinary(const QString &path)
The executable inside the macOS application bundle path (a directory ending in .app),...
Definition endpoints.cpp:180
std::optional< QString > applicationPath(const QJsonObject &config, const QString &root)
The application's canonical path, as the application sees it, or nothing if it can't be found: "execu...
Definition endpoints.cpp:201
A project's files under .sonde/, and its configuration (design 0028).
Where a project keeps its files: .sonde/ at its root.
Definition project.h:16