3 * Copyright (c) 2020 Project CHIP Authors
4 * Copyright (c) 2016-2017 Nest Labs, Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 * Class declarations for a Counter base class, and a monotonically-increasing counter.
29 #include <core/CHIPError.h>
37 * An interface for managing a counter as an integer value.
48 * Advance the value of the counter.
50 * @return A CHIP error code if anything failed, CHIP_NO_ERROR otherwise.
52 virtual CHIP_ERROR Advance() = 0;
56 * Get the current value of the counter.
58 * @return The current value of the counter.
60 virtual uint32_t GetValue() = 0;
64 * @class MonotonicallyIncreasingCounter
67 * A class for managing a monotonically-increasing counter as an integer value.
70 class MonotonicallyIncreasingCounter : public Counter
73 MonotonicallyIncreasingCounter();
74 ~MonotonicallyIncreasingCounter() override;
78 * Initialize a MonotonicallyIncreasingCounter object.
80 * @param[in] aStartValue The starting value of the counter.
82 * @return A CHIP error code if something fails, CHIP_NO_ERROR otherwise
84 CHIP_ERROR Init(uint32_t aStartValue);
88 * Advance the value of the counter.
90 * @return A CHIP error code if something fails, CHIP_NO_ERROR otherwise
92 CHIP_ERROR Advance() override;
96 * Get the current value of the counter.
98 * @return The current value of the counter.
100 uint32_t GetValue() override;
103 uint32_t mCounterValue;