Skip to content

Commit 9450060

Browse files
committed
refactor(internal): move core implementation headers to internal
Move non-deprecated core headers from include/kcenon/network/core/ to src/internal/core/ to reduce public API surface and hide implementation details. Changes: - Move 26 core implementation headers to src/internal/core/ - Create deprecated redirect headers for backward compatibility - Update include paths in source files - Preserve public interfaces through facade classes This change reduces the public header count by ~26 files while maintaining full backward compatibility for existing users. Closes #632
1 parent e07cba0 commit 9450060

72 files changed

Lines changed: 7703 additions & 6543 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 15 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
BSD 3-Clause License
33
4-
Copyright (c) 2024, 🍀☀🌕🌥 🌊
4+
Copyright (c) 2024, kcenon
55
All rights reserved.
66
77
Redistribution and use in source and binary forms, with or without
@@ -32,165 +32,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232

3333
#pragma once
3434

35-
#include <cstddef>
36-
#include <type_traits>
37-
38-
namespace kcenon::network {
39-
40-
/**
41-
* \brief Callback indices for messaging_client and secure_messaging_client.
42-
*
43-
* These clients use callbacks for: receive, connected, disconnected, error.
44-
*/
45-
enum class tcp_client_callback : std::size_t {
46-
receive = 0,
47-
connected = 1,
48-
disconnected = 2,
49-
error = 3
50-
};
51-
52-
/**
53-
* \brief Callback indices for messaging_server and secure_messaging_server.
54-
*
55-
* These servers use callbacks for: connection, disconnection, receive, error.
56-
*/
57-
enum class tcp_server_callback : std::size_t {
58-
connection = 0,
59-
disconnection = 1,
60-
receive = 2,
61-
error = 3
62-
};
63-
64-
/**
65-
* \brief Callback indices for messaging_udp_client.
66-
*
67-
* UDP client uses callbacks for: receive, error.
68-
*/
69-
enum class udp_client_callback : std::size_t {
70-
receive = 0,
71-
error = 1
72-
};
73-
74-
/**
75-
* \brief Callback indices for secure_messaging_udp_client.
76-
*
77-
* Secure UDP client uses callbacks for: receive, connected, disconnected, error.
78-
*/
79-
enum class secure_udp_client_callback : std::size_t {
80-
receive = 0,
81-
connected = 1,
82-
disconnected = 2,
83-
error = 3
84-
};
85-
86-
/**
87-
* \brief Callback indices for messaging_udp_server.
88-
*
89-
* UDP server uses callbacks for: receive, error.
90-
*/
91-
enum class udp_server_callback : std::size_t {
92-
receive = 0,
93-
error = 1
94-
};
95-
96-
/**
97-
* \brief Callback indices for unified_udp_messaging_client.
98-
*
99-
* Unified UDP client uses callbacks for: receive, connected, disconnected, error.
100-
* The connected/disconnected callbacks are used for DTLS handshake completion.
101-
* For plain UDP, connected is called immediately after start.
102-
*/
103-
enum class unified_udp_client_callback : std::size_t {
104-
receive = 0,
105-
connected = 1,
106-
disconnected = 2,
107-
error = 3
108-
};
109-
110-
/**
111-
* \brief Callback indices for unified_udp_messaging_server.
112-
*
113-
* Unified UDP server uses callbacks for: receive, client_connected,
114-
* client_disconnected, error.
115-
* The client_connected/client_disconnected callbacks are used for DTLS sessions.
116-
* For plain UDP, only receive and error are meaningful.
117-
*/
118-
enum class unified_udp_server_callback : std::size_t {
119-
receive = 0,
120-
client_connected = 1,
121-
client_disconnected = 2,
122-
error = 3
123-
};
124-
125-
/**
126-
* \brief Callback indices for messaging_ws_client.
127-
*
128-
* WebSocket client uses callbacks for: message, text_message, binary_message,
129-
* connected, disconnected, error.
130-
*/
131-
enum class ws_client_callback : std::size_t {
132-
message = 0,
133-
text_message = 1,
134-
binary_message = 2,
135-
connected = 3,
136-
disconnected = 4,
137-
error = 5
138-
};
139-
140-
/**
141-
* \brief Callback indices for messaging_ws_server.
142-
*
143-
* WebSocket server uses callbacks for: connection, disconnection, message,
144-
* text_message, binary_message, error.
145-
*/
146-
enum class ws_server_callback : std::size_t {
147-
connection = 0,
148-
disconnection = 1,
149-
message = 2,
150-
text_message = 3,
151-
binary_message = 4,
152-
error = 5
153-
};
154-
155-
/**
156-
* \brief Callback indices for messaging_quic_client.
157-
*
158-
* QUIC client uses callbacks for: receive, stream_receive, connected,
159-
* disconnected, error.
160-
*/
161-
enum class quic_client_callback : std::size_t {
162-
receive = 0,
163-
stream_receive = 1,
164-
connected = 2,
165-
disconnected = 3,
166-
error = 4
167-
};
168-
169-
/**
170-
* \brief Callback indices for messaging_quic_server.
171-
*
172-
* QUIC server uses callbacks for: connection, disconnection, receive,
173-
* stream_receive, error.
174-
*/
175-
enum class quic_server_callback : std::size_t {
176-
connection = 0,
177-
disconnection = 1,
178-
receive = 2,
179-
stream_receive = 3,
180-
error = 4
181-
};
182-
183-
/**
184-
* \brief Helper to convert enum to std::size_t for callback_manager access.
185-
* \tparam E The enum type.
186-
* \param e The enum value.
187-
* \return The underlying std::size_t value.
188-
*/
189-
template <typename E>
190-
constexpr auto to_index(E e) noexcept -> std::size_t
191-
{
192-
static_assert(std::is_enum_v<E>, "to_index requires an enum type");
193-
return static_cast<std::size_t>(e);
194-
}
195-
196-
} // namespace kcenon::network
35+
// DEPRECATED: This header location is deprecated.
36+
// Please use facade headers for new code.
37+
#ifndef NETWORK_SYSTEM_SUPPRESS_DEPRECATION_WARNINGS
38+
#if defined(__GNUC__) || defined(__clang__)
39+
#pragma message("DEPRECATED: include path 'kcenon/network/core/callback_indices.h' is deprecated. " \
40+
"Use facade headers instead.")
41+
#elif defined(_MSC_VER)
42+
#pragma message("DEPRECATED: include path 'kcenon/network/core/callback_indices.h' is deprecated. " \
43+
"Use facade headers instead.")
44+
#endif
45+
#endif
46+
47+
// Include internal header for backward compatibility
48+
#include "internal/core/callback_indices.h"
Lines changed: 15 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*****************************************************************************
22
BSD 3-Clause License
33
4-
Copyright (c) 2024, 🍀☀🌕🌥 🌊
4+
Copyright (c) 2024, kcenon
55
All rights reserved.
66
77
Redistribution and use in source and binary forms, with or without
@@ -32,128 +32,17 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232

