1 /*
2  * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef LIGHT_LUX_BUFFER_H
17 #define LIGHT_LUX_BUFFER_H
18 
19 #include <cstdint>
20 #include <iostream>
21 #include <sstream>
22 
23 namespace OHOS {
24 namespace DisplayPowerMgr {
25 
26 class LightLuxBuffer {
27 public:
28     explicit LightLuxBuffer(unsigned int initialCapacity = LUX_BUFFER_SIZE_DEFAULT);
29     virtual ~LightLuxBuffer();
30     LightLuxBuffer(const LightLuxBuffer&) = delete;
31     LightLuxBuffer& operator=(const LightLuxBuffer&) = delete;
32     LightLuxBuffer(LightLuxBuffer&&) = delete;
33     LightLuxBuffer& operator=(LightLuxBuffer&&) = delete;
34 
35     void Push(const int64_t timestamp, const float data);
36     void Prune(const int64_t horizon);
37     void Clear();
38     float GetData(const unsigned int index) const;
39     int64_t GetTime(const unsigned int index) const;
40     unsigned int GetSize() const;
41     std::string ToString(unsigned int n);
42 
43 private:
44     unsigned int OffsetOf(const unsigned int index) const;
45     int LuxBufferCheck();
46     int CopyLuxBuffer(int newSize);
47 
48 private:
49     static const unsigned int LUX_BUFFER_SIZE_DEFAULT = 32;
50 
51     float* mBufferData {nullptr};
52     int64_t* mBufferTime {nullptr};
53     unsigned int mCapacity {0};
54     unsigned int mStart {0};
55     unsigned int mEnd {0};
56     unsigned int mCount {0};
57 };
58 } // namespace BrightnessPowerMgr
59 } // namespace OHOS
60 #endif // LIGHT_LUX_RING_BUFFER_H