libdoip  0.1.0
DoIP (Diagnostics over Internet Protocol) ISO 13400 C++17 Library
doip::DoIPConnection Class Reference

#include <DoIPConnection.h>

Inheritance diagram for doip::DoIPConnection:
Collaboration diagram for doip::DoIPConnection:

Public Member Functions

 DoIPConnection (int tcpSocket, UniqueServerModelPtr model)
 
int receiveTcpMessage ()
 
size_t receiveFixedNumberOfBytesFromTCP (uint8_t *receivedData, size_t payloadLength)
 Receive exactly payloadLength bytes from the TCP stream and put them into receivedData. More...
 
void sendDiagnosticPayload (const DoIPAddress &sourceAddress, const ByteArray &payload)
 
bool isSocketActive ()
 
void triggerDisconnection ()
 
void sendDiagnosticAck (const DoIPAddress &sourceAddress)
 
void sendDiagnosticNegativeAck (const DoIPAddress &sourceAddress, DoIPNegativeDiagnosticAck ackCode)
 
ssize_t sendProtocolMessage (const DoIPMessage &msg) override
 Send a DoIP protocol message to the client. More...
 
void closeConnection (DoIPCloseReason reason) override
 Close the TCP connection. More...
 
DoIPAddress getServerAddress () const override
 Get the server's logical address. More...
 
DoIPAddress getClientAddress () const override
 Get the currently client (active source) address. More...
 
void setClientAddress (const DoIPAddress &address) override
 Set the client (active source) address after routing activation. More...
 
DoIPDiagnosticAck notifyDiagnosticMessage (const DoIPMessage &msg) override
 Handle an incoming diagnostic message (application callback) More...
 
void notifyConnectionClosed (DoIPCloseReason reason) override
 Notify application that connection is closing. More...
 
void notifyDiagnosticAckSent (DoIPDiagnosticAck ack) override
 Notify application that diagnostic ACK/NACK was sent. More...
 
bool hasDownstreamHandler () const override
 Check if downstream forwarding is available. More...
 
- Public Member Functions inherited from doip::DoIPDefaultConnection
 DoIPDefaultConnection (UniqueServerModelPtr model)
 Constructs a DoIPDefaultConnection. More...
 
ssize_t sendProtocolMessage (const DoIPMessage &msg) override
 Sends a DoIP protocol message to the client. More...
 
void closeConnection (DoIPCloseReason reason) override
 Closes the connection. More...
 
bool isOpen () const override
 Checks if the connection is open. More...
 
DoIPCloseReason getCloseReason () const override
 Gets the reason for connection closure. More...
 
bool isRoutingActivated () const
 Checks if routing is currently activated. More...
 
uint8_t getAliveCheckRetryCount () const
 Gets the alive check retry count. More...
 
std::chrono::milliseconds getInitialInactivityTimeout () const
 Gets the initial inactivity timeout duration. More...
 
std::chrono::milliseconds getGeneralInactivityTimeout () const
 Gets the general inactivity timeout duration. More...
 
std::chrono::milliseconds getAliveCheckTimeout () const
 Gets the alive check timeout duration. More...
 
std::chrono::milliseconds getDownstreamResponseTimeout () const
 Gets the downstream response timeout duration. More...
 
void setAliveCheckRetryCount (uint8_t count)
 Sets the alive check retry count. More...
 
void setInitialInactivityTimeout (std::chrono::milliseconds timeout)
 Sets the initial inactivity timeout duration. More...
 
void setGeneralInactivityTimeout (std::chrono::milliseconds timeout)
 Sets the general inactivity timeout duration. More...
 
void setAliveCheckTimeout (std::chrono::milliseconds timeout)
 Sets the alive check timeout duration. More...
 
void setDownstreamResponseTimeout (std::chrono::milliseconds timeout)
 Sets the downstream response timeout duration. More...
 
DoIPAddress getServerAddress () const override
 Gets the server's logical address. More...
 
DoIPAddress getClientAddress () const override
 Gets the client's address. More...
 
DoIPDiagnosticAck notifyDiagnosticMessage (const DoIPMessage &msg) override
 Handles an incoming diagnostic message. More...
 
void notifyConnectionClosed (DoIPCloseReason reason) override
 Notifies application that connection is closing. More...
 
