Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / MessageDef / Builder.h
1 /**
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2016-2017 Nest Labs, Inc.
5  *
6  *    Licensed under the Apache License, Version 2.0 (the "License");
7  *    you may not use this file except in compliance with the License.
8  *    You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *    Unless required by applicable law or agreed to in writing, software
13  *    distributed under the License is distributed on an "AS IS" BASIS,
14  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *    See the License for the specific language governing permissions and
16  *    limitations under the License.
17  */
18 /**
19  *    @file
20  *      This file defines builder in CHIP interaction model
21  *
22  */
23
24 #pragma once
25
26 #ifndef _CHIP_INTERACTION_MODEL_MESSAGE_DEF_BUILDER_H
27 #define _CHIP_INTERACTION_MODEL_MESSAGE_DEF_BUILDER_H
28
29 #include <core/CHIPCore.h>
30 #include <core/CHIPTLV.h>
31 #include <support/CodeUtils.h>
32 #include <support/logging/CHIPLogging.h>
33 #include <util/basic-types.h>
34
35 namespace chip {
36 namespace app {
37 class Builder
38 {
39 public:
40     /**
41      *  @brief Initialize the Builder object with TLVWriter and ContainerType
42      *
43      *  @param [in] apWriter A pointer to a TLVWriter
44      *  @param [in] aOuterContainerType outer container type
45      *
46      */
47     void Init(chip::TLV::TLVWriter * const apWriter, chip::TLV::TLVType aOuterContainerType);
48
49     /**
50      *  @brief Reset the Error
51      *
52      */
53     void ResetError();
54
55     /**
56      *  @brief Reset the Error with particular aErr.
57      *  @param [in] aErr the Error it would be reset with
58      *
59      */
60     void ResetError(CHIP_ERROR aErr);
61
62     /**
63      *  @brief Get current error
64      *
65      *  @return #CHIP_NO_ERROR on success
66      */
67     CHIP_ERROR GetError() const { return mError; };
68
69     /**
70      *  @brief Get TLV Writer
71      *
72      *  @return #Pointer to the TLVWriter
73      */
74     chip::TLV::TLVWriter * GetWriter() { return mpWriter; };
75
76     /**
77      * Checkpoint the current tlv state into a TLVWriter
78      *
79      * @param[out] aPoint A writer to checkpoint the state of the TLV writer into.
80      *                    This writer must not outlive the builder
81      */
82     void Checkpoint(chip::TLV::TLVWriter & aPoint) { aPoint = *mpWriter; };
83
84     /**
85      * Rollback the request state to the checkpointed TLVWriter
86      *
87      * @param[in] aPoint A that captured the state via Checkpoint() at some point in the past
88      */
89     void Rollback(const chip::TLV::TLVWriter & aPoint) { *mpWriter = aPoint; }
90
91 protected:
92     CHIP_ERROR mError;
93     chip::TLV::TLVWriter * mpWriter;
94     chip::TLV::TLVType mOuterContainerType;
95
96     Builder();
97     void EndOfContainer();
98
99     CHIP_ERROR InitAnonymousStructure(chip::TLV::TLVWriter * const apWriter);
100 };
101 }; // namespace app
102 }; // namespace chip
103
104 #endif // _CHIP_INTERACTION_MODEL_MESSAGE_DEF_BUILDER_H