1 #ifndef DOIPDEFAULTCONNECTION_H
2 #define DOIPDEFAULTCONNECTION_H
4 #include "DoIPConfig.h"
15 using namespace std::chrono_literals;
29 return os <<
"Initial Inactivity";
31 return os <<
"General Inactivity";
33 return os <<
"Alive Check";
35 return os <<
"Downstream Response";
37 return os <<
"User Defined";
39 return os <<
"Unknown(" <<
static_cast<int>(tid) <<
")";
61 struct StateDescriptor {
78 std::chrono::milliseconds timeoutDurationUser_ = 0ms)
80 stateAfterTimeout(stateAfterTimeout_),
81 messageHandler(std::move(handler_)),
83 enterStateHandler(enterState_),
84 timeoutHandler(std::move(timeoutHandler_)),
85 timeoutDurationUser(timeoutDurationUser_) {}
93 std::chrono::milliseconds timeoutDurationUser{0};
100 void setClientAddress(
const DoIPAddress &address)
override;
114 ssize_t sendProtocolMessage(
const DoIPMessage &msg)
override;
135 return m_closeReason;
239 bool hasDownstreamHandler()
const override;
260 return m_state->state;
268 return m_serverModel;
284 const StateDescriptor *m_state =
nullptr;
288 uint8_t m_aliveCheckRetry{0};
289 uint8_t m_aliveCheckRetryCount{DOIP_ALIVE_CHECK_RETRIES};
295 std::chrono::milliseconds m_downstreamResponseTimeout{10s};
301 std::chrono::milliseconds getTimerDuration(StateDescriptor
const *stateDesc);
303 void startStateTimer(StateDescriptor
const *stateDesc);
304 void restartStateTimer();
322 ssize_t sendAliveCheckRequest();
Default implementation of IConnectionContext.
TimerManager< ConnectionTimers > m_timerManager
std::chrono::milliseconds getDownstreamResponseTimeout() const
Gets the downstream response timeout duration.
void setAliveCheckRetryCount(uint8_t count)
Sets the alive check retry count.
bool isOpen() const override
Checks if the connection is open.
bool isRoutingActivated() const
Checks if routing is currently activated.
std::chrono::milliseconds getGeneralInactivityTimeout() const
Gets the general inactivity timeout duration.
std::chrono::milliseconds getInitialInactivityTimeout() const
Gets the initial inactivity timeout duration.
std::array< StateDescriptor, 7 > STATE_DESCRIPTORS
void setDownstreamResponseTimeout(std::chrono::milliseconds timeout)
Sets the downstream response timeout duration.
DoIPCloseReason getCloseReason() const override
Gets the reason for connection closure.
UniqueServerModelPtr m_serverModel
std::chrono::milliseconds getAliveCheckTimeout() const
Gets the alive check timeout duration.
void setInitialInactivityTimeout(std::chrono::milliseconds timeout)
Sets the initial inactivity timeout duration.
DoIPAddress m_routedClientAddress
uint8_t getAliveCheckRetryCount() const
Gets the alive check retry count.
DoIPServerState getState() const
Gets the current state of the connection.
void setGeneralInactivityTimeout(std::chrono::milliseconds timeout)
Sets the general inactivity timeout duration.
void setAliveCheckTimeout(std::chrono::milliseconds timeout)
Sets the alive check timeout duration.
UniqueServerModelPtr & getServerModel()
Gets the server model.
Represents a complete DoIP message with internal ByteArray representation.
Interface between DoIPServerStateMachine and DoIPConnection.
constexpr std::chrono::milliseconds AliveCheckResponseTimeout(500)
Time in ms to wait for a alive check response.
constexpr std::chrono::milliseconds InitialInactivityTimeout(200)
Maximum inactivity time in ms after a TCP connection was accepted.
constexpr std::chrono::milliseconds GeneralInactivityTimeout(500)
Maximum inactivity time in ms after a TCP message was sent or received.
std::function< void(std::optional< DoIPMessage >)> MessageHandler
std::function< void(ConnectionTimers)> TimeOutHandler
uint16_t DoIPAddress
Represents a 16-bit DoIP address consisting of high and low significant bytes.
std::optional< DoIPNegativeDiagnosticAck > DoIPDiagnosticAck
Alias for diagnostic acknowledgment type.
DoIPRoutingActivationResult
std::ostream & operator<<(std::ostream &os, const ByteArray &arr)
Stream operator for ByteArray.
DoIPDownstreamResult
Result of a downstream request initiation.
std::function< void()> StateChangeHandler
std::optional< DoIPMessage > OptDoIPMessage
DoIPCloseReason
Reason for connection closure.
std::unique_ptr< DoIPServerModel > UniqueServerModelPtr
A dynamic array of bytes with utility methods for network protocol handling.