LibQuicR
publish_namespace_handler.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) 2024 Cisco Systems
2 // SPDX-License-Identifier: BSD-2-Clause
3 
4 #pragma once
5 
6 #include "quicr/errors.h"
8 #include "quicr/track_name.h"
9 
10 #include <map>
11 #include <memory>
12 
13 namespace quicr {
14 
15  class Session;
16 
24  {
25  public:
29  enum class Status : uint8_t
30  {
31  kOk = 0,
36  kSendingDone,
37  kError,
38  };
39 
40  protected:
46 
55  virtual void StatusChanged(Status status);
56 
57  public:
63  static auto Create(const TrackNamespace& prefix)
64  {
65  return std::shared_ptr<PublishNamespaceHandler>(new PublishNamespaceHandler(prefix));
66  }
67 
73 
86  virtual void PublishTrack(std::shared_ptr<PublishTrackHandler> handler);
87 
93  virtual void UnPublishTrack(std::shared_ptr<PublishTrackHandler> handler);
94 
112  uint64_t track_alias,
113  const ObjectHeaders& object_headers,
114  BytesSpan data,
115  std::optional<messages::StreamHeaderProperties> stream_mode = std::nullopt);
116 
134  [[maybe_unused]] uint64_t track_alias,
135  [[maybe_unused]] bool is_new_stream,
136  [[maybe_unused]] uint64_t group_id,
137  [[maybe_unused]] uint64_t subgroup_id,
138  [[maybe_unused]] std::shared_ptr<const std::vector<uint8_t>> data)
139  {
141  }
142 
144  const TrackNamespace& GetPrefix() const noexcept { return prefix_; }
145 
151  constexpr Status GetStatus() const noexcept { return status_; }
152 
157  std::optional<Error<ErrorCode>> GetError() const noexcept { return error_; }
158 
159  protected:
166  void SetStatus(const Status status) noexcept
167  {
168  status_ = status;
169  if (status == Status::kError && !error_.has_value()) {
170  error_ = Error<ErrorCode>{ ErrorCode::kInternalError, "Unknown error" };
171  }
172 
173  StatusChanged(status);
174  }
175 
180  void SetError(const Error<ErrorCode>& error)
181  {
182  error_ = error;
184  }
185 
190  void RequestOkReceived(const messages::Parameters& params) override;
191 
199 
205  void RequestError(ErrorCode error_code, std::string reason) override
206  {
207  SetError(Error<ErrorCode>{ error_code, std::move(reason) });
208  }
209 
216  std::map<std::uint64_t, std::shared_ptr<PublishTrackHandler>> handlers_;
217 
218  private:
219  const TrackNamespace prefix_;
220 
221  Status status_{ Status::kNotPublished };
222 
223  std::optional<Error<ErrorCode>> error_{};
224 
225  friend class Session;
226  };
227 }
Publishes and manages tracks below one namespace prefix.
Definition: publish_namespace_handler.h:24
static auto Create(const TrackNamespace &prefix)
Creates a namespace publisher with shared ownership.
Definition: publish_namespace_handler.h:63
Reply< messages::Parameters, ErrorCode > RequestUpdateReceived(const messages::Parameters &params) override
Rejects updates to a namespace publication.
constexpr Status GetStatus() const noexcept
Get the status of the Publish.
Definition: publish_namespace_handler.h:151
virtual void PublishTrack(std::shared_ptr< PublishTrackHandler > handler)
Publish a new track.
const TrackNamespace & GetPrefix() const noexcept
Definition: publish_namespace_handler.h:144
void SetError(const Error< ErrorCode > &error)
Stores an error and transitions to kError.
Definition: publish_namespace_handler.h:180
virtual void UnPublishTrack(std::shared_ptr< PublishTrackHandler > handler)
Removes and unpublishes a track.
void SetStatus(const Status status) noexcept
Set the Publish status.
Definition: publish_namespace_handler.h:166
Status
Status codes for the Publish track.
Definition: publish_namespace_handler.h:30
@ kNotPublished
Initial/inactive state.
@ kPublishNotAuthorized
Peer denied publication.
@ kNotConnected
Session transport is disconnected.
@ kPendingResponse
Waiting for the peer's response.
@ kSendingDone
In this state, callbacks will not be called.
@ kError
Request failed; inspect GetError().
@ kOk
Namespace is accepted and active.
std::optional< Error< ErrorCode > > GetError() const noexcept
Get the error code and reason for the Publish namespace, if any.
Definition: publish_namespace_handler.h:157
virtual ~PublishNamespaceHandler()
Unpublishes all retained tracks when an attached session still exists.
void RequestOkReceived(const messages::Parameters &params) override
Handles peer acceptance by entering kOk.
std::map< std::uint64_t, std::shared_ptr< PublishTrackHandler > > handlers_
Track publishers keyed by the full-track-name hash.
Definition: publish_namespace_handler.h:216
virtual PublishTrackHandler::PublishObjectStatus PublishObject(uint64_t track_alias, const ObjectHeaders &object_headers, BytesSpan data, std::optional< messages::StreamHeaderProperties > stream_mode=std::nullopt)
Passthrough PublishObject to Publish Track matching full name hash.
virtual void StatusChanged(Status status)
Notification of Publish status.
void RequestError(ErrorCode error_code, std::string reason) override
Stores a request error and enters kError.
Definition: publish_namespace_handler.h:205
virtual PublishTrackHandler::PublishObjectStatus ForwardPublishedData([[maybe_unused]] uint64_t track_alias, [[maybe_unused]] bool is_new_stream, [[maybe_unused]] uint64_t group_id, [[maybe_unused]] uint64_t subgroup_id, [[maybe_unused]] std::shared_ptr< const std::vector< uint8_t >> data)
Passthrough to Forward received object data to each publish handler.
Definition: publish_namespace_handler.h:133
PublishNamespaceHandler(const TrackNamespace &prefix)
Constructs an inactive namespace publisher.
PublishObjectStatus
Publish status codes.
Definition: publish_track_handler.h:31
@ kInternalError
Required session/stream state was unavailable or invalid.
The reply to a callback, which may be answered immediately or deferred.
Definition: reply.h:31
MoQ Session endpoint supporting connection-explicit operations.
Definition: session.h:68
Common request state for track-related handlers.
Definition: track_handler.h:36
An N-tuple representation of a MOQ namespace.
Definition: track_name.h:22
Definition: parameters.h:185
Definition: attributes.h:13
std::span< const Byte > BytesSpan
Non-owning, read-only view of contiguous bytes.
Definition: bytes.h:21
ErrorCode
MOQT error code, as carried by REQUEST_ERROR.
Definition: errors.h:33
@ kInternalError
The endpoint encountered an unspecified internal failure.
A rejected result, holding why the request was rejected.
Definition: errors.h:21
Object headers struct.
Definition: object.h:49