3333
#pragma once
3434

35-
#include <atomic>
36-
#include <condition_variable>
37-
#include <memory>
38-
#include <mutex>
39-
#include <queue>
40-
#include <string>
41-
42-
#include "kcenon/network/core/messaging_client.h"
43-
#include "kcenon/network/utils/result_types.h"
44-
45-
namespace kcenon::network::core
46-
{
47-
48-
/*!
49-
* \class connection_pool
50-
* \brief Manages a pool of reusable client connections to reduce
51-
* connection overhead and improve performance.
52-
*
53-
* ### Key Features
54-
* - Pre-creates a fixed number of connections at initialization
55-
* - Provides thread-safe acquire/release semantics for borrowing connections
56-
* - Blocks when all connections are in use until one becomes available
57-
* - Automatically reconnects clients if connection is lost
58-
* - Tracks active connection count for monitoring
59-
*
60-
* ### Thread Safety
61-
* - All public methods are thread-safe
62-
* - Uses mutex and condition variable for synchronization
63-
* - Multiple threads can safely acquire/release connections concurrently
64-
*
65-
* ### Usage Example
66-
* \code
67-
* auto pool = std::make_shared<connection_pool>("localhost", 5555, 10);
68-
* auto result = pool->initialize();
69-
* if (!result) {
70-
* std::cerr << "Failed to initialize pool\n";
71-
* return;
72-
* }
73-
*
74-
* // Acquire a connection
75-
* auto client = pool->acquire();
76-
* client->send_packet(data);
77-
*
78-
* // Release back to pool when done
79-
* pool->release(std::move(client));
80-
* \endcode
81-
*/
82-
class connection_pool
83-
{
84-
public:
85-
/*!
86-
* \brief Constructs a connection pool.
87-
* \param host The remote host to connect to
88-
* \param port The remote port to connect to
89-
* \param pool_size Number of connections to maintain in the pool (default: 10)
90-
*/
91-
connection_pool(std::string host, unsigned short port,
92-
size_t pool_size = 10);
93-
94-
/*!
95-
* \brief Destructor. Stops all connections and cleans up resources.
96-
*/
97-
~connection_pool() noexcept;
98-
99-
/*!
100-
* \brief Initializes the pool by creating and connecting all clients.
101-
* \return Result<void> - Success if all connections established, or error
102-
*
103-
* This method should be called after construction and before using the pool.
104-
* It pre-creates all connections to avoid latency on first use.
105-
*/
106-
auto initialize() -> VoidResult;
107-
108-
/*!
109-
* \brief Acquires a connection from the pool.
110-
* \return A unique_ptr to messaging_client
111-
*
112-
* This method blocks if no connections are available until one is released.
113-
* The acquired connection is guaranteed to be connected and ready to use.
114-
*/
115-
auto acquire() -> std::unique_ptr<messaging_client>;
116-
117-
/*!
118-
* \brief Releases a connection back to the pool.
119-
* \param client The client to return to the pool
120-
*
121-
* The client is checked for connectivity and reconnected if necessary
122-
* before being returned to the available queue.
123-
*/
124-
auto release(std::unique_ptr<messaging_client> client) -> void;
125-
126-
/*!
127-
* \brief Gets the number of active (borrowed) connections.
128-
* \return Number of connections currently in use
129-
*/
130-
[[nodiscard]] auto active_count() const noexcept -> size_t
131-
{
132-
return active_count_.load(std::memory_order_relaxed);
133-
}
134-
135-
/*!
136-
* \brief Gets the total pool size.
137-
* \return Total number of connections in the pool
138-
*/
139-
[[nodiscard]] auto pool_size() const noexcept -> size_t
140-
{
141-
return pool_size_;
142-
}
143-
144-
private:
145-
std::string host_; /*!< Remote host to connect to */
146-
unsigned short port_; /*!< Remote port to connect to */
147-
size_t pool_size_; /*!< Total number of connections */
148-
149-
std::queue<std::unique_ptr<messaging_client>> available_;
150-
/*!< Available connections */
151-
std::atomic<size_t> active_count_{0};
152-
/*!< Active connection count */
153-
std::mutex mutex_; /*!< Protects available_ queue */
154-
std::condition_variable cv_; /*!< Signals when connection available */
155-
std::atomic<bool> is_shutdown_{false};
156-
/*!< Shutdown flag */
157-
};
158-
159-
} // namespace kcenon::network::core
35+
// DEPRECATED: This header location is deprecated.
36+
// Please use facade headers for new code.
37+
#ifndef NETWORK_SYSTEM_SUPPRESS_DEPRECATION_WARNINGS
38+
#if defined(__GNUC__) || defined(__clang__)
39+
#pragma message("DEPRECATED: include path 'kcenon/network/core/connection_pool.h' is deprecated. " \
40+
"Use facade headers instead.")
41+
#elif defined(_MSC_VER)
42+
#pragma message("DEPRECATED: include path 'kcenon/network/core/connection_pool.h' is deprecated. " \
43+
"Use facade headers instead.")
44+
#endif
45+
#endif
46+
47+
// Include internal header for backward compatibility
48+
#include "internal/core/connection_pool.h"

0 commit comments

Comments
 (0)