1595d5899Sopenharmony_ci/*
2595d5899Sopenharmony_ci * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3595d5899Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4595d5899Sopenharmony_ci * you may not use this file except in compliance with the License.
5595d5899Sopenharmony_ci * You may obtain a copy of the License at
6595d5899Sopenharmony_ci *
7595d5899Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8595d5899Sopenharmony_ci *
9595d5899Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10595d5899Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11595d5899Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12595d5899Sopenharmony_ci * See the License for the specific language governing permissions and
13595d5899Sopenharmony_ci * limitations under the License.
14595d5899Sopenharmony_ci */
15595d5899Sopenharmony_ci
16595d5899Sopenharmony_ci#ifndef LIGHT_LUX_BUFFER_H
17595d5899Sopenharmony_ci#define LIGHT_LUX_BUFFER_H
18595d5899Sopenharmony_ci
19595d5899Sopenharmony_ci#include <cstdint>
20595d5899Sopenharmony_ci#include <iostream>
21595d5899Sopenharmony_ci#include <sstream>
22595d5899Sopenharmony_ci
23595d5899Sopenharmony_cinamespace OHOS {
24595d5899Sopenharmony_cinamespace DisplayPowerMgr {
25595d5899Sopenharmony_ci
26595d5899Sopenharmony_ciclass LightLuxBuffer {
27595d5899Sopenharmony_cipublic:
28595d5899Sopenharmony_ci    explicit LightLuxBuffer(unsigned int initialCapacity = LUX_BUFFER_SIZE_DEFAULT);
29595d5899Sopenharmony_ci    virtual ~LightLuxBuffer();
30595d5899Sopenharmony_ci    LightLuxBuffer(const LightLuxBuffer&) = delete;
31595d5899Sopenharmony_ci    LightLuxBuffer& operator=(const LightLuxBuffer&) = delete;
32595d5899Sopenharmony_ci    LightLuxBuffer(LightLuxBuffer&&) = delete;
33595d5899Sopenharmony_ci    LightLuxBuffer& operator=(LightLuxBuffer&&) = delete;
34595d5899Sopenharmony_ci
35595d5899Sopenharmony_ci    void Push(const int64_t timestamp, const float data);
36595d5899Sopenharmony_ci    void Prune(const int64_t horizon);
37595d5899Sopenharmony_ci    void Clear();
38595d5899Sopenharmony_ci    float GetData(const unsigned int index) const;
39595d5899Sopenharmony_ci    int64_t GetTime(const unsigned int index) const;
40595d5899Sopenharmony_ci    unsigned int GetSize() const;
41595d5899Sopenharmony_ci    std::string ToString(unsigned int n);
42595d5899Sopenharmony_ci
43595d5899Sopenharmony_ciprivate:
44595d5899Sopenharmony_ci    unsigned int OffsetOf(const unsigned int index) const;
45595d5899Sopenharmony_ci    int LuxBufferCheck();
46595d5899Sopenharmony_ci    int CopyLuxBuffer(int newSize);
47595d5899Sopenharmony_ci
48595d5899Sopenharmony_ciprivate:
49595d5899Sopenharmony_ci    static const unsigned int LUX_BUFFER_SIZE_DEFAULT = 32;
50595d5899Sopenharmony_ci
51595d5899Sopenharmony_ci    float* mBufferData {nullptr};
52595d5899Sopenharmony_ci    int64_t* mBufferTime {nullptr};
53595d5899Sopenharmony_ci    unsigned int mCapacity {0};
54595d5899Sopenharmony_ci    unsigned int mStart {0};
55595d5899Sopenharmony_ci    unsigned int mEnd {0};
56595d5899Sopenharmony_ci    unsigned int mCount {0};
57595d5899Sopenharmony_ci};
58595d5899Sopenharmony_ci} // namespace BrightnessPowerMgr
59595d5899Sopenharmony_ci} // namespace OHOS
60595d5899Sopenharmony_ci#endif // LIGHT_LUX_RING_BUFFER_H