ImagingTools Core SDK
Public Member Functions | List of all members
imtcom::IServerDispatcherabstract

Interface for managing the lifecycle of multi-protocol servers. More...

#include <IServerDispatcher.h>

Inheritance diagram for imtcom::IServerDispatcher:
imtcom::CServerDispatcherComp

Public Member Functions

virtual bool StartServer (IServerConnectionInterface::ProtocolType protocolType)=0
 Start a server for the specified protocol.
 
virtual bool StopServer (IServerConnectionInterface::ProtocolType protocolType)=0
 Stop the server for the specified protocol.
 
virtual imtrest::IServer::ServerStatus GetServerStatus (IServerConnectionInterface::ProtocolType protocolType) const =0
 Query the operational status of a server.
 
virtual IServerConnectionInterface::ProtocolTypes GetSupportedProtocols () const =0
 Get the list of protocols supported by this dispatcher.
 

Detailed Description

Interface for managing the lifecycle of multi-protocol servers.

The IServerDispatcher provides control over server instances that can support multiple communication protocols (HTTP, WebSocket, gRPC). It enables starting, stopping, and querying the status of protocol-specific server implementations.

This interface acts as a facade for managing underlying server components (typically from the imtrest module), providing a unified API for multi-protocol server orchestration.

Key Features

Multi-Protocol Management:

Server Lifecycle:

Protocol Discovery:

Server Status States

Servers progress through the following states (from imtrest::IServer::ServerStatus):

Implementation

Usage Example

// Create dispatcher component
auto dispatcher = icomp::CreateComponent<CServerDispatcherComp>();
// Configure dispatcher with connection parameters and server components
// (via ACF component attributes and references)
// Start HTTP server
if (dispatcher->StartServer(IServerConnectionInterface::PT_HTTP)) {
qDebug() << "HTTP server started";
// Verify it's running
auto status = dispatcher->GetServerStatus(IServerConnectionInterface::PT_HTTP);
if (status == imtrest::IServer::SS_RUNNING) {
qDebug() << "Server is accepting connections";
}
} else {
qCritical() << "Failed to start HTTP server";
}
// Start WebSocket server simultaneously
if (dispatcher->StartServer(IServerConnectionInterface::PT_WEBSOCKET)) {
qDebug() << "WebSocket server started";
}
// Query supported protocols
auto protocols = dispatcher->GetSupportedProtocols();
qDebug() << "Dispatcher supports" << protocols.size() << "protocols";
// Later: graceful shutdown
dispatcher->StopServer(IServerConnectionInterface::PT_HTTP);
@ PT_WEBSOCKET
WebSocket/WSS protocol for real-time bidirectional communication (default port: 9000)
@ PT_HTTP
HTTP/HTTPS protocol for RESTful APIs (default port: 9001)

Integration Points

Server Components (imtrest):

Configuration:

Client Modules:

See also
CServerDispatcherComp, IServerConnectionInterface
imtrest::IServer, imtrest::CTcpServerComp, imtrest::CWebSocketServerComp

Definition at line 120 of file IServerDispatcher.h.

Member Function Documentation

◆ GetServerStatus()

virtual imtrest::IServer::ServerStatus imtcom::IServerDispatcher::GetServerStatus ( IServerConnectionInterface::ProtocolType  protocolType) const
pure virtual

Query the operational status of a server.

Returns the current status of the server implementation for the specified protocol. The status indicates whether the server is stopped, starting, running, or stopping.

Parameters
protocolTypeThe protocol type to query (PT_HTTP, PT_WEBSOCKET, etc.).
Returns
Current server status (SS_UNKNOWN, SS_STOPPED, SS_STARTING, SS_RUNNING, SS_STOPPING).
See also
StartServer(), StopServer(), imtrest::IServer::ServerStatus
Example:
auto status = dispatcher->GetServerStatus(IServerConnectionInterface::PT_HTTP);
switch (status) {
case imtrest::IServer::SS_RUNNING:
qDebug() << "Server is running";
break;
case imtrest::IServer::SS_STOPPED:
qDebug() << "Server is stopped";
break;
case imtrest::IServer::SS_STARTING:
qDebug() << "Server is starting...";
// Wait and check again
break;
case imtrest::IServer::SS_STOPPING:
qDebug() << "Server is stopping...";
break;
default:
qWarning() << "Unknown server status";
break;
}
Note
Status queries are typically lightweight and suitable for frequent polling or health checks.

◆ GetSupportedProtocols()

virtual IServerConnectionInterface::ProtocolTypes imtcom::IServerDispatcher::GetSupportedProtocols ( ) const
pure virtual

Get the list of protocols supported by this dispatcher.

Returns all protocol types that this dispatcher implementation can manage. Only protocols in this list can be passed to StartServer(), StopServer(), and GetServerStatus().

The list is typically static and defined by the dispatcher implementation. For example, CServerDispatcherComp supports PT_HTTP and PT_WEBSOCKET.

Returns
List of supported protocol types.
See also
IServerConnectionInterface::ProtocolTypes
Example:
auto protocols = dispatcher->GetSupportedProtocols();
for (auto protocol : protocols) {
qDebug() << "Supported protocol:" << protocol;
// Start all supported servers
if (!dispatcher->StartServer(protocol)) {
qWarning() << "Failed to start server for protocol:" << protocol;
}
}
Note
The returned list represents dispatcher capabilities, not currently configured protocols. Use IServerConnectionInterface::GetSupportedProtocols() to query configured protocols.

◆ StartServer()

virtual bool imtcom::IServerDispatcher::StartServer ( IServerConnectionInterface::ProtocolType  protocolType)
pure virtual

Start a server for the specified protocol.

Initializes and starts the server implementation for the given protocol. The server will begin listening on the port configured in the associated IServerConnectionInterface.

If the server is already running, this method may return true without restarting it (implementation-dependent).

Parameters
protocolTypeThe protocol type to start (PT_HTTP, PT_WEBSOCKET, etc.).
Returns
true if the server was started successfully or was already running; false if startup failed (e.g., port already in use, configuration invalid).
See also
StopServer(), GetServerStatus(), IServerConnectionInterface::GetPort()
Example:
if (!dispatcher->StartServer(IServerConnectionInterface::PT_HTTP)) {
qCritical() << "Failed to start HTTP server";
// Check logs for detailed error (port conflict, permission denied, etc.)
return false;
}
Note
Ensure the IServerConnectionInterface is properly configured with host and port before calling this method.

◆ StopServer()

virtual bool imtcom::IServerDispatcher::StopServer ( IServerConnectionInterface::ProtocolType  protocolType)
pure virtual

Stop the server for the specified protocol.

Gracefully shuts down the server implementation for the given protocol. The server will stop accepting new connections and may wait for active connections to complete (implementation-dependent).

If the server is already stopped, this method typically returns true without error.

Parameters
protocolTypeThe protocol type to stop (PT_HTTP, PT_WEBSOCKET, etc.).
Returns
true if the server was stopped successfully or was already stopped; false if shutdown failed.
See also
StartServer(), GetServerStatus()
Example:
// Graceful shutdown: stop in reverse order of startup
dispatcher->StopServer(IServerConnectionInterface::PT_HTTP);
Note
For production applications, consider implementing a graceful shutdown timeout to avoid hanging indefinitely on stuck connections.