blob: db694dd477b3e280489e31474c63758be6c9edf7 [file] [log] [blame]
Zang MingJiefbd2d102020-11-18 04:22:38 +08001/*
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 Wanga369e892021-04-09 22:07:32 -070020 * This file defines the classes corresponding to CHIP Exchange Context Delegate.
Zang MingJiefbd2d102020-11-18 04:22:38 +080021 *
22 */
23
24#pragma once
25
Pankaj Garg362c5f22021-04-14 16:35:15 -070026#include <messaging/ApplicationExchangeDispatch.h>
27#include <messaging/ExchangeMessageDispatch.h>
28#include <support/CHIPMem.h>
Zang MingJiefbd2d102020-11-18 04:22:38 +080029#include <system/SystemPacketBuffer.h>
Pankaj Garg362c5f22021-04-14 16:35:15 -070030#include <transport/SecureSessionMgr.h>
Zang MingJiefbd2d102020-11-18 04:22:38 +080031#include <transport/raw/MessageHeader.h>
32
33namespace chip {
Yufeng Wang01031e72020-12-01 09:57:42 -080034namespace Messaging {
Zang MingJiefbd2d102020-11-18 04:22:38 +080035
36class 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 Garg107a3802021-05-25 09:48:45 -070045class DLL_EXPORT ExchangeDelegate
Zang MingJiefbd2d102020-11-18 04:22:38 +080046{
47public:
Pankaj Garg107a3802021-05-25 09:48:45 -070048 virtual ~ExchangeDelegate() {}
Zang MingJiefbd2d102020-11-18 04:22:38 +080049
50 /**
51 * @brief
Boris Zbarsky6c172a22021-07-09 17:08:55 -040052 * 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 MingJiefbd2d102020-11-18 04:22:38 +080064 *
65 * @param[in] ec A pointer to the ExchangeContext object.
66 * @param[in] packetHeader A reference to the PacketHeader object.
Yufeng Wangfda8e092021-02-02 10:01:22 -080067 * @param[in] payloadHeader A reference to the PayloadHeader object.
Kevin Schoedelbc4f8412021-01-08 14:46:39 -050068 * @param[in] payload A handle to the PacketBuffer object holding the message payload.
Zang MingJiefbd2d102020-11-18 04:22:38 +080069 */
yunhanw-google475ae272021-06-23 14:28:20 -070070 virtual CHIP_ERROR OnMessageReceived(ExchangeContext * ec, const PacketHeader & packetHeader,
71 const PayloadHeader & payloadHeader, System::PacketBufferHandle && payload) = 0;
Zang MingJiefbd2d102020-11-18 04:22:38 +080072
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 Garg362c5f22021-04-14 16:35:15 -070090
Pankaj Garg107a3802021-05-25 09:48:45 -070091 virtual ExchangeMessageDispatch * GetMessageDispatch(ReliableMessageMgr * reliableMessageMgr, SecureSessionMgr * sessionMgr)
Pankaj Garg362c5f22021-04-14 16:35:15 -070092 {
Pankaj Garg107a3802021-05-25 09:48:45 -070093 return nullptr;
Pankaj Garg362c5f22021-04-14 16:35:15 -070094 }
Zang MingJiefbd2d102020-11-18 04:22:38 +080095};
96
Yufeng Wang01031e72020-12-01 09:57:42 -080097} // namespace Messaging
Zang MingJiefbd2d102020-11-18 04:22:38 +080098} // namespace chip