Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
kcenon::network::integration::NetworkSystemBridge Class Reference

Unified facade for all network_system integration bridges. More...

#include <network_system_bridge.h>

Collaboration diagram for kcenon::network::integration::NetworkSystemBridge:
Collaboration graph

Classes

class  Impl
 

Public Member Functions

 NetworkSystemBridge ()
 Default constructor.
 
 NetworkSystemBridge (std::shared_ptr< ThreadPoolBridge > thread_pool)
 Construct bridge with custom thread pool.
 
 ~NetworkSystemBridge ()
 Destructor.
 
 NetworkSystemBridge (const NetworkSystemBridge &)=delete
 
NetworkSystemBridgeoperator= (const NetworkSystemBridge &)=delete
 
 NetworkSystemBridge (NetworkSystemBridge &&) noexcept
 
NetworkSystemBridgeoperator= (NetworkSystemBridge &&) noexcept
 
VoidResult initialize (const NetworkSystemBridgeConfig &config)
 Initialize all configured bridges.
 
VoidResult shutdown ()
 Shutdown all bridges.
 
bool is_initialized () const
 Check if the bridge is initialized.
 
BridgeMetrics get_metrics () const
 Get aggregated metrics from all bridges.
 
std::shared_ptr< ThreadPoolBridgeget_thread_pool_bridge () const
 Get thread pool bridge.
 
std::shared_ptr< thread_pool_interfaceget_thread_pool () const
 Get thread pool interface.
 
std::shared_ptr< logger_interfaceget_logger () const
 Get logger interface.
 
std::shared_ptr< monitoring_interfaceget_monitoring () const
 Get monitoring interface.
 
VoidResult set_thread_pool_bridge (std::shared_ptr< ThreadPoolBridge > bridge)
 Set custom thread pool bridge.
 
VoidResult set_logger (std::shared_ptr< logger_interface > logger)
 Set custom logger.
 
VoidResult set_monitoring (std::shared_ptr< monitoring_interface > monitoring)
 Set custom monitoring.
 

Static Public Member Functions

static std::shared_ptr< NetworkSystemBridgecreate_default ()
 Create bridge with default configuration.
 
static std::shared_ptr< NetworkSystemBridgewith_thread_system (const std::string &pool_name="network_pool")
 Create bridge with thread_system integration.
 
static std::shared_ptr< NetworkSystemBridgewith_custom (std::shared_ptr< thread_pool_interface > thread_pool=nullptr, std::shared_ptr< logger_interface > logger=nullptr, std::shared_ptr< monitoring_interface > monitoring=nullptr)
 Create bridge with custom components.
 

Private Attributes

std::unique_ptr< Implpimpl_
 

Detailed Description

Unified facade for all network_system integration bridges.

This class provides a single entry point for managing all external system integrations in network_system. It consolidates thread pool, logger, and monitoring integrations into a unified interface.

Key Features:

  • Single initialization point for all integrations
  • Factory methods for common scenarios
  • Thread-safe access to bridge components
  • Centralized lifecycle management
  • Metrics aggregation from all bridges

Lifecycle:

  1. Create using factory method or direct constructor
  2. Call initialize() with configuration
  3. Access bridge components via getters
  4. Call shutdown() before destruction

Thread Safety:

  • All public methods are thread-safe
  • initialize() and shutdown() can be called from multiple threads
  • Getters are thread-safe after initialization

Definition at line 149 of file network_system_bridge.h.

Constructor & Destructor Documentation

◆ NetworkSystemBridge() [1/4]

kcenon::network::integration::NetworkSystemBridge::NetworkSystemBridge ( )

Default constructor.

Creates a bridge with default settings. All integrations are disabled until explicitly configured and initialized.

Definition at line 206 of file network_system_bridge.cpp.

207 : pimpl_(std::make_unique<Impl>()) {
208}

◆ NetworkSystemBridge() [2/4]

kcenon::network::integration::NetworkSystemBridge::NetworkSystemBridge ( std::shared_ptr< ThreadPoolBridge > thread_pool)
explicit

Construct bridge with custom thread pool.

