1 /*
2 * Copyright (c) 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 #include "hisysevent_manager_c.h"
17
18 #include <string>
19
20 #include "hisysevent_base_manager.h"
21 #include "hisysevent_query_callback_c.h"
22 #include "ret_code.h"
23
24 namespace {
25 using OHOS::HiviewDFX::HiSysEventBaseManager;
26 using OHOS::HiviewDFX::HiSysEventBaseQueryCallback;
27 using QueryArgCls = OHOS::HiviewDFX::QueryArg;
28 using QueryRuleCls = OHOS::HiviewDFX::QueryRule;
29 using OHOS::HiviewDFX::RuleType::WHOLE_WORD;
30 using OHOS::HiviewDFX::ERR_QUERY_RULE_INVALID;
31
HiSysEventQuery(const HiSysEventQueryArg & arg,HiSysEventQueryRule rules[],size_t ruleSize,HiSysEventQueryCallback & callback)32 int HiSysEventQuery(const HiSysEventQueryArg& arg, HiSysEventQueryRule rules[], size_t ruleSize,
33 HiSysEventQueryCallback& callback)
34 {
35 std::vector<QueryRuleCls> queryRules;
36 for (size_t i = 0; i < ruleSize; ++i) {
37 if (strlen(rules[i].domain) == 0 || rules[i].eventListSize == 0) {
38 return ERR_QUERY_RULE_INVALID;
39 }
40 std::vector<std::string> eventList;
41 for (size_t j = 0; j < rules[i].eventListSize; ++j) {
42 eventList.emplace_back(rules[i].eventList[j]);
43 }
44 std::string cond = rules[i].condition == nullptr ? "" : rules[i].condition;
45 queryRules.emplace_back(rules[i].domain, eventList, WHOLE_WORD, 0, cond);
46 }
47 QueryArgCls argCls(arg.beginTime, arg.endTime, arg.maxEvents);
48 auto callbackC = std::make_shared<HiSysEventQueryCallbackC>(callback.OnQuery, callback.OnComplete);
49 return HiSysEventBaseManager::Query(argCls, queryRules, std::make_shared<HiSysEventBaseQueryCallback>(callbackC));
50 }
51 }
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
OH_HiSysEvent_Query(const HiSysEventQueryArg & arg,HiSysEventQueryRule rules[],size_t ruleSize,HiSysEventQueryCallback & callback)57 int OH_HiSysEvent_Query(const HiSysEventQueryArg& arg, HiSysEventQueryRule rules[], size_t ruleSize,
58 HiSysEventQueryCallback& callback)
59 {
60 return HiSysEventQuery(arg, rules, ruleSize, callback);
61 }
62
63 #ifdef __cplusplus
64 }
65 #endif
66