Line data Source code
1 : /**
2 : *
3 : * Copyright (c) 2021 Project CHIP Authors
4 : * Licensed under the Apache License, Version 2.0 (the "License");
5 : * you may not use this file except in compliance with the License.
6 : * You may obtain a copy of the License at
7 : *
8 : * http://www.apache.org/licenses/LICENSE-2.0
9 : *
10 : * Unless required by applicable law or agreed to in writing, software
11 : * distributed under the License is distributed on an "AS IS" BASIS,
12 : * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 : * See the License for the specific language governing permissions and
14 : * limitations under the License.
15 : */
16 :
17 : #include "DataVersionFilterIBs.h"
18 :
19 : #include "MessageDefHelper.h"
20 :
21 : #include <inttypes.h>
22 : #include <stdarg.h>
23 : #include <stdio.h>
24 :
25 : #include <app/AppConfig.h>
26 :
27 : namespace chip {
28 : namespace app {
29 : #if CHIP_CONFIG_IM_PRETTY_PRINT
30 148 : CHIP_ERROR DataVersionFilterIBs::Parser::PrettyPrint() const
31 : {
32 148 : CHIP_ERROR err = CHIP_NO_ERROR;
33 148 : TLV::TLVReader reader;
34 :
35 148 : PRETTY_PRINT("DataVersionFilterIBs =");
36 148 : PRETTY_PRINT("[");
37 :
38 : // make a copy of the reader
39 148 : reader.Init(mReader);
40 :
41 2643 : while (CHIP_NO_ERROR == (err = reader.Next()))
42 : {
43 2495 : VerifyOrReturnError(TLV::AnonymousTag() == reader.GetTag(), CHIP_ERROR_INVALID_TLV_TAG);
44 : {
45 2495 : DataVersionFilterIB::Parser DataVersionFilter;
46 2495 : ReturnErrorOnFailure(DataVersionFilter.Init(reader));
47 2495 : PRETTY_PRINT_INCDEPTH();
48 2495 : ReturnErrorOnFailure(DataVersionFilter.PrettyPrint());
49 2495 : PRETTY_PRINT_DECDEPTH();
50 : }
51 : }
52 :
53 148 : PRETTY_PRINT("],");
54 148 : PRETTY_PRINT_BLANK_LINE();
55 :
56 : // if we have exhausted this container
57 148 : if (CHIP_END_OF_TLV == err)
58 : {
59 148 : err = CHIP_NO_ERROR;
60 : }
61 148 : ReturnErrorOnFailure(err);
62 148 : return reader.ExitContainer(mOuterContainerType);
63 : }
64 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
65 :
66 3037 : DataVersionFilterIB::Builder & DataVersionFilterIBs::Builder::CreateDataVersionFilter()
67 : {
68 3037 : mError = mDataVersionFilter.Init(mpWriter);
69 3037 : return mDataVersionFilter;
70 : }
71 :
72 3034 : CHIP_ERROR DataVersionFilterIBs::Builder::EncodeDataVersionFilterIB(const DataVersionFilter & aFilter)
73 : {
74 3034 : DataVersionFilterIB::Builder & filterIB = CreateDataVersionFilter();
75 3034 : ReturnErrorOnFailure(GetError());
76 3016 : ClusterPathIB::Builder & path = filterIB.CreatePath();
77 3016 : ReturnErrorOnFailure(filterIB.GetError());
78 2989 : ReturnErrorOnFailure(path.Endpoint(aFilter.mEndpointId).Cluster(aFilter.mClusterId).EndOfClusterPathIB());
79 2905 : ReturnErrorOnFailure(filterIB.DataVersion(aFilter.mDataVersion.Value()).EndOfDataVersionFilterIB());
80 :
81 2878 : ChipLogProgress(DataManagement, "Encoded DataVersionFilter: Endpoint=%u Cluster=" ChipLogFormatMEI " Version=%" PRIu32,
82 : aFilter.mEndpointId, ChipLogValueMEI(aFilter.mClusterId), aFilter.mDataVersion.Value());
83 :
84 2878 : return CHIP_NO_ERROR;
85 : }
86 :
87 148 : CHIP_ERROR DataVersionFilterIBs::Builder::EndOfDataVersionFilterIBs()
88 : {
89 148 : EndOfContainer();
90 148 : return GetError();
91 : }
92 : } // namespace app
93 : } // namespace chip
|