Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
session_concept.h
Go to the documentation of this file.
1/*****************************************************************************
2BSD 3-Clause License
3
4Copyright (c) 2025, kcenon
5All rights reserved.
6*****************************************************************************/
7
8#pragma once
9
11
12#include <chrono>
13#include <cstdint>
14#include <memory>
15#include <string>
16#include <string_view>
17#include <typeinfo>
18#include <vector>
19
20namespace kcenon::network::core {
21
22// Import VoidResult from network namespace for convenience
24
57public:
58 virtual ~session_concept() = default;
59
60 // Non-copyable (managed via unique_ptr)
63
64 // Movable
67
68 // =========================================================================
69 // Core Session Operations
70 // =========================================================================
71
76 [[nodiscard]] virtual auto id() const -> std::string_view = 0;
77
82 [[nodiscard]] virtual auto is_connected() const -> bool = 0;
83
89 [[nodiscard]] virtual auto send(std::vector<uint8_t>&& data)
90 -> VoidResult = 0;
91
95 virtual auto close() -> void = 0;
96
103 virtual auto stop() -> void = 0;
104
105 // =========================================================================
106 // Type Information
107 // =========================================================================
108
113 [[nodiscard]] virtual auto type() const noexcept -> const std::type_info& = 0;
114
122 [[nodiscard]] virtual auto get_raw() noexcept -> void* = 0;
123
128 [[nodiscard]] virtual auto get_raw() const noexcept -> const void* = 0;
129
130 // =========================================================================
131 // Activity Tracking (optional, based on traits)
132 // =========================================================================
133
138 [[nodiscard]] virtual auto has_activity_tracking() const noexcept -> bool = 0;
139
146 [[nodiscard]] virtual auto created_at() const
147 -> std::chrono::steady_clock::time_point = 0;
148
155 [[nodiscard]] virtual auto last_activity() const
156 -> std::chrono::steady_clock::time_point = 0;
157
163 virtual auto update_activity() -> void = 0;
164
169 [[nodiscard]] virtual auto idle_duration() const -> std::chrono::milliseconds = 0;
170
171protected:
172 session_concept() = default;
173};
174
175} // namespace kcenon::network::core
Type-erased interface for session management.
virtual auto last_activity() const -> std::chrono::steady_clock::time_point=0
Gets the last activity timestamp.
virtual auto close() -> void=0
Closes the session.
session_concept & operator=(session_concept &&)=default
virtual auto stop() -> void=0
Stops the session (alias for protocol-specific implementations)
virtual auto has_activity_tracking() const noexcept -> bool=0
Checks if this session type supports activity tracking.
virtual auto created_at() const -> std::chrono::steady_clock::time_point=0
Gets the creation timestamp.
virtual auto id() const -> std::string_view=0
Gets the session's unique identifier.
session_concept(session_concept &&)=default
virtual auto type() const noexcept -> const std::type_info &=0
Gets the runtime type information of the wrapped session.
virtual auto send(std::vector< uint8_t > &&data) -> VoidResult=0
Sends data through the session.
virtual auto get_raw() noexcept -> void *=0
Gets a raw pointer to the underlying session.
virtual auto is_connected() const -> bool=0
Checks if the session is currently connected.
virtual auto idle_duration() const -> std::chrono::milliseconds=0
Calculates idle duration since last activity.
virtual auto update_activity() -> void=0
Updates the last activity timestamp to current time.
session_concept(const session_concept &)=delete
session_concept & operator=(const session_concept &)=delete
Network-specific error and result type definitions.