Line data Source code
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 : #pragma once
18 :
19 : #include <lib/support/CodeUtils.h>
20 : #include <system/SystemPacketBuffer.h>
21 : #include <transport/raw/Base.h>
22 : #include <transport/raw/MessageHeader.h>
23 : #include <transport/raw/PeerAddress.h>
24 : #if INET_CONFIG_ENABLE_TCP_ENDPOINT
25 : #include <transport/raw/TCP.h>
26 : #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
27 :
28 : namespace chip {
29 :
30 : namespace Transport {
31 : class Base;
32 : }
33 :
34 : class TransportMgrDelegate;
35 :
36 : class TransportMgrBase : public Transport::RawTransportDelegate
37 : {
38 : public:
39 : CHIP_ERROR Init(Transport::Base * transport);
40 :
41 : CHIP_ERROR SendMessage(const Transport::PeerAddress & address, System::PacketBufferHandle && msgBuf);
42 :
43 : void Close();
44 :
45 : #if INET_CONFIG_ENABLE_TCP_ENDPOINT
46 : CHIP_ERROR TCPConnect(const Transport::PeerAddress & address, Transport::AppTCPConnectionCallbackCtxt * appState,
47 : Transport::ActiveTCPConnectionState ** peerConnState);
48 :
49 : void TCPDisconnect(const Transport::PeerAddress & address);
50 :
51 : void TCPDisconnect(Transport::ActiveTCPConnectionState * conn, bool shouldAbort = 0);
52 :
53 : void HandleConnectionReceived(Transport::ActiveTCPConnectionState * conn) override;
54 :
55 : void HandleConnectionAttemptComplete(Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr) override;
56 :
57 : void HandleConnectionClosed(Transport::ActiveTCPConnectionState * conn, CHIP_ERROR conErr) override;
58 : #endif // INET_CONFIG_ENABLE_TCP_ENDPOINT
59 :
60 215 : void SetSessionManager(TransportMgrDelegate * sessionManager) { mSessionManager = sessionManager; }
61 :
62 : TransportMgrDelegate * GetSessionManager() { return mSessionManager; };
63 :
64 : CHIP_ERROR MulticastGroupJoinLeave(const Transport::PeerAddress & address, bool join);
65 :
66 : void HandleMessageReceived(const Transport::PeerAddress & peerAddress, System::PacketBufferHandle && msg,
67 : Transport::MessageTransportContext * ctxt = nullptr) override;
68 :
69 : private:
70 : TransportMgrDelegate * mSessionManager = nullptr;
71 : Transport::Base * mTransport = nullptr;
72 : };
73 :
74 : } // namespace chip
|