void notifyDiagnosticAckSent (DoIPDiagnosticAck ack) override
 Notifies application that diagnostic ACK/NACK was sent. More...
 
bool hasDownstreamHandler () const override
 Checks if a downstream handler is present. More...
 
DoIPDownstreamResult notifyDownstreamRequest (const DoIPMessage &msg) override
 Notifies application of a downstream request. More...
 
void receiveDownstreamResponse (const ByteArray &response, DoIPDownstreamResult result) override
 Receives a downstream response. More...
 
DoIPServerState getState () const
 Gets the current state of the connection. More...
 
UniqueServerModelPtrgetServerModel ()
 Gets the server model. More...
 
void handleMessage2 (const DoIPMessage &message)
 Handles a message (internal helper) More...
 
- Public Member Functions inherited from doip::IConnectionContext
virtual ~IConnectionContext ()=default
 

Additional Inherited Members

- Protected Member Functions inherited from doip::DoIPDefaultConnection
void transitionTo (DoIPServerState newState)
 
std::chrono::milliseconds getTimerDuration (StateDescriptor const *stateDesc)
 
void startStateTimer (StateDescriptor const *stateDesc)
 
void restartStateTimer ()
 
void handleSocketInitialized (DoIPServerEvent event, OptDoIPMessage msg)
 
void handleWaitRoutingActivation (DoIPServerEvent event, OptDoIPMessage msg)
 
void handleRoutingActivated (DoIPServerEvent event, OptDoIPMessage msg)
 
void handleWaitAliveCheckResponse (DoIPServerEvent event, OptDoIPMessage msg)
 
void handleWaitDownstreamResponse (DoIPServerEvent event, OptDoIPMessage msg)
 
void handleFinalize (DoIPServerEvent event, OptDoIPMessage msg)
 
void handleTimeout (ConnectionTimers timer_id)
 Default timeout handler. More...
 
ssize_t sendRoutingActivationResponse (const DoIPAddress &source_address, DoIPRoutingActivationResult response_code)
 
ssize_t sendAliveCheckRequest ()
 
ssize_t sendDiagnosticMessageResponse (const DoIPAddress &sourceAddress, DoIPDiagnosticAck ack)
 
ssize_t sendDownstreamResponse (const DoIPAddress &sourceAddress, const ByteArray &payload)
 
- Protected Attributes inherited from doip::DoIPDefaultConnection
UniqueServerModelPtr m_serverModel
 
std::array< StateDescriptor, 7 > STATE_DESCRIPTORS
 
DoIPAddress m_routedClientAddress
 
bool m_isOpen
 
DoIPCloseReason m_closeReason = DoIPCloseReason::None
 
const StateDescriptor * m_state = nullptr
 
TimerManager< ConnectionTimersm_timerManager
 
uint8_t m_aliveCheckRetry {0}
 
uint8_t m_aliveCheckRetryCount {DOIP_ALIVE_CHECK_RETRIES}
 
std::chrono::milliseconds m_initialInactivityTimeout {times::server::InitialInactivityTimeout}
 
std::chrono::milliseconds m_generalInactivityTimeout {times::server::GeneralInactivityTimeout}
 
std::chrono::milliseconds m_aliveCheckTimeout {times::server::AliveCheckResponseTimeout}
 
std::chrono::milliseconds m_downstreamResponseTimeout {10s}
 

Detailed Description

Definition at line 25 of file DoIPConnection.h.

Constructor & Destructor Documentation

◆ DoIPConnection()

doip::DoIPConnection::DoIPConnection ( int  tcpSocket,
UniqueServerModelPtr  model 
)

Definition at line 11 of file DoIPConnection.cpp.

Member Function Documentation

◆ closeConnection()

void doip::DoIPConnection::closeConnection ( DoIPCloseReason  reason)
overridevirtual

Close the TCP connection.

Parameters
reasonWhy the connection is being closed

Implements doip::IConnectionContext.

Definition at line 130 of file DoIPConnection.cpp.

References doip::DoIPDefaultConnection::closeConnection(), LOG_DOIP_DEBUG, LOG_DOIP_INFO, and fmt::streamed().

◆ getClientAddress()

DoIPAddress doip::DoIPConnection::getClientAddress ( ) const
overridevirtual

Get the currently client (active source) address.

Returns
The client (active source) address, or 0 if no routing is active

Implements doip::IConnectionContext.

