forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTransportMgr.h
107 lines (92 loc) · 3.49 KB
/
TransportMgr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*
*
* Copyright (c) 2020-2021 Project CHIP Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
*/
/**
* @file
* This file implements a stateless TransportMgr, it will took a raw message
* buffer from transports, and then extract the message header without decode it.
* For secure messages, it will pass it to the SessionManager, and for unsecure
* messages (rendezvous messages), it will pass it to RendezvousSession.
* When sending messages, it will encode the packet header, and pass it to the
* transports.
* The whole process is fully stateless.
*/
#pragma once
#include <lib/support/CodeUtils.h>
#include <lib/support/logging/CHIPLogging.h>
#include <transport/TransportMgrBase.h>
#include <transport/raw/Base.h>
#include <transport/raw/MessageHeader.h>
#include <transport/raw/PeerAddress.h>
#include <transport/raw/Tuple.h>
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
#include <transport/raw/TCP.h>
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
namespace chip {
class TransportMgrBase;
class TransportMgrDelegate
{
public:
virtual ~TransportMgrDelegate() = default;
/**
* @brief
* Handle received secure message.
*
* @param source the source address of the package
* @param msgBuf the buffer containing a full CHIP message (except for the optional length field).
* @param ctxt the pointer to additional context on the underlying transport. For TCP, it is a pointer
* to the underlying connection object.
*/
virtual void OnMessageReceived(const Transport::PeerAddress & source, System::PacketBufferHandle && msgBuf,
Transport::MessageTransportContext * ctxt = nullptr) = 0;
#if INET_CONFIG_ENABLE_TCP_ENDPOINT
/**
* @brief
* Handle connection attempt completion.
*
* @param conn the connection object
* @param conErr the connection error on the attempt, or CHIP_NO_ERROR.
*/
virtual void HandleConnectionAttemptComplete(Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr){};
virtual void HandleConnectionClosed(Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr){};
virtual void HandleConnectionReceived(Transport::ActiveTCPConnectionState * conn){};
#endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
};
template <typename... TransportTypes>
class TransportMgr : public TransportMgrBase
{
public:
template <typename... Args>
CHIP_ERROR Init(Args &&... transportInitArgs)
{
ReturnErrorOnFailure(mTransport.Init(this, std::forward<Args>(transportInitArgs)...));
return TransportMgrBase::Init(&mTransport);
}
template <typename... Args>
CHIP_ERROR ResetTransport(Args &&... transportInitArgs)
{
return mTransport.Init(this, std::forward<Args>(transportInitArgs)...);
}
void Close()
{
TransportMgrBase::Close();
mTransport.Close();
};
private:
Transport::Tuple<TransportTypes...> mTransport;
public:
auto & GetTransport() { return mTransport; }
};
} // namespace chip