• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 //! Rust interfaces for crate hisysevent.
17 
18 mod sys_event_manager;
19 mod sys_event;
20 mod utils;
21 
22 #[macro_use]
23 pub mod macros;
24 
25 pub use sys_event_manager::{HiSysEventRecord, Querier, Watcher};
26 
27 pub use sys_event::{HiSysEventParam, HiSysEventParamType, HiSysEventParamValue, parse_type_len,
28     build_string_arrays};
29 
30 /// Enumerate system event types.
31 #[non_exhaustive]
32 #[derive(Copy, Clone)]
33 pub enum EventType {
34     /// Fault event.
35     Fault = 1,
36 
37     /// Statistic event.
38     Statistic = 2,
39 
40     /// Security event.
41     Security = 3,
42 
43     /// System behavior event.
44     Behavior = 4,
45 }
46 
47 /// Write system event.
write(event_domain: &str, event_name: &str, event_type: EventType, event_params: &[HiSysEventParam]) -> i3248 pub fn write(event_domain: &str, event_name: &str, event_type: EventType,
49     event_params: &[HiSysEventParam]) -> i32 {
50     sys_event::write(event_domain, event_name, event_type as std::ffi::c_int, event_params)
51 }
52 
53 /// Enumerate search system event rule type.
54 #[non_exhaustive]
55 #[derive(Copy, Clone)]
56 pub enum RuleType {
57     /// Whole word match.
58     WholeWord = 1,
59 
60     /// Prefix match.
61     Prefix = 2,
62 
63     /// Regular match.
64     Regular = 3,
65 }
66 
67 /// Definition arguments for query system event information.
68 #[derive(Copy, Clone)]
69 pub struct QueryArg {
70     /// Begin time.
71     pub begin_time: i64,
72 
73     /// End time.
74     pub end_time: i64,
75 
76     /// Max number of receive system event.
77     pub max_events: i32,
78 }
79 
80 /// Definition event for query system event information.
81 pub struct QueryRule<'a> {
82     /// The domain of the event.
83     pub domain: &'a str,
84 
85     /// List of event name.
86     pub event_list: Vec<&'a str>,
87 
88     /// extra condition for event query.
89     pub condition: &'a str,
90 }
91 
92 /// Query system event.
query(query_arg: &QueryArg, query_rules: &[QueryRule], querier: &Querier) -> i3293 pub fn query(query_arg: &QueryArg, query_rules: &[QueryRule], querier: &Querier) -> i32 {
94     sys_event_manager::query(query_arg, query_rules, querier)
95 }
96 
97 /// Definition listener rule for system event information.
98 #[derive(Copy, Clone)]
99 pub struct WatchRule<'a> {
100     /// The domain of the event.
101     pub domain: &'a str,
102 
103     /// The name of the event.
104     pub name: &'a str,
105 
106     /// The tag of the event.
107     pub tag: &'a str,
108 
109     /// The rule of match system event.
110     pub rule_type: RuleType,
111 
112     /// The type of match system event.
113     pub event_type: EventType,
114 }
115 
116 /// Add watcher to watch system event.
add_watcher(watcher: &Watcher, watch_rules: &[WatchRule]) -> i32117 pub fn add_watcher(watcher: &Watcher, watch_rules: &[WatchRule]) -> i32 {
118     sys_event_manager::add_watcher(watcher, watch_rules)
119 }
120 
121 /// Remove watcher.
remove_watcher(watcher: &Watcher) -> i32122 pub fn remove_watcher(watcher: &Watcher) -> i32 {
123     sys_event_manager::remove_watcher(watcher)
124 }
125