LibQuicR
session_manager.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) 2026 Cisco Systems
2 // SPDX-License-Identifier: BSD-2-Clause
3 
4 #pragma once
5 
6 #include "quicr/config.h"
7 #include "quicr/session.h"
8 
9 #include <cstdint>
10 #include <functional>
11 #include <map>
12 #include <memory>
13 #include <mutex>
14 
15 namespace quicr {
16 
17  class Clock;
18  class Connection;
19  class Logger;
20  class TrackHandler;
21 
29  {
30  public:
38  struct Callbacks
39  {
41  virtual ~Callbacks() = default;
42 
45  virtual void OnNewServerSession(const std::shared_ptr<Session>& new_session);
46 
49  virtual void OnSessionRemoved(const std::shared_ptr<Session>& session);
50  };
51 
52  public:
55  SessionManager(std::shared_ptr<Logger> logger = nullptr);
56 
61  SessionManager(std::shared_ptr<Callbacks> callbacks, std::shared_ptr<Logger> logger = nullptr);
62 
67  SessionManager(std::shared_ptr<Clock> clock, std::shared_ptr<Logger> logger = nullptr);
68 
74  SessionManager(std::shared_ptr<Callbacks> callbacks,
75  std::shared_ptr<Clock> clock,
76  std::shared_ptr<Logger> logger = nullptr);
77 
80 
89  std::weak_ptr<Session> AddTransport(const ClientConfig& config,
90  std::shared_ptr<Session::ClientCallbacks> callbacks = nullptr);
91 
99  void AddTransport(const ServerConfig& config, std::shared_ptr<Session::ServerCallbacks> callbacks = nullptr);
100 
107  void AddHandler(const std::shared_ptr<Session>& session, std::shared_ptr<TrackHandler> handler);
108 
115  void RemoveHandler(const std::shared_ptr<Session>& session, const std::shared_ptr<TrackHandler>& handler);
116 
117  private:
118  std::shared_ptr<Callbacks> callbacks_;
119 
120  std::shared_ptr<Clock> clock_;
121 
122  std::shared_ptr<Logger> logger_;
123 
124  std::mutex mutex_;
125 
126  std::map<std::uint64_t, std::shared_ptr<Transport>> transports_;
127 
128  std::map<std::uint64_t, std::shared_ptr<Session>> sessions_;
129 
130  std::function<void(const std::shared_ptr<Connection>&)> on_connection_closed_;
131  };
132 
133 }
Owns transports and sessions and routes generic track handlers to a session.
Definition: session_manager.h:29
void AddHandler(const std::shared_ptr< Session > &session, std::shared_ptr< TrackHandler > handler)
Register a concrete track or namespace handler with a session.
void RemoveHandler(const std::shared_ptr< Session > &session, const std::shared_ptr< TrackHandler > &handler)
Remove a concrete track or namespace handler from a session.
SessionManager(std::shared_ptr< Logger > logger=nullptr)
Construct with default callbacks and an internally created tick service per transport.
SessionManager(std::shared_ptr< Callbacks > callbacks, std::shared_ptr< Clock > clock, std::shared_ptr< Logger > logger=nullptr)
Construct with callbacks and a shared tick service.
std::weak_ptr< Session > AddTransport(const ClientConfig &config, std::shared_ptr< Session::ClientCallbacks > callbacks=nullptr)
Create a client transport and wait for its session to be established.
SessionManager(std::shared_ptr< Clock > clock, std::shared_ptr< Logger > logger=nullptr)
Construct with default callbacks and a shared tick service.
~SessionManager()
Shut down all transports owned by the manager.
void AddTransport(const ServerConfig &config, std::shared_ptr< Session::ServerCallbacks > callbacks=nullptr)
Create and start a server transport.
SessionManager(std::shared_ptr< Callbacks > callbacks, std::shared_ptr< Logger > logger=nullptr)
Construct with callbacks and an internally created tick service per transport.
Definition: attributes.h:13
Configuration for an outbound client session.
Definition: config.h:78
Configuration for a listening server transport.
Definition: config.h:85
Notifications for sessions owned by a manager.
Definition: session_manager.h:39
virtual void OnSessionRemoved(const std::shared_ptr< Session > &session)
Notify immediately before a closed session is removed from the manager.
virtual void OnNewServerSession(const std::shared_ptr< Session > &new_session)
Notify that a server accepted and created a session.
virtual ~Callbacks()=default
Destroy the callback interface.