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 <lib/core/CHIPError.h>
21 : #include <lib/core/Optional.h>
22 :
23 : namespace chip {
24 : namespace app {
25 :
26 : /**
27 : * @brief Interface for tracking responses to outbound InvokeRequests.
28 : *
29 : * This interface enables clients to:
30 : * * Verify that received responses correspond to issued InvokeRequests.
31 : * * Detect outstanding responses after the server indicates completion, helpful for identifying response omissions.
32 : */
33 : class PendingResponseTracker
34 : {
35 : public:
36 15 : virtual ~PendingResponseTracker() = default;
37 :
38 : /**
39 : * Start tracking the given `aCommandRef`
40 : *
41 : * @return CHIP_ERROR_INVALID_ARGUMENT if `aCommandRef` is already being tracked.
42 : */
43 : virtual CHIP_ERROR Add(uint16_t aCommandRef) = 0;
44 :
45 : /**
46 : * Removes tracking for the given `aCommandRef`
47 : *
48 : * @return CHIP_ERROR_KEY_NOT_FOUND if aCommandRef is not currently tracked.
49 : */
50 : virtual CHIP_ERROR Remove(uint16_t aCommandRef) = 0;
51 :
52 : /**
53 : * Checks if the given `aCommandRef` is being tracked.
54 : */
55 : virtual bool IsTracked(uint16_t aCommandRef) = 0;
56 :
57 : /**
58 : * Returns the number of pending responses.
59 : */
60 : virtual size_t Count() = 0;
61 :
62 : /**
63 : * Removes a pending response command reference from the tracker.
64 : *
65 : * Deletes an element from the tracker (order not guaranteed). This function can be called
66 : * repeatedly to remove all tracked pending responses.
67 : *
68 : * @return NullOptional if the tracker is empty.
69 : * @return Optional containing the CommandReference of a removed pending response.
70 : */
71 : virtual Optional<uint16_t> PopPendingResponse() = 0;
72 : };
73 :
74 : } // namespace app
75 : } // namespace chip
|