Definition at line 151 of file DoIPConnection.cpp.

◆ getServerAddress()

DoIPAddress doip::DoIPConnection::getServerAddress ( ) const
overridevirtual

Get the server's logical address.

Returns
The server's DoIP logical address

Implements doip::IConnectionContext.

Definition at line 147 of file DoIPConnection.cpp.

References doip::DoIPDefaultConnection::m_serverModel.

◆ hasDownstreamHandler()

bool doip::DoIPConnection::hasDownstreamHandler ( ) const
overridevirtual

Check if downstream forwarding is available.

Returns
true if the server model has a downstream handler configured

Implements doip::IConnectionContext.

Definition at line 181 of file DoIPConnection.cpp.

References doip::DoIPDefaultConnection::m_serverModel.

◆ isSocketActive()

bool doip::DoIPConnection::isSocketActive ( )
inline

Definition at line 34 of file DoIPConnection.h.

◆ notifyConnectionClosed()

void doip::DoIPConnection::notifyConnectionClosed ( DoIPCloseReason  reason)
overridevirtual

Notify application that connection is closing.

Parameters
reasonWhy the connection is closing

Implements doip::IConnectionContext.

Definition at line 168 of file DoIPConnection.cpp.

References doip::DoIPDefaultConnection::m_serverModel.

◆ notifyDiagnosticAckSent()

void doip::DoIPConnection::notifyDiagnosticAckSent ( DoIPDiagnosticAck  ack)
overridevirtual

Notify application that diagnostic ACK/NACK was sent.

Parameters
ackThe ACK/NACK that was sent

Implements doip::IConnectionContext.

Definition at line 175 of file DoIPConnection.cpp.

References doip::DoIPDefaultConnection::m_serverModel.

◆ notifyDiagnosticMessage()

DoIPDiagnosticAck doip::DoIPConnection::notifyDiagnosticMessage ( const DoIPMessage msg)
overridevirtual

Handle an incoming diagnostic message (application callback)

Parameters
msgThe diagnostic message received
Returns
std::nullopt for ACK, or NACK code

Implements doip::IConnectionContext.

Definition at line 159 of file DoIPConnection.cpp.

References doip::DoIPDefaultConnection::m_serverModel.

◆ receiveFixedNumberOfBytesFromTCP()

size_t doip::DoIPConnection::receiveFixedNumberOfBytesFromTCP ( uint8_t *  receivedData,
size_t  payloadLength 
)

Receive exactly payloadLength bytes from the TCP stream and put them into receivedData.

The method blocks until receivedData bytes are received or the socket is closed.

The parameter receivedData needs to point to a readily allocated array with at least payloadLength items.

Returns
number of bytes received

Definition at line 85 of file DoIPConnection.cpp.

Referenced by receiveTcpMessage().

◆ receiveTcpMessage()

◆ sendDiagnosticAck()

void doip::DoIPConnection::sendDiagnosticAck ( const DoIPAddress sourceAddress)

◆ sendDiagnosticNegativeAck()

void doip::DoIPConnection::sendDiagnosticNegativeAck ( const DoIPAddress sourceAddress,
DoIPNegativeDiagnosticAck  ackCode 
)

◆ sendDiagnosticPayload()

void doip::DoIPConnection::sendDiagnosticPayload ( const DoIPAddress sourceAddress,
const ByteArray payload 
)

◆ sendProtocolMessage()

ssize_t doip::DoIPConnection::sendProtocolMessage ( const DoIPMessage msg)
overridevirtual

Send a DoIP protocol message to the client.

Parameters
msgThe DoIP message to send

Implements doip::IConnectionContext.

Definition at line 120 of file DoIPConnection.cpp.

References doip::DoIPMessage::data(), LOG_DOIP_ERROR, LOG_DOIP_INFO, doip::DoIPMessage::size(), and fmt::streamed().

◆ setClientAddress()

void doip::DoIPConnection::setClientAddress ( const DoIPAddress address)
overridevirtual

Set the client (active source) address after routing activation.

Parameters
addressThe client's source address

Implements doip::IConnectionContext.

Definition at line 155 of file DoIPConnection.cpp.

◆ triggerDisconnection()

void doip::DoIPConnection::triggerDisconnection ( )

Definition at line 102 of file DoIPConnection.cpp.

References LOG_DOIP_INFO.


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