Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) 2020 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 | * limitations under the License. |
| 16 | */ |
| 17 | |
| 18 | /** |
| 19 | * @file |
Yufeng Wang | a369e89 | 2021-04-09 22:07:32 -0700 | [diff] [blame] | 20 | * This file defines the classes corresponding to CHIP Exchange Context Delegate. |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #pragma once |
| 25 | |
Pankaj Garg | 362c5f2 | 2021-04-14 16:35:15 -0700 | [diff] [blame] | 26 | #include <messaging/ApplicationExchangeDispatch.h> |
| 27 | #include <messaging/ExchangeMessageDispatch.h> |
| 28 | #include <support/CHIPMem.h> |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 29 | #include <system/SystemPacketBuffer.h> |
Pankaj Garg | 362c5f2 | 2021-04-14 16:35:15 -0700 | [diff] [blame] | 30 | #include <transport/SecureSessionMgr.h> |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 31 | #include <transport/raw/MessageHeader.h> |
| 32 | |
| 33 | namespace chip { |
Yufeng Wang | 01031e7 | 2020-12-01 09:57:42 -0800 | [diff] [blame] | 34 | namespace Messaging { |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 35 | |
| 36 | class ExchangeContext; |
| 37 | |
| 38 | /** |
| 39 | * @brief |
| 40 | * This class provides a skeleton for the callback functions. The functions will be |
| 41 | * called by ExchangeContext object on specific events. If the user of ExchangeContext |
| 42 | * is interested in receiving these callbacks, they can specialize this class and handle |
| 43 | * each trigger in their implementation of this class. |
| 44 | */ |
Pankaj Garg | 107a380 | 2021-05-25 09:48:45 -0700 | [diff] [blame] | 45 | class DLL_EXPORT ExchangeDelegate |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 46 | { |
| 47 | public: |
Pankaj Garg | 107a380 | 2021-05-25 09:48:45 -0700 | [diff] [blame] | 48 | virtual ~ExchangeDelegate() {} |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 49 | |
| 50 | /** |
| 51 | * @brief |
Boris Zbarsky | 6c172a2 | 2021-07-09 17:08:55 -0400 | [diff] [blame^] | 52 | * This function is the protocol callback for handling a received CHIP |
| 53 | * message. |
| 54 | * |
| 55 | * After calling this method an exchange will close itself unless one of |
| 56 | * two things happens: |
| 57 | * |
| 58 | * 1) A call to SendMessage on the exchange with the kExpectResponse flag |
| 59 | * set. |
| 60 | * 2) A call to WillSendMessage on the exchange. |
| 61 | * |
| 62 | * Consumers that don't do one of those things MUST NOT retain a pointer |
| 63 | * to the exchange. |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 64 | * |
| 65 | * @param[in] ec A pointer to the ExchangeContext object. |
| 66 | * @param[in] packetHeader A reference to the PacketHeader object. |
Yufeng Wang | fda8e09 | 2021-02-02 10:01:22 -0800 | [diff] [blame] | 67 | * @param[in] payloadHeader A reference to the PayloadHeader object. |
Kevin Schoedel | bc4f841 | 2021-01-08 14:46:39 -0500 | [diff] [blame] | 68 | * @param[in] payload A handle to the PacketBuffer object holding the message payload. |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 69 | */ |
yunhanw-google | 475ae27 | 2021-06-23 14:28:20 -0700 | [diff] [blame] | 70 | virtual CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader, |
| 71 | const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) = 0; |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * @brief |
| 75 | * This function is the protocol callback to invoke when the timeout for the receipt |
| 76 | * of a response message has expired. |
| 77 | * |
| 78 | * @param[in] ec A pointer to the ExchangeContext object. |
| 79 | */ |
| 80 | virtual void OnResponseTimeout(ExchangeContext * ec) = 0; |
| 81 | |
| 82 | /** |
| 83 | * @brief |
| 84 | * This function is the protocol callback to invoke when the associated |
| 85 | * exchange context is being closed |
| 86 | * |
| 87 | * @param[in] ec A pointer to the ExchangeContext object. |
| 88 | */ |
| 89 | virtual void OnExchangeClosing(ExchangeContext * ec) {} |
Pankaj Garg | 362c5f2 | 2021-04-14 16:35:15 -0700 | [diff] [blame] | 90 | |
Pankaj Garg | 107a380 | 2021-05-25 09:48:45 -0700 | [diff] [blame] | 91 | virtual ExchangeMessageDispatch * GetMessageDispatch(ReliableMessageMgr * reliableMessageMgr, SecureSessionMgr * sessionMgr) |
Pankaj Garg | 362c5f2 | 2021-04-14 16:35:15 -0700 | [diff] [blame] | 92 | { |
Pankaj Garg | 107a380 | 2021-05-25 09:48:45 -0700 | [diff] [blame] | 93 | return nullptr; |
Pankaj Garg | 362c5f2 | 2021-04-14 16:35:15 -0700 | [diff] [blame] | 94 | } |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 95 | }; |
| 96 | |
Yufeng Wang | 01031e7 | 2020-12-01 09:57:42 -0800 | [diff] [blame] | 97 | } // namespace Messaging |
Zang MingJie | fbd2d10 | 2020-11-18 04:22:38 +0800 | [diff] [blame] | 98 | } // namespace chip |