Parameters
thread_poolThread pool bridge to use

Creates a bridge with a specific thread pool bridge. Other integrations can be added via set_* methods.

Definition at line 210 of file network_system_bridge.cpp.

211 : pimpl_(std::make_unique<Impl>()) {
212 pimpl_->set_thread_pool_bridge(std::move(thread_pool));
213}

References pimpl_.

◆ ~NetworkSystemBridge()

kcenon::network::integration::NetworkSystemBridge::~NetworkSystemBridge ( )
default

Destructor.

Automatically calls shutdown() if initialized

◆ NetworkSystemBridge() [3/4]

kcenon::network::integration::NetworkSystemBridge::NetworkSystemBridge ( const NetworkSystemBridge & )
delete

◆ NetworkSystemBridge() [4/4]

kcenon::network::integration::NetworkSystemBridge::NetworkSystemBridge ( NetworkSystemBridge && )
defaultnoexcept

Member Function Documentation

◆ create_default()

std::shared_ptr< NetworkSystemBridge > kcenon::network::integration::NetworkSystemBridge::create_default ( )
static

Create bridge with default configuration.

Returns
Shared pointer to NetworkSystemBridge

Creates a bridge with:

  • Thread pool from thread_system (if available)
  • Default logger (disabled)
  • Default monitoring (disabled)

Example:

bridge->initialize(config);
static std::shared_ptr< NetworkSystemBridge > create_default()
Create bridge with default configuration.
tracing_config config
Definition exporters.cpp:29

Definition at line 311 of file network_system_bridge.cpp.

311 {
312 auto bridge = std::make_shared<NetworkSystemBridge>();
313
314 // Try to create thread pool from thread_system if available
315#if KCENON_WITH_THREAD_SYSTEM
316 auto thread_pool_bridge = ThreadPoolBridge::from_thread_system("network_pool");
317 bridge->set_thread_pool_bridge(thread_pool_bridge);
318#endif
319
320 return bridge;
321}
static std::shared_ptr< ThreadPoolBridge > from_thread_system(const std::string &pool_name="network_pool")
Create bridge from thread_system.

References kcenon::network::integration::ThreadPoolBridge::from_thread_system().

Here is the call graph for this function:

◆ get_logger()

std::shared_ptr< logger_interface > kcenon::network::integration::NetworkSystemBridge::get_logger ( ) const

Get logger interface.

Returns
Shared pointer to logger, or nullptr if not configured

Definition at line 265 of file network_system_bridge.cpp.

265 {
266 if (!pimpl_) {
267 return nullptr;
268 }
269 return pimpl_->get_logger();
270}

References pimpl_.

◆ get_metrics()

BridgeMetrics kcenon::network::integration::NetworkSystemBridge::get_metrics ( ) const

Get aggregated metrics from all bridges.

Returns
Aggregated bridge metrics

Returns combined metrics from all initialized bridges. Custom metrics from each bridge are prefixed with the bridge name.

Definition at line 244 of file network_system_bridge.cpp.

244 {
245 if (!pimpl_) {
246 return BridgeMetrics{};
247 }
248 return pimpl_->get_metrics();
249}

References pimpl_.

◆ get_monitoring()

std::shared_ptr< monitoring_interface > kcenon::network::integration::NetworkSystemBridge::get_monitoring ( ) const

Get monitoring interface.

Returns
Shared pointer to monitoring, or nullptr if not configured

Definition at line 272 of file network_system_bridge.cpp.

272 {
273 if (!pimpl_) {
274 return nullptr;
275 }
276 return pimpl_->get_monitoring();
277}

References pimpl_.

◆ get_thread_pool()

std::shared_ptr< thread_pool_interface > kcenon::network::integration::NetworkSystemBridge::get_thread_pool ( ) const

Get thread pool interface.

Returns
Shared pointer to thread pool, or nullptr if not configured

Convenience method equivalent to:

return bridge ? bridge->get_thread_pool() : nullptr;
std::shared_ptr< ThreadPoolBridge > get_thread_pool_bridge() const
Get thread pool bridge.

Definition at line 258 of file network_system_bridge.cpp.

