1 // Copyright (C) 2023 Huawei Device Co., Ltd.
2 // Licensed under the Apache License, Version 2.0 (the "License");
3 // you may not use this file except in compliance with the License.
4 // You may obtain a copy of the License at
5 //
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 //! Rust interfaces for crate hisysevent.
15
16 mod sys_event;
17 mod sys_event_manager;
18 mod utils;
19
20 #[macro_use]
21 pub mod macros;
22
23 pub use sys_event::{
24 build_string_arrays, parse_type_len, HiSysEventParam, HiSysEventParamType, HiSysEventParamValue,
25 };
26 pub use sys_event_manager::{HiSysEventRecord, Querier, Watcher};
27
28 /// Enumerate system event types.
29 #[non_exhaustive]
30 #[derive(Copy, Clone)]
31 pub enum EventType {
32 /// Fault event.
33 Fault = 1,
34
35 /// Statistic event.
36 Statistic = 2,
37
38 /// Security event.
39 Security = 3,
40
41 /// System behavior event.
42 Behavior = 4,
43 }
44
45 /// Write system event.
write( event_domain: &str, event_name: &str, event_type: EventType, event_params: &[HiSysEventParam], ) -> i3246 pub fn write(
47 event_domain: &str,
48 event_name: &str,
49 event_type: EventType,
50 event_params: &[HiSysEventParam],
51 ) -> i32 {
52 sys_event::write(
53 event_domain,
54 event_name,
55 event_type as std::ffi::c_int,
56 event_params,
57 )
58 }
59
60 /// Enumerate search system event rule type.
61 #[non_exhaustive]
62 #[derive(Copy, Clone)]
63 pub enum RuleType {
64 /// Whole word match.
65 WholeWord = 1,
66
67 /// Prefix match.
68 Prefix = 2,
69
70 /// Regular match.
71 Regular = 3,
72 }
73
74 /// Definition arguments for query system event information.
75 #[derive(Copy, Clone)]
76 pub struct QueryArg {
77 /// Begin time.
78 pub begin_time: i64,
79
80 /// End time.
81 pub end_time: i64,
82
83 /// Max number of receive system event.
84 pub max_events: i32,
85 }
86
87 /// Definition event for query system event information.
88 pub struct QueryRule<'a> {
89 /// The domain of the event.
90 pub domain: &'a str,
91
92 /// List of event name.
93 pub event_list: Vec<&'a str>,
94
95 /// extra condition for event query.
96 pub condition: &'a str,
97 }
98
99 /// Query system event.
query(query_arg: &QueryArg, query_rules: &[QueryRule], querier: &Querier) -> i32100 pub fn query(query_arg: &QueryArg, query_rules: &[QueryRule], querier: &Querier) -> i32 {
101 sys_event_manager::query(query_arg, query_rules, querier)
102 }
103
104 /// Definition listener rule for system event information.
105 #[derive(Copy, Clone)]
106 pub struct WatchRule<'a> {
107 /// The domain of the event.
108 pub domain: &'a str,
109
110 /// The name of the event.
111 pub name: &'a str,
112
113 /// The tag of the event.
114 pub tag: &'a str,
115
116 /// The rule of match system event.
117 pub rule_type: RuleType,
118
119 /// The type of match system event.
120 pub event_type: EventType,
121 }
122
123 /// Add watcher to watch system event.
add_watcher(watcher: &Watcher, watch_rules: &[WatchRule]) -> i32124 pub fn add_watcher(watcher: &Watcher, watch_rules: &[WatchRule]) -> i32 {
125 sys_event_manager::add_watcher(watcher, watch_rules)
126 }
127
128 /// Remove watcher.
remove_watcher(watcher: &Watcher) -> i32129 pub fn remove_watcher(watcher: &Watcher) -> i32 {
130 sys_event_manager::remove_watcher(watcher)
131 }
132