forked from project-chip/connectedhomeip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBufferedReadCallback.h
138 lines (120 loc) · 5.04 KB
/
BufferedReadCallback.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/*
*
* Copyright (c) 2021 Project CHIP Authors
* All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include "lib/core/TLV.h"
#include "system/SystemPacketBuffer.h"
#include "system/TLVPacketBufferBackingStore.h"
#include <app/AppConfig.h>
#include <app/AttributePathParams.h>
#include <app/ReadClient.h>
#include <vector>
#if CHIP_CONFIG_ENABLE_READ_CLIENT
namespace chip {
namespace app {
/*
* This is an adapter that intercepts calls that deliver data from the ReadClient,
* selectively buffers up list chunks in TLV and reconstitutes them into a singular, contiguous TLV array
* upon completion of delivery of all chunks. This is then delivered to a compliant ReadClient::Callback
* without any awareness on their part that chunking happened.
*
*/
class BufferedReadCallback : public ReadClient::Callback
{
public:
BufferedReadCallback(Callback & callback) : mCallback(callback) {}
private:
/*
* Generates the reconsistuted TLV array from the stored individual list elements
*/
CHIP_ERROR GenerateListTLV(TLV::ScopedBufferTLVReader & reader);
/*
* Dispatch any buffered list data if we need to. Buffered data will only be dispatched if:
* 1. The path provided in aPath is different from the buffered path being tracked internally AND the type of data
* in the buffer is list data
*
* OR
*
* 2. The path provided in aPath is similar to what is buffered but we've hit the end of the report.
*
*/
CHIP_ERROR DispatchBufferedData(const ConcreteAttributePath & aPath, const StatusIB & aStatus, bool aEndOfReport = false);
/*
* Buffer up list data as they arrive.
*/
CHIP_ERROR BufferData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apReader);
//
// ReadClient::Callback
//
void OnReportBegin() override;
void OnReportEnd() override;
void OnAttributeData(const ConcreteDataAttributePath & aPath, TLV::TLVReader * apData, const StatusIB & aStatus) override;
void OnError(CHIP_ERROR aError) override
{
mBufferedList.clear();
return mCallback.OnError(aError);
}
void OnEventData(const EventHeader & aEventHeader, TLV::TLVReader * apData, const StatusIB * apStatus) override
{
return mCallback.OnEventData(aEventHeader, apData, apStatus);
}
void OnDone(ReadClient * apReadClient) override { return mCallback.OnDone(apReadClient); }
void OnSubscriptionEstablished(SubscriptionId aSubscriptionId) override
{
mCallback.OnSubscriptionEstablished(aSubscriptionId);
}
CHIP_ERROR OnResubscriptionNeeded(ReadClient * apReadClient, CHIP_ERROR aTerminationCause) override
{
return mCallback.OnResubscriptionNeeded(apReadClient, aTerminationCause);
}
void OnDeallocatePaths(chip::app::ReadPrepareParams && aReadPrepareParams) override
{
return mCallback.OnDeallocatePaths(std::move(aReadPrepareParams));
}
virtual CHIP_ERROR OnUpdateDataVersionFilterList(DataVersionFilterIBs::Builder & aDataVersionFilterIBsBuilder,
const Span<AttributePathParams> & aAttributePaths,
bool & aEncodedDataVersionList) override
{
return mCallback.OnUpdateDataVersionFilterList(aDataVersionFilterIBsBuilder, aAttributePaths, aEncodedDataVersionList);
}
virtual CHIP_ERROR GetHighestReceivedEventNumber(Optional<EventNumber> & aEventNumber) override
{
return mCallback.GetHighestReceivedEventNumber(aEventNumber);
}
void OnUnsolicitedMessageFromPublisher(ReadClient * apReadClient) override
{
return mCallback.OnUnsolicitedMessageFromPublisher(apReadClient);
}
void OnCASESessionEstablished(const SessionHandle & aSession, ReadPrepareParams & aSubscriptionParams) override
{
return mCallback.OnCASESessionEstablished(aSession, aSubscriptionParams);
}
/*
* Given a reader positioned at a list element, allocate a packet buffer, copy the list item where
* the reader is positioned into that buffer and add it to our buffered list for tracking.
*
* This should be called in list index order starting from the lowest index that needs to be buffered.
*
*/
CHIP_ERROR BufferListItem(TLV::TLVReader & reader);
ConcreteDataAttributePath mBufferedPath;
std::vector<System::PacketBufferHandle> mBufferedList;
Callback & mCallback;
};
} // namespace app
} // namespace chip
#endif // CHIP_CONFIG_ENABLE_READ_CLIENT