258 {
259 if (!pimpl_) {
260 return nullptr;
261 }
262 return pimpl_->get_thread_pool();
263}

References pimpl_.

◆ get_thread_pool_bridge()

std::shared_ptr< ThreadPoolBridge > kcenon::network::integration::NetworkSystemBridge::get_thread_pool_bridge ( ) const

Get thread pool bridge.

Returns
Shared pointer to thread pool bridge, or nullptr if not configured

Definition at line 251 of file network_system_bridge.cpp.

251 {
252 if (!pimpl_) {
253 return nullptr;
254 }
255 return pimpl_->get_thread_pool_bridge();
256}

References pimpl_.

◆ initialize()

VoidResult kcenon::network::integration::NetworkSystemBridge::initialize ( const NetworkSystemBridgeConfig & config)

Initialize all configured bridges.

Parameters
configConfiguration for all bridges
Returns
ok() on success, error_info on failure

Initializes all enabled bridges according to the configuration. If any bridge fails to initialize, all previously initialized bridges are shut down and an error is returned.

Error Conditions:

  • Already initialized
  • Bridge initialization failure
  • Invalid configuration

Example:

config.enable_thread_pool = true;
config.thread_pool_properties["pool_name"] = "network_pool";
auto result = bridge->initialize(config);
if (result.is_err()) {
std::cerr << "Init failed: " << result.error().message << std::endl;
}

Definition at line 220 of file network_system_bridge.cpp.

220 {
221 if (!pimpl_) {
222 return error_void(
224 "Bridge has been moved",
225 "NetworkSystemBridge::initialize");
226 }
227 return pimpl_->initialize(config);
228}
VoidResult error_void(int code, const std::string &message, const std::string &source="network_system", const std::string &details="")

References config, kcenon::network::error_void(), and kcenon::network::error_codes::common_errors::not_initialized.

Here is the call graph for this function:

◆ is_initialized()

bool kcenon::network::integration::NetworkSystemBridge::is_initialized ( ) const

Check if the bridge is initialized.

Returns
true if initialized and ready, false otherwise

Definition at line 237 of file network_system_bridge.cpp.

237 {
238 if (!pimpl_) {
239 return false;
240 }
241 return pimpl_->is_initialized();
242}

References pimpl_.

◆ operator=() [1/2]

NetworkSystemBridge & kcenon::network::integration::NetworkSystemBridge::operator= ( const NetworkSystemBridge & )
delete

◆ operator=() [2/2]

NetworkSystemBridge & kcenon::network::integration::NetworkSystemBridge::operator= ( NetworkSystemBridge && )
defaultnoexcept

◆ set_logger()

VoidResult kcenon::network::integration::NetworkSystemBridge::set_logger ( std::shared_ptr< logger_interface > logger)

Set custom logger.

Parameters
loggerLogger implementation to use
Returns
ok() on success, error_info on failure

Sets a custom logger. Must be called before initialize().

Definition at line 289 of file network_system_bridge.cpp.

289 {
290 if (!pimpl_) {
291 return error_void(
293 "Bridge has been moved",
294 "NetworkSystemBridge::set_logger");
295 }
296 return pimpl_->set_logger(std::move(logger));
297}

References kcenon::network::error_void(), kcenon::network::error_codes::common_errors::not_initialized, and pimpl_.

Here is the call graph for this function:

◆ set_monitoring()

VoidResult kcenon::network::integration::NetworkSystemBridge::set_monitoring ( std::shared_ptr< monitoring_interface > monitoring)

Set custom monitoring.

Parameters
monitoringMonitoring implementation to use
Returns
ok() on success, error_info on failure

Sets a custom monitoring implementation. Must be called before initialize().

Definition at line 299 of file network_system_bridge.cpp.

299 {
300 if (!pimpl_) {
301 return error_void(
303 "Bridge has been moved",
304 "NetworkSystemBridge::set_monitoring");
305 }
306 return pimpl_->set_monitoring(std::move(monitoring));
307}

References kcenon::network::error_void(), kcenon::network::error_codes::common_errors::not_initialized, and pimpl_.

