/src/connectedhomeip/src/transport/TransportMgrBase.cpp
Line | Count | Source |
1 | | /* |
2 | | * |
3 | | * Copyright (c) 2020-2021 Project CHIP Authors |
4 | | * |
5 | | * Licensed under the Apache License, Version 2.0 (the "License"); |
6 | | * you may not use this file except in compliance with the License. |
7 | | * You may obtain a copy of the License at |
8 | | * |
9 | | * http://www.apache.org/licenses/LICENSE-2.0 |
10 | | * |
11 | | * Unless required by applicable law or agreed to in writing, software |
12 | | * distributed under the License is distributed on an "AS IS" BASIS, |
13 | | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
14 | | * See the License for the specific language governing permissions and |
15 | | */ |
16 | | |
17 | | #include <transport/TransportMgrBase.h> |
18 | | |
19 | | #include <lib/support/CodeUtils.h> |
20 | | #include <platform/LockTracker.h> |
21 | | #include <transport/TransportMgr.h> |
22 | | #include <transport/raw/Base.h> |
23 | | |
24 | | namespace chip { |
25 | | |
26 | | CHIP_ERROR TransportMgrBase::SendMessage(const Transport::PeerAddress & address, System::PacketBufferHandle && msgBuf) |
27 | 1.52k | { |
28 | 1.52k | return mTransport->SendMessage(address, std::move(msgBuf)); |
29 | 1.52k | } |
30 | | |
31 | | #if INET_CONFIG_ENABLE_TCP_ENDPOINT |
32 | | CHIP_ERROR TransportMgrBase::TCPConnect(const Transport::PeerAddress & address, Transport::AppTCPConnectionCallbackCtxt * appState, |
33 | | Transport::ActiveTCPConnectionHandle & peerConnState) |
34 | 0 | { |
35 | 0 | return mTransport->TCPConnect(address, appState, peerConnState); |
36 | 0 | } |
37 | | #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT |
38 | | |
39 | | CHIP_ERROR TransportMgrBase::Init(Transport::Base * transport) |
40 | 1 | { |
41 | 1 | if (mTransport != nullptr) |
42 | 0 | { |
43 | 0 | return CHIP_ERROR_INCORRECT_STATE; |
44 | 0 | } |
45 | 1 | mTransport = transport; |
46 | 1 | mTransport->SetDelegate(this); |
47 | | |
48 | 1 | ChipLogDetail(Inet, "TransportMgr initialized"); |
49 | 1 | return CHIP_NO_ERROR; |
50 | 1 | } |
51 | | |
52 | | void TransportMgrBase::Close() |
53 | 1 | { |
54 | 1 | mSessionManager = nullptr; |
55 | 1 | mTransport = nullptr; |
56 | 1 | } |
57 | | |
58 | | CHIP_ERROR TransportMgrBase::MulticastGroupJoinLeave(const Transport::PeerAddress & address, bool join) |
59 | 0 | { |
60 | 0 | return mTransport->MulticastGroupJoinLeave(address, join); |
61 | 0 | } |
62 | | |
63 | | void TransportMgrBase::HandleMessageReceived(const Transport::PeerAddress & peerAddress, System::PacketBufferHandle && msg, |
64 | | Transport::MessageTransportContext * ctxt) |
65 | 0 | { |
66 | | // This is the first point all incoming messages funnel through. Ensure |
67 | | // that our message receipts are all synchronized correctly. |
68 | 0 | assertChipStackLockedByCurrentThread(); |
69 | |
|
70 | 0 | if (msg->HasChainedBuffer()) |
71 | 0 | { |
72 | | // Something in the lower levels messed up. |
73 | 0 | char addrBuffer[Transport::PeerAddress::kMaxToStringSize]; |
74 | 0 | peerAddress.ToString(addrBuffer); |
75 | 0 | ChipLogError(Inet, "message from %s dropped due to lower layers not ensuring a single packet buffer.", addrBuffer); |
76 | 0 | return; |
77 | 0 | } |
78 | | |
79 | 0 | if (mSessionManager != nullptr) |
80 | 0 | { |
81 | 0 | mSessionManager->OnMessageReceived(peerAddress, std::move(msg), ctxt); |
82 | 0 | } |
83 | 0 | else |
84 | 0 | { |
85 | 0 | char addrBuffer[Transport::PeerAddress::kMaxToStringSize]; |
86 | 0 | peerAddress.ToString(addrBuffer); |
87 | 0 | ChipLogError(Inet, "message from %s is dropped since no corresponding handler is set in TransportMgr.", addrBuffer); |
88 | 0 | } |
89 | 0 | } |
90 | | |
91 | | #if INET_CONFIG_ENABLE_TCP_ENDPOINT |
92 | | void TransportMgrBase::HandleConnectionReceived(Transport::ActiveTCPConnectionState & conn) |
93 | 0 | { |
94 | 0 | if (mSessionManager != nullptr) |
95 | 0 | { |
96 | 0 | mSessionManager->HandleConnectionReceived(conn); |
97 | 0 | } |
98 | 0 | } |
99 | | |
100 | | void TransportMgrBase::HandleConnectionAttemptComplete(Transport::ActiveTCPConnectionHandle & conn, CHIP_ERROR conErr) |
101 | 0 | { |
102 | 0 | if (mSessionManager != nullptr) |
103 | 0 | { |
104 | 0 | mSessionManager->HandleConnectionAttemptComplete(conn, conErr); |
105 | 0 | } |
106 | 0 | } |
107 | | |
108 | | void TransportMgrBase::HandleConnectionClosed(Transport::ActiveTCPConnectionState & conn, CHIP_ERROR conErr) |
109 | 0 | { |
110 | 0 | if (mSessionManager != nullptr) |
111 | 0 | { |
112 | 0 | mSessionManager->HandleConnectionClosed(conn, conErr); |
113 | 0 | } |
114 | 0 | } |
115 | | #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT |
116 | | |
117 | | } // namespace chip |