Skip to content

refactor: Create common protocol interfaces (IProtocolClient, IProtocolServer) #593

Description

@kcenon

What

Create unified protocol interfaces that all protocol implementations (TCP, UDP, HTTP, WebSocket) will implement. This establishes a common contract for clients and servers across all protocols.

Summary

Define two core interfaces:

  • IProtocolClient: Common interface for all protocol clients
  • IProtocolServer: Common interface for all protocol servers

Change Type

  • Refactor (architectural improvement)

Affected Components

  • include/interfaces/ - New interface definitions
  • Protocol implementations (TCP, UDP, HTTP, WebSocket) - Will implement these interfaces in subsequent tasks

Why

Problem Solved

Currently, each protocol (TCP, UDP, HTTP, WebSocket) has its own client/server structure with duplicated patterns. This creates:

  • Maintenance burden: Changes must be replicated across protocols
  • Learning curve: Developers must understand each protocol's unique structure
  • Testing complexity: Each protocol requires separate test infrastructure

Related Issues

Business Value

  • Consistency: Uniform API across all protocols
  • Maintainability: Single source of truth for protocol contracts
  • Extensibility: New protocols can easily adopt the common interface

When

Urgency

Target Release

Milestone: EPIC #577 completion

Dependencies

  • None - This is the first task in the EPIC

Blocks

  • Facade class implementation
  • Adapter consolidation
  • Protocol-specific refactoring

Where

Files to Create

File Purpose
include/interfaces/i_protocol_client.h Client interface definition
include/interfaces/i_protocol_server.h Server interface definition

Files to Reference (for API design)

  • Existing TCP/UDP/HTTP/WebSocket client/server implementations
  • Current protocol patterns

How

Implementation Approach

  1. Analyze existing protocols:

    • Review common operations across TCP, UDP, HTTP, WebSocket clients
    • Review common operations across TCP, UDP, HTTP, WebSocket servers
    • Identify common lifecycle methods (connect, send, receive, disconnect)
  2. Design IProtocolClient interface:

    class IProtocolClient {
    public:
        virtual ~IProtocolClient() = default;
        
        // Connection management
        virtual bool connect(const std::string& address, uint16_t port) = 0;
        virtual bool disconnect() = 0;
        virtual bool is_connected() const = 0;
        
        // Data transfer
        virtual bool send(const std::vector<uint8_t>& data) = 0;
        virtual std::optional<std::vector<uint8_t>> receive() = 0;
        
        // Configuration
        virtual void set_timeout(std::chrono::milliseconds timeout) = 0;
    };
  3. Design IProtocolServer interface:

    class IProtocolServer {
    public:
        virtual ~IProtocolServer() = default;
        
        // Server lifecycle
        virtual bool start(uint16_t port) = 0;
        virtual bool stop() = 0;
        virtual bool is_running() const = 0;
        
        // Connection handling
        virtual void set_connection_handler(
            std::function<void(ConnectionInfo)> handler) = 0;
        virtual void set_data_handler(
            std::function<void(const std::vector<uint8_t>&)> handler) = 0;
    };
  4. Documentation:

    • Add detailed Doxygen comments
    • Document design rationale
    • Provide usage examples

Acceptance Criteria

  • IProtocolClient interface defined with common client operations
  • IProtocolServer interface defined with common server operations
  • Interfaces use modern C++ features (smart pointers, std::optional)
  • Comprehensive Doxygen documentation
  • No breaking changes to existing code (interfaces are additive)
  • Code compiles without warnings
  • Design reviewed and approved

Testing Plan

  • No runtime tests required for interface-only changes
  • Verify compilation succeeds
  • Verify documentation builds correctly

Breaking Changes

None - This is an additive change. Existing code is not modified.

Checklist

  • Code follows project style guidelines
  • Self-review completed
  • Documentation added
  • No breaking changes
  • Compiles without warnings

Metadata

Metadata

Assignees

Labels

architectureArchitectural changes and designpriority:highHigh priority issuerefactoringCode refactoring and improvements

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions