3 * Copyright (c) 2020 Project CHIP Authors
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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
19 * This file implements a stateless TransportMgr, it will took a raw message
20 * buffer from transports, and then extract the message header without decode it.
21 * For secure messages, it will pass it to the SecureSessionMgr, and for unsecure
22 * messages (rendezvous messages), it will pass it to RendezvousSession.
23 * When sending messages, it will encode the packet header, and pass it to the
25 * The whole process is fully stateless.
30 #include <support/CodeUtils.h>
31 #include <support/logging/CHIPLogging.h>
32 #include <transport/TransportMgrBase.h>
33 #include <transport/raw/Base.h>
34 #include <transport/raw/MessageHeader.h>
35 #include <transport/raw/PeerAddress.h>
36 #include <transport/raw/Tuple.h>
40 class TransportMgrBase;
42 class TransportMgrDelegate
45 virtual ~TransportMgrDelegate() = default;
48 * Handle received secure message.
50 * @param header the received message header
51 * @param source the source address of the package
52 * @param msgBuf the buffer of (encrypted) payload
54 virtual void OnMessageReceived(const PacketHeader & header, const Transport::PeerAddress & source,
55 System::PacketBufferHandle msgBuf) = 0;
58 template <typename... TransportTypes>
59 class TransportMgr : public TransportMgrBase
62 template <typename... Args>
63 CHIP_ERROR Init(Args &&... transportInitArgs)
65 CHIP_ERROR err = CHIP_NO_ERROR;
67 err = mTransport.Init(this, std::forward<Args>(transportInitArgs)...);
69 err = TransportMgrBase::Init(&mTransport);
74 template <typename... Args>
75 CHIP_ERROR ResetTransport(Args &&... transportInitArgs)
77 return mTransport.Init(this, std::forward<Args>(transportInitArgs)...);
81 Transport::Tuple<TransportTypes...> mTransport;