Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / lib / support / CHIPCounter.h
1 /*
2  *
3  *    Copyright (c) 2020 Project CHIP Authors
4  *    Copyright (c) 2016-2017 Nest Labs, Inc.
5  *    All rights reserved.
6  *
7  *    Licensed under the Apache License, Version 2.0 (the "License");
8  *    you may not use this file except in compliance with the License.
9  *    You may obtain a copy of the License at
10  *
11  *        http://www.apache.org/licenses/LICENSE-2.0
12  *
13  *    Unless required by applicable law or agreed to in writing, software
14  *    distributed under the License is distributed on an "AS IS" BASIS,
15  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  *    See the License for the specific language governing permissions and
17  *    limitations under the License.
18  */
19
20 /**
21  * @file
22  *
23  * @brief
24  *   Class declarations for a Counter base class, and a monotonically-increasing counter.
25  */
26
27 #pragma once
28
29 #include <core/CHIPError.h>
30
31 namespace chip {
32
33 /**
34  * @class Counter
35  *
36  * @brief
37  *   An interface for managing a counter as an integer value.
38  */
39
40 class Counter
41 {
42 public:
43     Counter() {}
44     virtual ~Counter() {}
45
46     /**
47      *  @brief
48      *  Advance the value of the counter.
49      *
50      *  @return A CHIP error code if anything failed, CHIP_NO_ERROR otherwise.
51      */
52     virtual CHIP_ERROR Advance() = 0;
53
54     /**
55      *  @brief
56      *  Get the current value of the counter.
57      *
58      *  @return The current value of the counter.
59      */
60     virtual uint32_t GetValue() = 0;
61 };
62
63 /**
64  * @class MonotonicallyIncreasingCounter
65  *
66  * @brief
67  *   A class for managing a monotonically-increasing counter as an integer value.
68  */
69
70 class MonotonicallyIncreasingCounter : public Counter
71 {
72 public:
73     MonotonicallyIncreasingCounter();
74     ~MonotonicallyIncreasingCounter() override;
75
76     /**
77      *  @brief
78      *    Initialize a MonotonicallyIncreasingCounter object.
79      *
80      *  @param[in] aStartValue  The starting value of the counter.
81      *
82      *  @return A CHIP error code if something fails, CHIP_NO_ERROR otherwise
83      */
84     CHIP_ERROR Init(uint32_t aStartValue);
85
86     /**
87      *  @brief
88      *  Advance the value of the counter.
89      *
90      *  @return A CHIP error code if something fails, CHIP_NO_ERROR otherwise
91      */
92     CHIP_ERROR Advance() override;
93
94     /**
95      *  @brief
96      *  Get the current value of the counter.
97      *
98      *  @return The current value of the counter.
99      */
100     uint32_t GetValue() override;
101
102 protected:
103     uint32_t mCounterValue;
104 };
105
106 } // namespace chip