Pulp 1.88.0
Cross-platform audio plugin framework
Loading...
Searching...
No Matches
control_service.hpp
Go to the documentation of this file.
1#pragma once
2
5
6#include <functional>
7#include <memory>
8#include <mutex>
9#include <optional>
10#include <string>
11#include <string_view>
12#include <unordered_map>
13
14namespace pulp::inspect {
15
25
27
30 std::optional<ControlEnvelope> response;
31 std::optional<ControlAdmissionStatus> admission_status;
32 std::string explanation;
33};
34
38
45 public:
47 using ProgressSink = std::function<bool(const ControlProgressEnvelope&)>;
49
50 explicit ControlService(ControlBroker& broker, Executor executor = {},
51 ControlServiceConfig config = {});
53
57 class Session {
58 public:
60 Session(const Session&) = delete;
61 Session& operator=(const Session&) = delete;
62 Session(Session&& other) noexcept;
63 Session& operator=(Session&& other) noexcept;
64
65 bool is_open() const {
66 return broker_ != nullptr;
67 }
68 const ControlClientId& client_id() const {
69 return client_id_;
70 }
72 return peer_;
73 }
74
75 ControlServiceResult dispatch(std::string_view encoded_envelope);
77 ControlArtifactReadResult read_artifact(std::string_view artifact_id, std::uint64_t offset,
78 std::size_t maximum_bytes);
79
80 private:
81 friend class ControlService;
83 ControlClientId client_id, ProgressSink progress_sink, bool accepted,
84 bool disconnect_client_on_close)
85 : service_(&service), broker_(accepted ? &service.broker_ : nullptr),
86 peer_(std::move(peer)), client_id_(std::move(client_id)),
87 progress_sink_(std::move(progress_sink)),
88 disconnect_client_on_close_(disconnect_client_on_close) {}
89
90 void close() noexcept;
91
92 ControlService* service_ = nullptr;
93 ControlBroker* broker_ = nullptr;
95 ControlClientId client_id_;
96 ProgressSink progress_sink_;
97 bool disconnect_client_on_close_ = true;
98 std::optional<std::vector<std::string>> negotiated_features_;
99 };
100
102 const ControlClientId& connection_client_id,
103 ProgressSink progress_sink = {},
104 bool disconnect_client_on_close = true);
105
106 bool is_listening() const {
107 return false;
108 }
109
110 private:
111 struct CompletionOwner {
112 std::mutex mutex;
113 ControlBroker* broker = nullptr;
114 // The owner mutex is the teardown fence: callbacks hold it across
115 // broker settlement, and destruction terminalizes these entries before
116 // detaching the broker.
117 std::unordered_map<std::string, std::function<void(ControlBroker&)>> deferred_operations;
118 };
119
120 ControlServiceResult dispatch(Session& session, std::string_view encoded_envelope);
121 ControlServiceResult dispatch_request(Session& session, const ControlRequestEnvelope& request);
122 ControlArtifactReadResult read_artifact(Session& session, std::string_view artifact_id,
123 std::uint64_t offset, std::size_t maximum_bytes);
124
125 ControlBroker& broker_;
126 Executor executor_;
127 ControlServiceConfig config_;
128 std::shared_ptr<CompletionOwner> completion_owner_;
129};
130
131} // namespace pulp::inspect
Dormant composition root for the local capability-control broker.
Definition control_broker.hpp:45
Carrier-owned state for exactly one authenticated local connection.
Definition control_service.hpp:57
Session(Session &&other) noexcept
const VerifiedControlPeerIdentity & peer() const
Definition control_service.hpp:71
ControlServiceResult dispatch(std::string_view encoded_envelope)
Session & operator=(const Session &)=delete
bool is_open() const
Definition control_service.hpp:65
ControlArtifactReadResult read_artifact(std::string_view artifact_id, std::uint64_t offset, std::size_t maximum_bytes)
Reads only artifacts produced by this connection-bound client ID.
Session & operator=(Session &&other) noexcept
friend class ControlService
Definition control_service.hpp:81
const ControlClientId & client_id() const
Definition control_service.hpp:68
Session open_session(const VerifiedControlPeerIdentity &peer, const ControlClientId &connection_client_id, ProgressSink progress_sink={}, bool disconnect_client_on_close=true)
std::function< bool(const ControlProgressEnvelope &)> ProgressSink
Definition control_service.hpp:47
ControlService(ControlBroker &broker, Executor executor={}, ControlServiceConfig config={})
bool is_listening() const
Definition control_service.hpp:106
ControlOperationExecutor Executor
Definition control_service.hpp:48
ControlProgressReporter ProgressReporter
Definition control_service.hpp:46
Copyable proof minted only by the broker's trusted OS peer verifier.
Definition control_identity.hpp:63
Definition agent_context.hpp:7
ControlServiceStatus
Definition control_service.hpp:16
@ ReceiptTransitionFailed
Definition control_service.hpp:21
@ InvalidEnvelope
Definition control_service.hpp:18
@ NegotiationRequired
Definition control_service.hpp:22
@ UnsupportedMessage
Definition control_service.hpp:19
@ Responded
Definition control_service.hpp:17
@ AdmissionDenied
Definition control_service.hpp:20
std::function< bool(std::uint64_t current, std::uint64_t total, std::string detail_json)> ControlProgressReporter
Definition control_execution.hpp:23
std::string_view control_service_status_id(ControlServiceStatus status)
@ ResourceExhausted
Definition control_admission.hpp:26
std::function< ControlExecutionOutcome( const ControlAdmissionPlan &, const ControlRequestEnvelope &, const ControlExecutionContext &)> ControlOperationExecutor
Trusted in-process adapter contract.
Definition control_execution.hpp:56
STL namespace.
Definition control_artifacts.hpp:146
Definition control_identity.hpp:28
A bounded progress observation for one admitted operation.
Definition control_protocol.hpp:109
Definition control_service.hpp:35
std::size_t maximum_progress_events_per_operation
Definition control_service.hpp:36
Definition control_service.hpp:28
std::string explanation
Definition control_service.hpp:32
std::optional< ControlAdmissionStatus > admission_status
Definition control_service.hpp:31
std::optional< ControlEnvelope > response
Definition control_service.hpp:30
ControlServiceStatus status
Definition control_service.hpp:29