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
15 * limitations under the License.
20 * Defines base properties and constants valid across all transport
21 * classes (UDP, TCP, BLE, ....)
26 #include <core/CHIPError.h>
27 #include <inet/IPAddress.h>
28 #include <inet/UDPEndPoint.h>
29 #include <system/SystemPacketBuffer.h>
30 #include <transport/raw/MessageHeader.h>
31 #include <transport/raw/PeerAddress.h>
36 class RawTransportDelegate
39 virtual ~RawTransportDelegate() {}
40 virtual void HandleMessageReceived(const PacketHeader & packetHeader, const Transport::PeerAddress & peerAddress,
41 System::PacketBufferHandle msg) = 0;
45 * Transport class base, defining common methods among transports (message
46 * packing by encoding and decoding headers) and generic message transport
55 * Sets the delegate of the transport
57 * @param[in] delegate The argument to pass in to the handler function
60 void SetDelegate(RawTransportDelegate * delegate) { mDelegate = delegate; }
63 * @brief Send a message to the specified target.
65 * On connection-oriented transports, sending a message implies connecting to the target first.
67 virtual CHIP_ERROR SendMessage(const PacketHeader & header, const PeerAddress & address, System::PacketBufferHandle msgBuf) = 0;
70 * Determine if this transport can SendMessage to the specified peer address.
72 * Generally it is expected that a transport can send to any peer from which it receives a message.
74 virtual bool CanSendToPeer(const PeerAddress & address) = 0;
77 * Handle disconnection from the specified peer if currently connected to it.
79 virtual void Disconnect(const PeerAddress & address) {}
82 * Close the open endpoint without destroying the object
84 virtual void Close(){};
88 * Method used by subclasses to notify that a packet has been received after
89 * any associated headers have been decoded.
91 void HandleMessageReceived(const PacketHeader & header, const PeerAddress & source, System::PacketBufferHandle && buffer)
93 mDelegate->HandleMessageReceived(header, source, std::move(buffer));
96 RawTransportDelegate * mDelegate;
99 } // namespace Transport