• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2022 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 HISYSEVENT_BASE_QUERY_CALLBACK_H
17 #define HISYSEVENT_BASE_QUERY_CALLBACK_H
18 
19 #include <string>
20 #include <vector>
21 
22 #include "hisysevent_record.h"
23 #include "hisysevent_query_callback.h"
24 
25 namespace OHOS {
26 namespace HiviewDFX {
27 class HiSysEventBaseQueryCallback {
28 public:
29     HiSysEventBaseQueryCallback() = default;
HiSysEventBaseQueryCallback(std::shared_ptr<HiSysEventQueryCallback> callback)30     HiSysEventBaseQueryCallback(std::shared_ptr<HiSysEventQueryCallback> callback): callback(callback) {}
~HiSysEventBaseQueryCallback()31     virtual ~HiSysEventBaseQueryCallback() {}
32 
33 public:
OnQuery(const::std::vector<std::string> & sysEvents,const std::vector<int64_t> & seqs)34     virtual void OnQuery(const ::std::vector<std::string>& sysEvents,
35         const std::vector<int64_t>& seqs)
36     {
37         if (callback != nullptr) {
38             auto records = std::make_shared<std::vector<HiSysEventRecord>>();
39             for_each(sysEvents.cbegin(), sysEvents.cend(), [&records](const std::string& content) {
40                 records->emplace_back(HiSysEventRecord(content));
41             });
42             callback->OnQuery(records);
43         }
44     }
45 
OnComplete(int32_t reason,int32_t total)46     virtual void OnComplete(int32_t reason, int32_t total)
47     {
48         if (callback != nullptr) {
49             callback->OnComplete(reason, total);
50         }
51     }
52 
OnComplete(int32_t reason,int32_t total,int64_t seq)53     virtual void OnComplete(int32_t reason, int32_t total, int64_t seq)
54     {
55         OnComplete(reason, total);
56     }
57 
58 private:
59     HiSysEventBaseQueryCallback(const HiSysEventBaseQueryCallback&) = delete;
60     HiSysEventBaseQueryCallback& operator=(const HiSysEventBaseQueryCallback&) = delete;
61     HiSysEventBaseQueryCallback(const HiSysEventBaseQueryCallback&&) = delete;
62     HiSysEventBaseQueryCallback& operator=(const HiSysEventBaseQueryCallback&&) = delete;
63 
64 private:
65     std::shared_ptr<HiSysEventQueryCallback> callback;
66 };
67 } // namespace HiviewDFX
68 } // namespace OHOS
69 
70 #endif // HISYSEVENT_BASE_QUERY_CALLBACK_H
71