Here is the call graph for this function:

◆ set_thread_pool_bridge()

VoidResult kcenon::network::integration::NetworkSystemBridge::set_thread_pool_bridge ( std::shared_ptr< ThreadPoolBridge > bridge)

Set custom thread pool bridge.

Parameters
bridgeThread pool bridge to use
Returns
ok() on success, error_info on failure

Sets a custom thread pool bridge. Must be called before initialize().

Error Conditions:

  • Already initialized
  • Null bridge pointer

Definition at line 279 of file network_system_bridge.cpp.

279 {
280 if (!pimpl_) {
281 return error_void(
283 "Bridge has been moved",
284 "NetworkSystemBridge::set_thread_pool_bridge");
285 }
286 return pimpl_->set_thread_pool_bridge(std::move(bridge));
287}

References kcenon::network::error_void(), kcenon::network::error_codes::common_errors::not_initialized, and pimpl_.

Here is the call graph for this function:

◆ shutdown()

VoidResult kcenon::network::integration::NetworkSystemBridge::shutdown ( )

Shutdown all bridges.

Returns
ok() on success, error_info on failure

Shuts down all initialized bridges in reverse initialization order. This method is idempotent - multiple calls are safe.

Definition at line 230 of file network_system_bridge.cpp.

230 {
231 if (!pimpl_) {
232 return ok(); // Already moved or destroyed
233 }
234 return pimpl_->shutdown();
235}
VoidResult ok()

References kcenon::network::ok(), and pimpl_.

Here is the call graph for this function:

◆ with_custom()

std::shared_ptr< NetworkSystemBridge > kcenon::network::integration::NetworkSystemBridge::with_custom ( std::shared_ptr< thread_pool_interface > thread_pool = nullptr,
std::shared_ptr< logger_interface > logger = nullptr,
std::shared_ptr< monitoring_interface > monitoring = nullptr )
static

Create bridge with custom components.

Parameters
thread_poolCustom thread pool (optional)
loggerCustom logger (optional)
monitoringCustom monitoring (optional)
Returns
Shared pointer to NetworkSystemBridge

Creates a bridge with custom components.

Definition at line 365 of file network_system_bridge.cpp.

368 {
369
370 auto bridge = std::make_shared<NetworkSystemBridge>();
371
372 if (thread_pool) {
373 auto thread_pool_bridge = std::make_shared<ThreadPoolBridge>(
375 bridge->set_thread_pool_bridge(thread_pool_bridge);
376 }
377
378 if (logger) {
379 bridge->set_logger(logger);
380 }
381
382 if (monitoring) {
383 bridge->set_monitoring(monitoring);
384 }
385
386 return bridge;
387}

References kcenon::network::integration::ThreadPoolBridge::Custom.

◆ with_thread_system()

std::shared_ptr< NetworkSystemBridge > kcenon::network::integration::NetworkSystemBridge::with_thread_system ( const std::string & pool_name = "network_pool")
static

Create bridge with thread_system integration.

Parameters
pool_nameThread pool name (default: "network_pool")
Returns
Shared pointer to NetworkSystemBridge

Creates a bridge configured for thread_system integration.

Example:

config.enable_thread_pool = true;
bridge->initialize(config);
static std::shared_ptr< NetworkSystemBridge > with_thread_system(const std::string &pool_name="network_pool")
Create bridge with thread_system integration.

Definition at line 323 of file network_system_bridge.cpp.

324 {
325 auto bridge = std::make_shared<NetworkSystemBridge>();
326
327#if KCENON_WITH_THREAD_SYSTEM
328 auto thread_pool_bridge = ThreadPoolBridge::from_thread_system(pool_name);
329 bridge->set_thread_pool_bridge(thread_pool_bridge);
330#endif
331
332 return bridge;
333}

References kcenon::network::integration::ThreadPoolBridge::from_thread_system().

Here is the call graph for this function:

Member Data Documentation

◆ pimpl_

std::unique_ptr<Impl> kcenon::network::integration::NetworkSystemBridge::pimpl_
private

The documentation for this class was generated from the following files: