ImagingTools Core SDK
Classes
imtcom Namespace Reference

Server Communication and Connection Management Module. More...

Classes

class  CAsyncConnectionCheckerComp
 Timer-based asynchronous connection status checker using HTTP requests. More...
 
class  CRequestSender
 
class  CServerConnectionInterfaceParam
 Basic implementation of IServerConnectionInterface with protocol-port mapping. More...
 
class  CServerConnectionInterfaceParamComp
 ACF component implementation of IServerConnectionInterface with default port configuration. More...
 
class  CServerDispatcherComp
 ACF component implementing multi-protocol server dispatch for HTTP and WebSocket. More...
 
class  CSimpleConnectionCheckerComp
 GraphQL-based connection status checker for application-level connectivity validation. More...
 
class  IConnectionController
 Simple interface for connection lifecycle control. More...
 
class  IConnectionStatusProvider
 Interface for monitoring network connection status with observable state changes. More...
 
class  IFileTransfer
 Interface for file upload and download operations via URLs. More...
 
class  IServerConnectionInterface
 Interface for describing server connection configuration with multi-protocol support. More...
 
class  IServerDispatcher
 Interface for managing the lifecycle of multi-protocol servers. More...
 
class  ISslConfigurationApplier
 Interface for applying SSL-related settings to an SSL configuration. More...
 

Detailed Description

Server Communication and Connection Management Module.

The imtcom module provides comprehensive infrastructure for server connection configuration, multi-protocol dispatch, SSL/TLS security management, and network connection status monitoring.

Overview

This module serves as the foundation for client-server communication in ImtCore, handling:

Architecture

Design Patterns

Interface-Implementation Pattern:

Component Pattern (ACF):

Observer Pattern:

Strategy Pattern:

Core Interfaces

The module is organized around several key interface hierarchies:

Connection Configuration Hierarchy:

IServerConnectionInterface (iser::ISerializable, istd::IChangeable)
├─ Defines host, port, protocol configuration
├─ Supports CF_DEFAULT and CF_SECURE connection flags
└─ Protocols: PT_HTTP, PT_WEBSOCKET, PT_FILE, PT_GRPC
├─ CServerConnectionInterfaceParam (concrete data holder)
└─ CServerConnectionInterfaceParamComp (ACF component with defaults)
ACF component implementation of IServerConnectionInterface with default port configuration.
Basic implementation of IServerConnectionInterface with protocol-port mapping.
Interface for describing server connection configuration with multi-protocol support.

Server Dispatch Hierarchy:

IServerDispatcher (istd::IPolymorphic)
├─ Manages server lifecycle: StartServer(), StopServer()
├─ Provides server status queries
└─ Multi-protocol support
└─ CServerDispatcherComp (HTTP and WebSocket dispatcher)
ACF component implementing multi-protocol server dispatch for HTTP and WebSocket.
Interface for managing the lifecycle of multi-protocol servers.

Connection Monitoring Hierarchy:

IConnectionStatusProvider (istd::IChangeable)
├─ CS_UNKNOWN, CS_DISCONNECTED, CS_CONNECTED states
└─ Observable connection status
├─ CAsyncConnectionCheckerComp (timer-based HTTP checks)
├─ CSimpleConnectionCheckerComp (GraphQL-based checks)
└─ CInternetConnectionCheckerComp (internet availability)
Timer-based asynchronous connection status checker using HTTP requests.
GraphQL-based connection status checker for application-level connectivity validation.
Interface for monitoring network connection status with observable state changes.

SSL/TLS Configuration Hierarchy:

ISslConfigurationManager (istd::IPolymorphic)
├─ Creates QSslConfiguration from parameter sets
├─ Defines SSL protocols, key algorithms, encoding formats
└─ Peer verification modes
└─ CSslConfigurationManagerComp
ISslConfigurationApplier (istd::IPolymorphic)
├─ Applies certificates, private keys, CA chains
├─ Sets protocols and peer verification modes
└─ File-based certificate/key loading
└─ CSslConfigurationAdapterComp
Interface for applying SSL-related settings to an SSL configuration.

Key Components

Component Interface Purpose
CServerConnectionInterfaceParamComp IServerConnectionInterface Connection configuration with default ports (HTTP:9001, WS:9000, gRPC:50101)
CServerDispatcherComp IServerDispatcher Multi-protocol server lifecycle management
CSslConfigurationManagerComp ISslConfigurationManager SSL configuration factory from parameters
CSslConfigurationAdapterComp ISslConfigurationApplier SSL settings application (certificates, keys, protocols)
CAsyncConnectionCheckerComp IConnectionStatusProvider Timer-based async connection health checks
CSimpleConnectionCheckerComp IConnectionStatusProvider GraphQL-based connection validation
CInternetConnectionCheckerComp IConnectionStatusProvider General internet connectivity detection
CRequestSender N/A Synchronous HTTP request helper (GET/POST/PUT)

Usage Examples

Configuring a Server Connection

// Create connection configuration component
auto connectionParam = icomp::CreateComponent<CServerConnectionInterfaceParamComp>();
// Configure connection parameters
connectionParam->SetHost("example.com");
connectionParam->SetPort(IServerConnectionInterface::PT_HTTP, 8080);
connectionParam->SetPort(IServerConnectionInterface::PT_WEBSOCKET, 8081);
connectionParam->SetConnectionFlags(IServerConnectionInterface::CF_SECURE);
// Get URL for a protocol
QUrl httpUrl;
if (connectionParam->GetUrl(IServerConnectionInterface::PT_HTTP, httpUrl)) {
qDebug() << "HTTP URL:" << httpUrl.toString();
// Output: "https://example.com:8080"
}
@ PT_WEBSOCKET
WebSocket/WSS protocol for real-time bidirectional communication (default port: 9000)
@ PT_HTTP
HTTP/HTTPS protocol for RESTful APIs (default port: 9001)
@ CF_SECURE
Secure connection with SSL/TLS encryption (HTTPS, WSS)

Using the Server Dispatcher

// Create server dispatcher component
auto dispatcher = icomp::CreateComponent<CServerDispatcherComp>();
// Start HTTP server
if (dispatcher->StartServer(IServerConnectionInterface::PT_HTTP)) {
qDebug() << "HTTP server started successfully";
}
// Check server status
auto status = dispatcher->GetServerStatus(IServerConnectionInterface::PT_HTTP);
if (status == imtrest::IServer::ServerStatus::SS_RUNNING) {
qDebug() << "Server is running";
}
// Stop server when done
dispatcher->StopServer(IServerConnectionInterface::PT_HTTP);

Monitoring Connection Status

// Create connection checker
auto checker = icomp::CreateComponent<CAsyncConnectionCheckerComp>();
// Configure the checker (set server URL, check interval, etc.)
// ... component attribute configuration ...
// Observe connection status changes
QObject::connect(checker.get(), &IChangeable::OnChanged, [](const IChangeable::ChangeSet& cs) {
auto provider = dynamic_cast<IConnectionStatusProvider*>(sender());
auto status = provider->GetConnectionStatus();
switch (status) {
case IConnectionStatusProvider::CS_CONNECTED:
qDebug() << "Connection established";
break;
case IConnectionStatusProvider::CS_DISCONNECTED:
qDebug() << "Connection lost";
break;
case IConnectionStatusProvider::CS_UNKNOWN:
qDebug() << "Connection status unknown";
break;
}
});

Configuring SSL/TLS

// Create SSL configuration manager
auto sslManager = icomp::CreateComponent<CSslConfigurationManagerComp>();
// Create parameter set with SSL configuration
auto params = icomp::CreateComponent<iprm::CParamsSetComp>();
params->SetValue(ISslConfigurationManager::ParamKeys::s_protocolParamKey,
ISslConfigurationManager::SP_TLS_V1_3_OR_LATER);
params->SetValue(ISslConfigurationManager::ParamKeys::s_verifyModeParamKey,
ISslConfigurationManager::PVM_VERIFY);
// Create SSL configuration
QSslConfiguration sslConfig;
if (sslManager->CreateSslConfiguration(*params, sslConfig)) {
// Apply to network request
QNetworkRequest request;
request.setSslConfiguration(sslConfig);
}
// Alternative: Apply settings directly
auto applier = icomp::CreateComponent<CSslConfigurationAdapterComp>();
applier->LoadLocalCertificateFromFile("/path/to/cert.pem");
applier->LoadPrivateKeyFromFile("/path/to/key.pem", QSsl::Rsa);
applier->LoadCaCertificatesFromFile("/path/to/ca.pem");
applier->SetSslProtocol(QSsl::TlsV1_3OrLater);
applier->SetPeerVerifyMode(QSslSocket::VerifyPeer);

Cross-Module Integration

The imtcom module integrates with several other ImtCore modules:

imtrest Module:

imtclientgql Module:

imtservergql Module:

imtqml Module:

imtauthgui Module:

imthttp Module:

imtservice Module:

Supported Protocols

The module supports four primary communication protocols via the ProtocolType enumeration:

Protocol Enum Value Typical Port Use Case
HTTP PT_HTTP 9001 (default) REST API, traditional web services
WebSocket PT_WEBSOCKET 9000 (default) Real-time bidirectional communication, GraphQL subscriptions
gRPC PT_GRPC 50101 (default) High-performance RPC, microservices
File PT_FILE N/A File-based communication, local protocols

Each protocol can be independently configured with custom ports and security settings. The CF_SECURE flag determines whether HTTPS/WSS is used instead of HTTP/WS.

SSL/TLS Security

The module provides comprehensive SSL/TLS support with:

Protocols:

Key Algorithms:

Encoding Formats:

Peer Verification Modes:

Testing Utilities

The module includes several testing and diagnostic components:

These components support configurable timeouts, retry counts, and check intervals, making them suitable for both development diagnostics and production monitoring.

Module Dependencies

ACF Framework Dependencies:

ImtCore Module Dependencies:

Qt Framework Dependencies:

Best Practices

Connection Configuration:

Server Management:

SSL/TLS Configuration:

Connection Monitoring:

See Also

Related ImtCore modules:

Author
ImtCore Development Team
Version
1.0
Date
2024-2026