• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 INPUT_AGGREGATOR_H
17 #define INPUT_AGGREGATOR_H
18 
19 #include "mmi_log.h"
20 
21 namespace OHOS {
22 namespace MMI {
23 class Aggregator {
24 public:
25     Aggregator(std::function<int32_t(int32_t, int32_t, std::function<void()>)> addTimer,
26                std::function<int32_t(int32_t)> resetTimer, uint32_t maxRecordCount = 100)
addTimer_(std::move (addTimer))27         : addTimer_(std::move(addTimer)), resetTimer_(std::move(resetTimer)), maxRecordCount_(maxRecordCount)
28     {}
29 
30     bool Record(const LogHeader &lh, const std::string &key, const std::string &record);
31 
32     ~Aggregator();
33 
34 private:
35     struct RecordInfo {
36         std::string record;
37         std::chrono::system_clock::time_point timestamp;
38     };
39     std::string key_;
40     std::vector<RecordInfo> records_;
41     std::function<int32_t(int32_t, int32_t, std::function<void()>)> addTimer_;
42     std::function<int32_t(int32_t)> resetTimer_;
43     int32_t timerId_ { -1 };
44     uint32_t maxRecordCount_ { 0 };
45 
46     void FlushRecords(const LogHeader &lh, const std::string &key = "", const std::string &extraRecord = "");
47 };
48 } // namespace MMI
49 } // namespace OHOS
50 #endif // INPUT_AGGREGATOR_H
51