Line data Source code
1 : /*
2 : * Copyright (c) 2024 Project CHIP Authors
3 : * All rights reserved.
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 : #pragma once
19 :
20 : #include <access/SubjectDescriptor.h>
21 : #include <lib/core/DataModelTypes.h>
22 : #include <lib/core/GroupId.h>
23 : #include <lib/core/Optional.h>
24 : #include <messaging/ExchangeContext.h>
25 : #include <protocols/interaction_model/StatusCode.h>
26 : #include <system/SystemPacketBuffer.h>
27 :
28 : namespace chip {
29 : namespace app {
30 :
31 : /**
32 : * Interface for sending InvokeResponseMessage(s).
33 : *
34 : * Provides information about the associated exchange context.
35 : *
36 : * Design Rationale: This interface enhances unit testability and allows applications to
37 : * customize InvokeResponse behavior. For example, a bridge application might locally execute
38 : * a command using cluster APIs without intending to sending a response on an exchange.
39 : * These cluster APIs require providing an instance of CommandHandler where a status response
40 : * is added (see https://github.com/project-chip/connectedhomeip/issues/32030).
41 : */
42 : class CommandHandlerExchangeInterface
43 : {
44 : public:
45 16 : virtual ~CommandHandlerExchangeInterface() = default;
46 :
47 : /**
48 : * Get a non-owning pointer to the exchange context the InvokeRequestMessage was
49 : * delivered on.
50 : *
51 : * @return The exchange context. Might be nullptr if no exchange context has been
52 : * assigned or the context has been released. For example, the exchange
53 : * context might not be assigned in unit tests, or if an application wishes
54 : * to locally execute cluster APIs and still receive response data without
55 : * sending it on an exchange.
56 : */
57 : virtual Messaging::ExchangeContext * GetExchangeContext() const = 0;
58 :
59 : // TODO(#30453): Follow up refactor. It should be possible to remove
60 : // GetSubjectDescriptor and GetAccessingFabricIndex, as CommandHandler can get these
61 : // values from ExchangeContext.
62 :
63 : /**
64 : * Gets subject descriptor of the exchange.
65 : *
66 : * WARNING: This method should only be called when the caller is certain the
67 : * session has not been evicted.
68 : */
69 : virtual Access::SubjectDescriptor GetSubjectDescriptor() const = 0;
70 :
71 : /**
72 : * Gets accessing fabic index of the exchange.
73 : *
74 : * WARNING: This method should only be called when the caller is certain the
75 : * session has not been evicted.
76 : */
77 : virtual FabricIndex GetAccessingFabricIndex() const = 0;
78 : /**
79 : * If session for the exchange is a group session, returns its group ID. Otherwise,
80 : * returns a null optional.
81 : */
82 : virtual Optional<GroupId> GetGroupId() const = 0;
83 :
84 : /**
85 : * @brief Called to indicate a slow command is being processed.
86 : *
87 : * Enables the exchange to send whatever transport-level acks might be needed without waiting
88 : * for command processing to complete.
89 : */
90 : virtual void HandlingSlowCommand() = 0;
91 :
92 : /**
93 : * @brief Adds a completed InvokeResponseMessage to the queue for sending to requester.
94 : *
95 : * Called by CommandHandler.
96 : */
97 : virtual void AddInvokeResponseToSend(System::PacketBufferHandle && aPacket) = 0;
98 :
99 : /**
100 : * @brief Called to indicate that an InvokeResponse was dropped.
101 : *
102 : * Called by CommandHandler to relay this information to the requester.
103 : */
104 : virtual void ResponseDropped() = 0;
105 :
106 : /**
107 : * @brief Gets the maximum size of a packet buffer to encode a Command
108 : * Response message. This size depends on the underlying session used
109 : * by the exchange.
110 : *
111 : * The size returned here is the size not including the prepended headers.
112 : *
113 : * Called by CommandHandler when allocating buffer for encoding the Command
114 : * response.
115 : */
116 : virtual size_t GetCommandResponseMaxBufferSize() = 0;
117 : };
118 :
119 : } // namespace app
120 : } // namespace chip
|