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 : * @file
18 : * This file defines DataVersionFilter parser and builder in CHIP interaction model
19 : *
20 : */
21 :
22 : #include "DataVersionFilterIB.h"
23 :
24 : #include "MessageDefHelper.h"
25 :
26 : #include <inttypes.h>
27 : #include <stdarg.h>
28 : #include <stdio.h>
29 :
30 : #include <app/AppConfig.h>
31 :
32 : namespace chip {
33 : namespace app {
34 : #if CHIP_CONFIG_IM_PRETTY_PRINT
35 2496 : CHIP_ERROR DataVersionFilterIB::Parser::PrettyPrint() const
36 : {
37 2496 : CHIP_ERROR err = CHIP_NO_ERROR;
38 2496 : TLV::TLVReader reader;
39 :
40 2496 : PRETTY_PRINT("DataVersionFilterIB =");
41 2496 : PRETTY_PRINT("{");
42 :
43 : // make a copy of the Path reader
44 2496 : reader.Init(mReader);
45 :
46 7488 : while (CHIP_NO_ERROR == (err = reader.Next()))
47 : {
48 4992 : if (!TLV::IsContextTag(reader.GetTag()))
49 : {
50 0 : continue;
51 : }
52 4992 : uint32_t tagNum = TLV::TagNumFromTag(reader.GetTag());
53 4992 : switch (tagNum)
54 : {
55 2496 : case to_underlying(Tag::kPath): {
56 2496 : ClusterPathIB::Parser path;
57 2496 : ReturnErrorOnFailure(path.Init(reader));
58 :
59 2496 : PRETTY_PRINT_INCDEPTH();
60 2496 : ReturnErrorOnFailure(path.PrettyPrint());
61 2496 : PRETTY_PRINT_DECDEPTH();
62 : }
63 2496 : break;
64 2496 : case to_underlying(Tag::kDataVersion):
65 2496 : VerifyOrReturnError(TLV::kTLVType_UnsignedInteger == reader.GetType(), CHIP_ERROR_WRONG_TLV_TYPE);
66 :
67 : #if CHIP_DETAIL_LOGGING
68 : {
69 : chip::DataVersion version;
70 2496 : ReturnErrorOnFailure(reader.Get(version));
71 2496 : PRETTY_PRINT("\tDataVersion = 0x%" PRIx32 ",", version);
72 : }
73 : #endif // CHIP_DETAIL_LOGGING
74 2496 : break;
75 0 : default:
76 0 : PRETTY_PRINT("Unknown tag num %" PRIu32, tagNum);
77 0 : break;
78 : }
79 : }
80 2496 : PRETTY_PRINT("},");
81 2496 : PRETTY_PRINT_BLANK_LINE();
82 :
83 : // if we have exhausted this container
84 2496 : if (CHIP_END_OF_TLV == err)
85 : {
86 2496 : err = CHIP_NO_ERROR;
87 : }
88 2496 : ReturnErrorOnFailure(err);
89 2496 : return reader.ExitContainer(mOuterContainerType);
90 : }
91 : #endif // CHIP_CONFIG_IM_PRETTY_PRINT
92 :
93 2493 : CHIP_ERROR DataVersionFilterIB::Parser::GetPath(ClusterPathIB::Parser * const apPath) const
94 : {
95 2493 : TLV::TLVReader reader;
96 2493 : ReturnErrorOnFailure(mReader.FindElementWithTag(TLV::ContextTag(Tag::kPath), reader));
97 2493 : return apPath->Init(reader);
98 : }
99 :
100 2493 : CHIP_ERROR DataVersionFilterIB::Parser::GetDataVersion(chip::DataVersion * const apVersion) const
101 : {
102 2493 : return GetUnsignedInteger(to_underlying(Tag::kDataVersion), apVersion);
103 : }
104 :
105 3020 : ClusterPathIB::Builder & DataVersionFilterIB::Builder::CreatePath()
106 : {
107 3020 : if (mError == CHIP_NO_ERROR)
108 : {
109 3020 : mError = mPath.Init(mpWriter, to_underlying(Tag::kPath));
110 : }
111 3020 : return mPath;
112 : }
113 :
114 2909 : DataVersionFilterIB::Builder & DataVersionFilterIB::Builder::DataVersion(const chip::DataVersion aDataVersion)
115 : {
116 : // skip if error has already been set
117 2909 : if (mError == CHIP_NO_ERROR)
118 : {
119 2909 : mError = mpWriter->Put(TLV::ContextTag(Tag::kDataVersion), aDataVersion);
120 : }
121 2909 : return *this;
122 : }
123 :
124 2909 : CHIP_ERROR DataVersionFilterIB::Builder::EndOfDataVersionFilterIB()
125 : {
126 2909 : EndOfContainer();
127 2909 : return GetError();
128 : }
129 : } // namespace app
130 : } // namespace chip
|